搜索内容 搜索用户

# [已答复] 绘制函数图形

 如果矩阵中的某一个元素为函数，请教，如何才能画出该元素的函数图形；例如画出如下程序中矩阵M(2,4)的三维图形 clc close all clear %% syms Psi delt sigma1=30; sigma2=30; theta1=30; theta2=30; N=cosd(2*Psi); Sc=sind(2*Psi)*cosd(delt); Ss=sind(2*Psi)*sind(delt); A1=1-(1-cosd(sigma1))*sind(2*theta1)*sind(2*theta1); A2=1-(1-cosd(sigma2))*sind(2*theta2)*sind(2*theta2); B1=(1-cosd(sigma1))*sind(2*theta1)*cosd(2*theta1); B2=(1-cosd(sigma2))*sind(2*theta2)*cosd(2*theta2); C1=sind(sigma1)*sind(2*theta1); C2=sind(sigma2)*sind(2*theta2); D1=1-(1-cosd(sigma1))*cosd(2*theta1)*cosd(2*theta1); D2=1-(1-cosd(sigma2))*cosd(2*theta2)*cosd(2*theta2); E1=sind(sigma1)*cosd(2*theta1); E2=sind(sigma2)*cosd(2*theta2); F1=cosd(sigma1); F2=cosd(sigma2); W2=[1 0 0 0;0 A2 B2 -C2;0 B2 D2 F2;0 C2 -E2 F2]; S=[1 -N 0 0;-N 1 0 0;0 0 Sc Ss;0 0 -Ss Sc]; W1=[1 0 0 0;0 A1 B1 -C1;0 B1 D1 F1;0 C1 -E1 F1]; M=W2*S*W1; [Psi,delt] = meshgrid(-2*pi:2*pi); mesh(Psi,delt,M(2,4)) set(gca,'xlim',[-2*pi,2*pi]);%设置x轴坐标范围 set(gca,'xtick',-2*pi:pi/2:2*pi)%设置x轴坐标间隔 set(gca,'XTickLabel',{'-2\pi','-3\pi/2','-\pi','-\pi/2','0','\pi/2','\pi','3\pi/2','2\pi'});%\pi=π set(gca,'ylim',[-2*pi,2*pi]);%设置y轴坐标范围 set(gca,'ytick',-2*pi:pi/2:2*pi);%设置y轴坐标间隔 set(gca,'YTickLabel',{'-2\pi','-3\pi/2','-\pi','-\pi/2','0','\pi/2','\pi','3\pi/2','2\pi'});%\pi=π xlabel('Ψ'),ylabel('Δ'),zlabel(''); 运行时提示，z必须为矩阵，不能是标量或向量；请教解决该问题的方法

2 条回复

## 倒序浏览

20141303 发表于 2021-5-7 08:23:19
 仅供参考 clc close all clear %% syms Psi delt sigma1=30; sigma2=30; theta1=30; theta2=30; N=cosd(2*Psi); Sc=sind(2*Psi)*cosd(delt); Ss=sind(2*Psi)*sind(delt); A1=1-(1-cosd(sigma1))*sind(2*theta1)*sind(2*theta1); A2=1-(1-cosd(sigma2))*sind(2*theta2)*sind(2*theta2); B1=(1-cosd(sigma1))*sind(2*theta1)*cosd(2*theta1); B2=(1-cosd(sigma2))*sind(2*theta2)*cosd(2*theta2); C1=sind(sigma1)*sind(2*theta1); C2=sind(sigma2)*sind(2*theta2); D1=1-(1-cosd(sigma1))*cosd(2*theta1)*cosd(2*theta1); D2=1-(1-cosd(sigma2))*cosd(2*theta2)*cosd(2*theta2); E1=sind(sigma1)*cosd(2*theta1); E2=sind(sigma2)*cosd(2*theta2); F1=cosd(sigma1); F2=cosd(sigma2); W2=[1 0 0 0;0 A2 B2 -C2;0 B2 D2 F2;0 C2 -E2 F2]; S=[1 -N 0 0;-N 1 0 0;0 0 Sc Ss;0 0 -Ss Sc]; W1=[1 0 0 0;0 A1 B1 -C1;0 B1 D1 F1;0 C1 -E1 F1]; M=W2*S*W1; [Psi1,delt1] = meshgrid(-2*pi:2*pi); for i=1:size(Psi1,1)     for j=1:size(Psi1,2)         mid(i,j)=double(subs(M(2,4),[Psi,delt],[Psi1(i,j),delt1(i,j)]));     end end mesh(Psi1,delt1,mid) set(gca,'xlim',[-2*pi,2*pi]);%设置x轴坐标范围 set(gca,'xtick',-2*pi:pi/2:2*pi)%设置x轴坐标间隔 set(gca,'XTickLabel',{'-2\pi','-3\pi/2','-\pi','-\pi/2','0','\pi/2','\pi','3\pi/2','2\pi'});%\pi=π set(gca,'ylim',[-2*pi,2*pi]);%设置y轴坐标范围 set(gca,'ytick',-2*pi:pi/2:2*pi);%设置y轴坐标间隔 set(gca,'YTickLabel',{'-2\pi','-3\pi/2','-\pi','-\pi/2','0','\pi/2','\pi','3\pi/2','2\pi'});%\pi=π xlabel('Ψ'),ylabel('Δ'),zlabel('');复制代码

 20141303 发表于 2021-5-7 08:23 仅供参考 已解决，多谢前辈指教
 您需要登录后才可以回帖 登录 | 注册 本版积分规则 回帖后跳转到最后一页