matlab solve 求解方程组遇到Error using ==> subsasgn代码如下1#是没加循环时可以运行,2#是加循环是出现报错报错内容:Error using ==> subsasgnIn an assignment A(:) = B,the number of elements in A and Bmust be the same.Err
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/24 04:48:10
matlab solve 求解方程组遇到Error using ==> subsasgn代码如下1#是没加循环时可以运行,2#是加循环是出现报错报错内容:Error using ==> subsasgnIn an assignment A(:) = B,the number of elements in A and Bmust be the same.Err
matlab solve 求解方程组遇到Error using ==> subsasgn
代码如下1#是没加循环时可以运行,2#是加循环是出现报错
报错内容:
Error using ==> subsasgn
In an assignment A(:) = B,the number of elements in A and B
must be the same.
Error in ==> sym.subsasgn at 33
y = builtin('subsasgn',sx,a,b);
一直没找到原因
%1#
clc
clear
syms Z0 K ;
E1=30.336*1000;%Mpa
E2=69*1000; %AL(Mpa)
E3=E1;
D1=1350/1000000;
D3=-D1/3;
a=0.32; %mm
b=0.4;
Z1=Z0+a;
Z2=Z1+b;
Z3=Z2+a;
M1=(1/3)*b*E1*K*(Z3^3-Z2^3)+(1/2)*b*E1*D1*(Z2^2-Z3^2);
M2=(1/3)*b*E2*K*(Z2^3-Z1^3);
M3=(1/3)*b*E3*K*(Z1^3-Z0^3)+(1/2)*b*E3*D3*(Z0^2-Z1^2);
F1=(1/2)*b*E1*K*(Z3^2-Z2^2)-b*E1*D1*(Z3-Z2);
F2=(1/2)*b*E2*K*(Z2^2-Z1^2);
F3=(1/2)*b*E3*K*(Z1^2-Z0^2)-b*E3*D3*(Z1-Z0);
equ1=M1+M2+M3;
equ2=F1+F2+F3;
[K,Z0] = solve(equ1,equ2);
%2#
clc
clear
syms Z0 K ;
E1=30.336*1000;%Mpa
E2=69*1000; %AL(Mpa)
E3=E1;
D1=1350/1000000;
D3=-D1/3;
a=0.32; %mm
b=0.1:0.02:1;
n=length(b);
for i=1:n
Z1=Z0+a;
Z2=Z1+b(i);
Z3=Z2+a;
M1=(1/3)*b(i)*E1*K*(Z3^3-Z2^3)+(1/2)*b(i)*E1*D1*(Z2^2-Z3^2);
M2=(1/3)*b(i)*E2*K*(Z2^3-Z1^3);
M3=(1/3)*b(i)*E3*K*(Z1^3-Z0^3)+(1/2)*b(i)*E3*D3*(Z0^2-Z1^2);
F1=(1/2)*b(i)*E1*K*(Z3^2-Z2^2)-b(i)*E1*D1*(Z3-Z2);
F2=(1/2)*b(i)*E2*K*(Z2^2-Z1^2);
F3=(1/2)*b(i)*E3*K*(Z1^2-Z0^2)-b(i)*E3*D3*(Z1-Z0);
equ1=M1+M2+M3;
equ2=F1+F2+F3;
[x(i),y(i)] = solve(equ1,equ2); %X(i)=K(i),Y(i)=Z0(i)
end
x';
2#代码中把for i=1:n改为for i=1:3可以运行,但是改为for i=1:4或比4大的数就不能运行
但是将对应的b=0.16或b=0.18代入1#中单独求都可求出1组解
我是彻底懵了,到底咋回事啊,
matlab solve 求解方程组遇到Error using ==> subsasgn代码如下1#是没加循环时可以运行,2#是加循环是出现报错报错内容:Error using ==> subsasgnIn an assignment A(:) = B,the number of elements in A and Bmust be the same.Err
我把你程序直接贴到命令行没有报错啊?