matlab编程程序,请大神看看哪里有问题?
Error:Functiondefinitionsarenotpermittedinthiscontext.functionw=cc(q,x,y,z,miu,t)ifx>...
Error: Function definitions are not permitted in this context.
function w=cc(q,x,y,z,miu,t)
if x>1000
a1=0.850834;
r1=0.602052;
else
a1=0.901074;
r1=0.425809;
end
if x>500
a2=2.10881;
r2=0.000211545;
elseif x>300&&x<500
a2=1.51360;
r2=0.00854771;
else
a2=1.12154;
r2=0.0799904;
end
sy=r1*x.^a1;
sz=r2*x.^a2;
if 0.5<t&&t<1
sy=r1*x.^a1*(2*t).^0.2;
sz=r2*x.^a2;
else
sy=r1*x.^a1*(2*t).^0.3;
sz=r2*x.^a2;
end
w=q./(pi*miu*sy*sz).exp(-(y.^2./(2*sy^2)+z.^2./(2*sz^2)));
q=400000;
t=120;
x=linspace(0,50,100);
y=linspace(-50,50,100);
m=length(x);
y=length(y);
www=zeros(m,n);
for i=1:m
for j=1:n
www(i,j)=cc(q,x(i),y(j),1.5,2.5,t,1);
end
end
[X Y]=meshgrid(x,y);
X=X*100;
Y=Y*100;
surf(X,Y,www') 展开
function w=cc(q,x,y,z,miu,t)
if x>1000
a1=0.850834;
r1=0.602052;
else
a1=0.901074;
r1=0.425809;
end
if x>500
a2=2.10881;
r2=0.000211545;
elseif x>300&&x<500
a2=1.51360;
r2=0.00854771;
else
a2=1.12154;
r2=0.0799904;
end
sy=r1*x.^a1;
sz=r2*x.^a2;
if 0.5<t&&t<1
sy=r1*x.^a1*(2*t).^0.2;
sz=r2*x.^a2;
else
sy=r1*x.^a1*(2*t).^0.3;
sz=r2*x.^a2;
end
w=q./(pi*miu*sy*sz).exp(-(y.^2./(2*sy^2)+z.^2./(2*sz^2)));
q=400000;
t=120;
x=linspace(0,50,100);
y=linspace(-50,50,100);
m=length(x);
y=length(y);
www=zeros(m,n);
for i=1:m
for j=1:n
www(i,j)=cc(q,x(i),y(j),1.5,2.5,t,1);
end
end
[X Y]=meshgrid(x,y);
X=X*100;
Y=Y*100;
surf(X,Y,www') 展开
1个回答
展开全部
主要问题:
1、代码本来应该分两部分,都被混到一起了。而且你可能是直接在命令窗口中直接贴代码运行,这对于函数而言是不允许的,应该保存成M文件再运行。
2、几个低级错误:
(1)变量名错误:y=length(y);应为n=length(y);
(2)调用函数时参数数量错误:www(i,j)=cc(q,x(i),y(j),1.5,2.5,t,1);应为www(i,j)=cc(q,x(i),y(j),1.5,2.5,t);
(3)点乘缺少乘号:w=q./(pi*miu*sy*sz).exp(-(y.^2./(2*sy^2)+z.^2./(2*sz^2)));应为w=q./(pi*miu*sy*sz).*exp(-(y.^2./(2*sy^2)+z.^2./(2*sz^2)));
改后的代码:
function zd1668380218552966787
q=400000;
t=120;
x=linspace(0,50,100);
y=linspace(-50,50,100);
m=length(x);
n=length(y);
www=zeros(m,n);
for i=1:m
for j=1:n
www(i,j)=cc(q,x(i),y(j),1.5,2.5,t);
end
end
[X Y]=meshgrid(x,y);
X=X*100;
Y=Y*100;
surf(X,Y,www')
function w=cc(q,x,y,z,miu,t)
if x>1000
a1=0.850834;
r1=0.602052;
else
a1=0.901074;
r1=0.425809;
end
if x>500
a2=2.10881;
r2=0.000211545;
elseif x>300&&x<500
a2=1.51360;
r2=0.00854771;
else
a2=1.12154;
r2=0.0799904;
end
sy=r1*x.^a1;
sz=r2*x.^a2;
if 0.5<t&&t<1
sy=r1*x.^a1*(2*t).^0.2;
sz=r2*x.^a2;
else
sy=r1*x.^a1*(2*t).^0.3;
sz=r2*x.^a2;
end
w=q./(pi*miu*sy*sz).*exp(-(y.^2./(2*sy^2)+z.^2./(2*sz^2)));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询