MATLAB 用solve函数解方程,结果是虚数,而且不满足原方程,自己变换后都能满足,求解原因 255
clear;symsr1;symsr2;symsr3;symsr4;symsC1;symsC2;symsC3;symsC4;symsRg;symsRg1;symsRm;s...
clear;
syms r1;
syms r2;
syms r3;
syms r4;
syms C1;
syms C2;
syms C3;
syms C4;
syms Rg;
syms Rg1;
syms Rm;
syms Rm1;
syms Rd;
syms L;
syms I;
[C1,C2,C3,C4]=solve('C1+C2+C3+C4=I-Rm*Rd*I/(Rm*Rd+Rg*Rd+Rg*Rm)','C1*exp(r1*L)+C2*exp(r2*L)+C3*exp(r3*L)+C4*exp(r4*L)=I-Rm*Rd*I/(Rm*Rd+Rg*Rd+Rg*Rm)','Rg*(I-Rm*Rd*I/(Rm*Rd+Rg*Rd+Rg*Rm))=Rg1*(C1*r1^2+C2*r2^2+C3*r3^2+C4*r4^2)','Rg*(C1*exp(r1*L)+C2*exp(r2*L)+C3*exp(r3*L)+C4*exp(r4*L))=Rg1*(C1*r1^2*exp(r1*L)+C2*r2^2*exp(r2*L)+C3*r3^2*exp(r3*L)+C4*r4^2*exp(r4*L))','C1','C2','C3','C4')
Rg=0.026;
Rg1=15;
Rm=0.5;
Rm1=15;
Rd=0.05;
L=2;
I=1000;
r1=sqrt(((Rd+Rm)*Rg1+Rm1*Rg+sqrt((Rd*Rg1+Rm*Rg1+Rm1*Rg)^2-4*Rg1*Rm1*(Rm*Rd+Rg*Rd+Rg*Rm)))/(2*Rg1*Rm1))
r2=-r1
r3=sqrt(((Rd+Rm)*Rg1+Rm1*Rg-sqrt((Rd*Rg1+Rm*Rg1+Rm1*Rg)^2-4*Rg1*Rm1*(Rm*Rd+Rg*Rd+Rg*Rm)))/(2*Rg1*Rm1))
r4=-r3
问题已解决,最佳方法是用矩阵形式求解 展开
syms r1;
syms r2;
syms r3;
syms r4;
syms C1;
syms C2;
syms C3;
syms C4;
syms Rg;
syms Rg1;
syms Rm;
syms Rm1;
syms Rd;
syms L;
syms I;
[C1,C2,C3,C4]=solve('C1+C2+C3+C4=I-Rm*Rd*I/(Rm*Rd+Rg*Rd+Rg*Rm)','C1*exp(r1*L)+C2*exp(r2*L)+C3*exp(r3*L)+C4*exp(r4*L)=I-Rm*Rd*I/(Rm*Rd+Rg*Rd+Rg*Rm)','Rg*(I-Rm*Rd*I/(Rm*Rd+Rg*Rd+Rg*Rm))=Rg1*(C1*r1^2+C2*r2^2+C3*r3^2+C4*r4^2)','Rg*(C1*exp(r1*L)+C2*exp(r2*L)+C3*exp(r3*L)+C4*exp(r4*L))=Rg1*(C1*r1^2*exp(r1*L)+C2*r2^2*exp(r2*L)+C3*r3^2*exp(r3*L)+C4*r4^2*exp(r4*L))','C1','C2','C3','C4')
Rg=0.026;
Rg1=15;
Rm=0.5;
Rm1=15;
Rd=0.05;
L=2;
I=1000;
r1=sqrt(((Rd+Rm)*Rg1+Rm1*Rg+sqrt((Rd*Rg1+Rm*Rg1+Rm1*Rg)^2-4*Rg1*Rm1*(Rm*Rd+Rg*Rd+Rg*Rm)))/(2*Rg1*Rm1))
r2=-r1
r3=sqrt(((Rd+Rm)*Rg1+Rm1*Rg-sqrt((Rd*Rg1+Rm*Rg1+Rm1*Rg)^2-4*Rg1*Rm1*(Rm*Rd+Rg*Rd+Rg*Rm)))/(2*Rg1*Rm1))
r4=-r3
问题已解决,最佳方法是用矩阵形式求解 展开
1个回答
展开全部
使用 fsolve 具体如下
运行主文件,代码如下
x0 = [0.01;0.01;0.01]; % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
[x,fval] = fsolve(@myfsolvefun,x0,options); % Call optimize
x
然后新建个m文件 命名为myfsolvefun.m(即定义这个函数)
myfsolvefun.m里的代码如下
function F = myfsolvefun(sita)
x=2;y=3;z=4;l0=5;l1=6;l2=7;l3=8; %这里我随便赋的值,根据你自己的要求修改
F=[cos(sita(1))*(l1*sin(sita(2))+l2*sin(sita(2)+sita(3))+l3)-x;
sin(sita(1))*(l1*sin(sita(2))+l2*sin(sita(2)+sita(3))+l3)-y;
l0+l1*cos(sita(2))+l2*cos(sita(2)+sita(3))-z];
最后X为输出结果
运行主文件,代码如下
x0 = [0.01;0.01;0.01]; % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
[x,fval] = fsolve(@myfsolvefun,x0,options); % Call optimize
x
然后新建个m文件 命名为myfsolvefun.m(即定义这个函数)
myfsolvefun.m里的代码如下
function F = myfsolvefun(sita)
x=2;y=3;z=4;l0=5;l1=6;l2=7;l3=8; %这里我随便赋的值,根据你自己的要求修改
F=[cos(sita(1))*(l1*sin(sita(2))+l2*sin(sita(2)+sita(3))+l3)-x;
sin(sita(1))*(l1*sin(sita(2))+l2*sin(sita(2)+sita(3))+l3)-y;
l0+l1*cos(sita(2))+l2*cos(sita(2)+sita(3))-z];
最后X为输出结果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询