登录论坛

查看完整版本 : [MATLAB毕业设计] 请问各位大师,我这个程序的问题在哪儿


zyl0303
2011-09-16, 14:54
syms t1 t2;
N=100;
L=0.5;
dx=L/(N-1);
i=sqrt(-1);
u=1.257*10^(-6);
e=8.854*10^(-12);
o=2*pi/sqrt(u*e);
k=o*sqrt(u*e);
JJ=zeros(1,N-1);

for n=1:N-1
if n==1;
J1(n)=0*t1;
JJ1(n)=subs(J1(n));
J2(n)=(((n*dx-t1)./dx).*exp(-i*k*sqrt(t1-t2).^2))./(4*pi*sqrt(t1-t2).^2);
JJ2(n)=subs(J2(n));
else
J1(n)=(((t1-(n-2)*dx)./dx).*exp(-i*k*sqrt(t1-t2).^2))./(4*pi*sqrt(t1-t2).^2);
JJ1(n)=subs(J1(n));
J2(n)=(((n*dx-t1)./dx).*exp(-i*k*sqrt(t1-t2).^2))./(4*pi*sqrt(t1-t2).^2);
JJ2(n)=subs(J2(n));
end
end

下面是程序报错:
??? The following error occurred converting from sym to double:
Error using ==> mupadmex
Error in MuPAD command: DOUBLE cannot convert the input expression
into a double array.

If the input expression contains a symbolic variable, use the VPA
function instead.

Error in ==> QUADmn at 21
JJ1(n)=subs(J1(n));
我是新手,请各位大师能够在百忙之总给予指点,本人感激不尽!!!

laohuiosa
2011-09-18, 09:42
使用SUBS这个函数把符号变量转换为数值变量时,你把所有的符号变量运算完毕后,再对符号变量赋值,再使用SUBS进行计算,你的代码中t1都没有赋值,你无法使用SUBS ,建议你把符运算进行完在SUBS