gqs2872
2013-11-29, 08:55
我想在Matlab输出个一个6乘6的矩阵,元素是C(i,j)=(i+1)*(j+1)*alpha^(i+j),i=1到6,j=1到6,用for 循环语句, 我想让输出的这个矩阵中含有符号变量alpha。
以下是我目前的code, 主要是for 循环的 Cdo1 不对。
syms rho A h EI alpha Cd e
m1=zeros(6);
k1=zeros(6);
Cdo1=zeros(6);
for i = 1:6;
for j=1:6;
m1(i,j)=1./(i+j+3);
k1(i,j)=i*(i+1)*j*(j+1)./(i+j-1);
Cdo1(i,j)=(i+1)*(j+1)*alpha^(i+j);
end
end
M=rho*A*h*m1;
K=EI*h*k1;
Cdo=2*Cd*e^2*Cdo1;
以下是matlab给出的错误原因:
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 Problemone (line 9)
Cdo1(i,j)=(i+1)*(j+1)*alpha^(i+j);
以下是我目前的code, 主要是for 循环的 Cdo1 不对。
syms rho A h EI alpha Cd e
m1=zeros(6);
k1=zeros(6);
Cdo1=zeros(6);
for i = 1:6;
for j=1:6;
m1(i,j)=1./(i+j+3);
k1(i,j)=i*(i+1)*j*(j+1)./(i+j-1);
Cdo1(i,j)=(i+1)*(j+1)*alpha^(i+j);
end
end
M=rho*A*h*m1;
K=EI*h*k1;
Cdo=2*Cd*e^2*Cdo1;
以下是matlab给出的错误原因:
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 Problemone (line 9)
Cdo1(i,j)=(i+1)*(j+1)*alpha^(i+j);