I have 5 nonlinear algebraic equations with many terms, fsolve command is ineffective in solving these nonlinear equations.

3 次查看(过去 30 天)
Hi All. I have a system of 5 nonlinear equations that is expected to have three roots (three solutions).
I try to solve these nonlinear equations with fsolve. when I run the code, I get errors, like no solutions found, or fslove stopped prematurely. etc. It does not achieve anysolution, and sometimes achieve only one of the solutions.
Thus I decided to use 5 for loops for initial guesses in the fsolve command to get all the solutions, but running the program in this approach takes too much time. Even after two days, it couldn't solve the system of equations.
Is there a way to solve this problem?I would be grateful if you guide me on how I can solve the system of equations correctly.
for V_DC=1:1:400
for inia=0:0.5:1.5
for inib=0:0.5:1.5
for inic=0:0.5:1.5
for inid=0:0.5:1.5
for inie=0:0.5:1.5
u0=[inia inib inic inid inie]
f_u=@(u)[A1*u(1)^3+B1*u(2)^3+Z1*u(3)^3+D1*u(4)^3+E1*u(5)^3+F1*u(1)^2*u(2)+G1*u(1)^2*u(3)+H1*u(1)^2*u(4)+I1*u(1)^2*u(5)+J1*u(2)^2*u(1)+K1*u(2)^2*u(3)+L1*u(2)^2*u(4)+M1*u(2)^2*u(5)+N1*u(3)^2*u(1)+O1*u(3)^2*u(2)+P1*u(3)^2*u(4)+Q1*u(3)^2*u(5)+R1*u(4)^2*u(1)+S1*u(4)^2*u(2)+T1*u(4)^2*u(3)+V1*u(4)^2*u(5)+Aa1*u(5)^2*u(1)+Ba1*u(5)^2*u(2)+Za1*u(5)^2*u(3)+Da1*u(5)^2*u(4)+Ea1*u(1)*u(2)*u(3)+Fa1*u(1)*u(2)*u(4)+Ga1*u(1)*u(2)*u(5)+Ha1*u(1)*u(3)*u(4)+Ia1*u(1)*u(3)*u(5)+Ja1*u(1)*u(4)*u(5)+Ka1*u(2)*u(3)*u(4)+La1*u(2)*u(3)*u(5)+Ma1*u(2)*u(4)*u(5)+Na1*u(3)*u(4)*u(5)+Oa1*u(1)^2+Pa1*u(2)^2+Qa1*u(3)^2+Ra1*u(4)^2+Sa1*u(5)^2+Ta1*u(1)*u(2)+Va1*u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)*u(3)+phi4((1-L_e)/2)*u(4)+phi5((1-L_e)/2)*u(5))^s))+4*((phi5(((1-L_e)/2)+(L_e/2))*(w0(((1-L_e)/2)+(L_e/2))+phi1(((1-L_e)/2)+(L_e/2))*u(1)+phi2(((1-L_e)/2)+(L_e/2))*u(2)+phi3(((1-L_e)/2)+(L_e/2))*u(3)+phi4(((1-L_e)/2)+(L_e/2))*u(4)+phi5(((1-L_e)/2)+(L_e/2))*u(5)))/(1+q*(w0(((1-L_e)/2)+(L_e/2))+phi1(((1-L_e)/2)+(L_e/2))*u(1)+phi2(((1-L_e)/2)+(L_e/2))*u(2)+phi3(((1-L_e)/2)+(L_e/2))*u(3)+phi4(((1-L_e)/2)+(L_e/2))*u(4)+phi5(((1-L_e)/2)+(L_e/2))*u(5))^s))+((phi5((1+L_e)/2)*(w0((1+L_e)/2)+phi1((1+L_e)/2)*u(1)+phi2((1+L_e)/2)*u(2)+phi3((1+L_e)/2)*u(3)+phi4((1+L_e)/2)*u(4)+phi5((1+L_e)/2)*u(5)))/(1+q*(w0((1+L_e)/2)+phi1((1+L_e)/2)*u(1)+phi2((1+L_e)/2)*u(2)+phi3((1+L_e)/2)*u(3)+phi4((1+L_e)/2)*u(4)+phi5((1+L_e)/2)*u(5))^s)))];
[root,fval,exitflag]= fsolve(f_u,u0)
if isreal(root(1))==1 & isreal(root(2))==1 & isreal(root(3))==1 & isreal(root(4))==1 & isreal(root(5))==1 & exitflag>0
hold on
plot(V_DC,(root(1)*phi1_midpoint+root(2)*phi2_midpoint+root(3)*phi3_midpoint+root(4)*phi4_midpoint+root(5)*phi5_midpoint)*d*1e+6+9,'bo');
end
end
end
end
end
end
end
xlabel('V_DC')
ylabel('W_max')

回答(1 个)

Matt J
Matt J 2021-11-6
编辑:Matt J 2021-11-6
Rather than using loops, you should probably do a grid search using ndgrid just to see if the equations ever get close to zero.
[U{1:5}]=ndgrid(0:0.15:1.5);
U=cellfun(@(x) x(:),U,'uni',0);
UAll=cell2mat(U);
Then evaluate your equations at all the grid points with,
Eq1= abs( A1*U{1}.^3 + B1*U{2}.^3 + Z1*U{3}.^3 + ... );
Eq2= abs( A2*U{1}.^3 + B2*U{2}.^3 + Z2*U{3}.^3 + ... );
...
EqAll=[Eq1,Eq2,Eq3,Eq4,Eq5];
Then see if/where the equations get simultaneously closest to zero,
[minval,location] = min( max( EqAll ,[],2 ) , 'all');
minval,
UAll(location,:)

类别

Help CenterFile Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by