作业帮 > 综合 > 作业

这个matlab 程序应该如何改

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/05/11 19:22:39
这个matlab 程序应该如何改
syms w;
md=1700
g=8.27*10^7
n=10
l=10
s=zeros(9)
%%给矩阵赋值
for i=1:9
for j=1:9
if (j==i-1)
s(i,j)=n^2/l^2;
elseif (j==i)
s(i,j)=md*(w^2)/g-(2*i-1)*(n^2)/i*l^2;
elseif (j==i+1)
s(i,j)=((n/l)^2)/i;
end
end
end
s(1,2)=0;
s(9,9)=md*w^2/g-(n/l)^2;
s(9,8)= (n/l)^2;
%%解行列式为0的方程,y即未知数w的值
y=solve(det(s))
提示出错为
The following error occurred converting from sym to double:
Error using ==> sym.double
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 ==> matlab at 14
s(i,j)=md*(w^2)/g-(2*i-1)*(n^2)/i*l^2;
那这是为什么呀?
这个matlab 程序应该如何改
a=zeros(1,1);
syms w
a(1,1)=w
上面的程序,你试一下就知道了.在matlab中是不能够将一个符号变量赋值给数值矩阵的
你试一下下面的程序
就是把s=zeros(9)一行去掉
syms w;
md=1700
g=8.27*10^7
n=10
l=10
%给矩阵赋值
for i=1:9
for j=1:9
if (j==i-1)
s(i,j)=n^2/l^2;
elseif (j==i)
s(i,j)=md*(w^2)/g-(2*i-1)*(n^2)/i*l^2;
elseif (j==i+1)
s(i,j)=((n/l)^2)/i;
end
end
end
s(1,2)=0;
s(9,9)=md*w^2/g-(n/l)^2;
s(9,8)= (n/l)^2;
%%解行列式为0的方程,y即未知数w的值
y=solve(det(s))