我的程序如下,请指导,谢谢!
D1=0:0.01:0.5;
>> for D2=[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
P=pi*(2*D1*D2-2D1.^2-D2.^2+D2);
plot(D1,P)
hold on
P=0;
end
谢谢 我是想在D2=0.1时 画一个plot(D1,P) D2=0.2时 画一个plot(D1,P) 依次画到D2=0.9
追答楼下的哥们,我想楼主想画应该不是曲面,而是一族曲线
D2是一个参数,D1是变量,对吧
我前面的代码就是这样的,稍微改改:
clear all;clc;
D1=0:0.01:0.5;
D2=0:0.1:1;
for ii=1:length(D1)
for jj=1:length(D2)
P(ii,jj)=pi*(2*D1(ii)*D2(jj)-2*D1(ii)^2-D2(jj)^2+D2(jj));
end
end
plot(D1,P);
---------------------------------------
要是你不愿意循环的话,就这样:
clear all;clc;
D1=(0:0.01:0.5)';
m=length(D1);
D2=0:0.1:1;
n=length(D2);
P=pi*(2*D1*D2-2*repmat(D1.^2,1,n)-repmat(D2.^2,m,1)+repmat(D2,m,1));
plot(D1,P);
谢谢您了!十分感谢,我就是那个意思。
本回答被提问者和网友采纳