xl2033 2022-08-16 11:23 采纳率: 57.1%

# matlab fsolve求解非线性方程组为什么得到复数解

function F = zw(X)
da= X(1);
dr= X(2);
ct= X(3);
dc=31;
Dw = 12.303;
A = 0.627;
dm = 58;
a=35/180*pi;
Kn=3.0363*10^5;
ri=6.405;
Ri=dm/2+(ri-Dw/2)*cos(a);

Fr=4500;Fa=3000;M=800000;
p1 = 0:2*pi/13:24*pi/13;
p2 = pi/13:2*pi/13:25*pi/13;
F(1) = Fa-Kn*A^1.5*sum((sin(a) + da/A+Ri*(ct/A)*cos(p1)).*(((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*ct*cos(p1)/A).^2).^0.5 - 1).^1.5./((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*(ct/A)*cos(p1)).^2).^0.5)+Kn*A^1.5*sum((sin(a) - da/A-Ri*(ct/A)*cos(p2)).*(((sin(a) - da/A-Ri*(ct/A)*cos(p2)).^2 + (cos(a) + dr* cos(p2)/A-0.5*dc*ct*cos(p2)/A).^2).^0.5 - 1).^1.5./((sin(a) - da/A-Ri*(ct/A)*cos(p2)).^2 + (cos(a) + dr* cos(p2)/A-0.5*dc*(ct/A)*cos(p2)).^2).^0.5);
F(2) = Fr-Kn*A^1.5*sum((cos(a) + (dr/A)*cos(p1)+0.5*dc*(ct/A)*cos(p1)).*cos(p1).*(((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*ct*cos(p1)/A).^2).^0.5 - 1).^1.5./((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*(ct/A)*cos(p1)).^2).^0.5)-Kn*A^1.5*sum((cos(a) + (dr/A)*cos(p2)-0.5*dc*(ct/A)*cos(p2)).*cos(p2).*(((sin(a) -da/A-Ri*(ct/A)*cos(p2)).^2 + (cos(a) + dr* cos(p2)/A-0.5*dc*ct*cos(p2)/A).^2).^0.5 - 1).^1.5./((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*(ct/A)*cos(p1)).^2).^0.5);
F(3)=M-dm/2*Kn*A^1.5*sum((sin(a) + da/A+Ri*(ct/A)*cos(p1)).*cos(p1).*(((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*ct*cos(p1)/A).^2).^0.5 - 1).^1.5./((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*(ct/A)*cos(p1)).^2).^0.5)-dc/2*Kn*A^1.5*sum((cos(a) + (dr/A)*cos(p1)+0.5*dc*(ct/A)*cos(p1)).*cos(p1).*(((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*ct*cos(p1)/A).^2).^0.5 - 1).^1.5./((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*(ct/A)*cos(p1)).^2).^0.5)+dm/2*Kn*A^1.5*sum((sin(a) - da/A-Ri*(ct/A)*cos(p2)).*cos(p2).*(((sin(a) - da/A-Ri*(ct/A)*cos(p2)).^2 + (cos(a) + dr* cos(p2)/A-0.5*dc*ct*cos(p2)/A).^2).^0.5 - 1).^1.5./((sin(a) - da/A-Ri*(ct/A)*cos(p2)).^2 + (cos(a) + dr* cos(p2)/A-0.5*dc*(ct/A)*cos(p2)).^2).^0.5)+dc/2*Kn*A^1.5*sum((cos(a) + (dr/A)*cos(p2)-0.5*dc*(ct/A)*cos(p2)).*cos(p2).*(((sin(a) -da/A-Ri*(ct/A)*cos(p2)).^2 + (cos(a) + dr* cos(p2)/A-0.5*dc*ct*cos(p2)/A).^2).^0.5 - 1).^1.5./((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*(ct/A)*cos(p1)).^2).^0.5);

end

h=optimset;
h.Display='off';
h.TolX=1e-6;
[jg,fval,exitflag]=fsolve('zw',[0,0,0],h) %求解
• 写回答

#### 2条回答默认 最新

• 斗迷飞鸟 2022-08-19 02:49
关注

（1）问题分析
出现复数解应该是因为你的“zw”函数中有1.5次方和0.5次方，而fsolve搜索解的时候对应幂的底数可能是负的，这样对应的1.5次方和0.5次方就会出现复数，进而导致目标函数值为复数，最终导致得到的解为复数。
（2）问题的可能改进代码
考虑在zw中将最后的函数值取模，这样可以得到实数解

function F = zw_real(X)
da= X(1);
dr= X(2);
ct= X(3);
dc=31;
Dw = 12.303;
A = 0.627;
dm = 58;
a=35/180*pi;
Kn=3.0363*10^5;
ri=6.405;
Ri=dm/2+(ri-Dw/2)*cos(a);

Fr=4500;Fa=3000;M=800000;
p1 = 0:2*pi/13:24*pi/13;
p2 = pi/13:2*pi/13:25*pi/13;
F(1) = Fa-Kn*A^1.5*sum((sin(a) + da/A+Ri*(ct/A)*cos(p1)).*(((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*ct*cos(p1)/A).^2).^0.5 - 1).^1.5./((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*(ct/A)*cos(p1)).^2).^0.5)+Kn*A^1.5*sum((sin(a) - da/A-Ri*(ct/A)*cos(p2)).*(((sin(a) - da/A-Ri*(ct/A)*cos(p2)).^2 + (cos(a) + dr* cos(p2)/A-0.5*dc*ct*cos(p2)/A).^2).^0.5 - 1).^1.5./((sin(a) - da/A-Ri*(ct/A)*cos(p2)).^2 + (cos(a) + dr* cos(p2)/A-0.5*dc*(ct/A)*cos(p2)).^2).^0.5);
F(2) = Fr-Kn*A^1.5*sum((cos(a) + (dr/A)*cos(p1)+0.5*dc*(ct/A)*cos(p1)).*cos(p1).*(((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*ct*cos(p1)/A).^2).^0.5 - 1).^1.5./((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*(ct/A)*cos(p1)).^2).^0.5)-Kn*A^1.5*sum((cos(a) + (dr/A)*cos(p2)-0.5*dc*(ct/A)*cos(p2)).*cos(p2).*(((sin(a) -da/A-Ri*(ct/A)*cos(p2)).^2 + (cos(a) + dr* cos(p2)/A-0.5*dc*ct*cos(p2)/A).^2).^0.5 - 1).^1.5./((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*(ct/A)*cos(p1)).^2).^0.5);
F(3)=M-dm/2*Kn*A^1.5*sum((sin(a) + da/A+Ri*(ct/A)*cos(p1)).*cos(p1).*(((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*ct*cos(p1)/A).^2).^0.5 - 1).^1.5./((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*(ct/A)*cos(p1)).^2).^0.5)-dc/2*Kn*A^1.5*sum((cos(a) + (dr/A)*cos(p1)+0.5*dc*(ct/A)*cos(p1)).*cos(p1).*(((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*ct*cos(p1)/A).^2).^0.5 - 1).^1.5./((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*(ct/A)*cos(p1)).^2).^0.5)+dm/2*Kn*A^1.5*sum((sin(a) - da/A-Ri*(ct/A)*cos(p2)).*cos(p2).*(((sin(a) - da/A-Ri*(ct/A)*cos(p2)).^2 + (cos(a) + dr* cos(p2)/A-0.5*dc*ct*cos(p2)/A).^2).^0.5 - 1).^1.5./((sin(a) - da/A-Ri*(ct/A)*cos(p2)).^2 + (cos(a) + dr* cos(p2)/A-0.5*dc*(ct/A)*cos(p2)).^2).^0.5)+dc/2*Kn*A^1.5*sum((cos(a) + (dr/A)*cos(p2)-0.5*dc*(ct/A)*cos(p2)).*cos(p2).*(((sin(a) -da/A-Ri*(ct/A)*cos(p2)).^2 + (cos(a) + dr* cos(p2)/A-0.5*dc*ct*cos(p2)/A).^2).^0.5 - 1).^1.5./((sin(a) + da/A+Ri*(ct/A)*cos(p1)).^2 + (cos(a) + dr* cos(p1)/A+0.5*dc*(ct/A)*cos(p1)).^2).^0.5);
F=abs(F);  %给函数返回值取模
end

clear;clc;
h=optimset;
h.Display='off';
h.TolX=1e-6;
format long;
[jg,fval,exitflag]=fsolve('zw_real',[0,0,0],h) %求解
format short;

（3）代码运行结果截图
这是将zw的返回值取模得到的结果，不知道能不能对上你的理论解，欢迎讨论

本回答被题主选为最佳回答 , 对您是否有帮助呢?
评论 编辑记录

• 系统已结题 8月27日
• 已采纳回答 8月19日
• 创建了问题 8月16日

#### 悬赏问题

• ¥15 关于某款2.13寸墨水屏的问题
• ¥15 obsidian的中文层级自动编号
• ¥15 同一个网口一个电脑连接有网，另一个电脑连接没网
• ¥15 神经网络模型一直不能上GPU
• ¥15 pyqt怎么把滑块和输入框相互绑定，求解决！
• ¥20 wpf datagrid单元闪烁效果失灵
• ¥15 券商软件上市公司信息获取问题
• ¥100 ensp启动设备蓝屏，代码clock_watchdog_timeout
• ¥15 Android studio AVD启动不了
• ¥15 陆空双模式无人机怎么做