Using fsolve to solve a constrained system of nonlinear equations
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to use fsolve to solve a system of non-linear equations. However, when I run this script. I am receiving an error stating that "no solution found. fsolve stopped because the last step was ineffective." My code follows:
clear all;close all;clc
mdot_tot = 15;
n_branch = 3;
mdot0 = (0.5*mdot_tot/n_branch).*ones(1,n_branch);
dP = @(mdot)branches(mdot,mdot_tot);
options = optimoptions('fsolve','Algorithm',...
'levenberg-marquardt','StepTolerance',1e-5,'Display','iter');
[mdot,dP] = fsolve(dP,mdot0,options)
function P = branches(mdot,mdot_tot)
P(1) = (0.040288*(mdot(1)^2)) + (0.01612*mdot(1)^2);
P(2) = (0.0875*mdot(2)^2);
P(3) = (0.04029 + 0.06043)*(mdot(3)^2);
P(3) = mdot_tot - mdot(1) - mdot(2) - mdot(3);
end
P(3) is required for a constraint that all mdot need to sum to mdot_tot. If I remove this branch fsolve finds a solution, but this solution is not for the mdot_tot that I require.
0 Commenti
Risposte (1)
Walter Roberson
il 25 Mag 2018
Reduce the number of variables by one and calculate the third inside the routine:
mdot_tot = 15;
n_branch = 3;
mdot0 = (0.5*mdot_tot/n_branch).*ones(1,n_branch-1);
dP = @(mdot)branches(mdot,mdot_tot);
options = optimoptions('fsolve','Algorithm',...
'levenberg-marquardt','StepTolerance',1e-5,'Display','iter');
[mdot,dP] = fsolve(dP,mdot0,options)
function P = branches(mdot,mdot_tot)
mdot1 = mdot(1);
mdot2 = mdot(2);
mdot3 = mdot_tot - (mdot1 + mdot2);
P(1) = (0.040288*(mdot1^2)) + (0.01612*mdot1^2);
P(2) = (0.0875*mdot2^2);
P(3) = (0.04029 + 0.06043)*(mdot3^2);
end
However, it is easy to see that this cannot have a solution. Your P(1) involves only mdot(1) and has no additive constants, and so can be zero only if mdot(1) is zero. Likewise clearly your P(2) can be zero only if mdot(2) is zero. That forces mdot3 to be mdot_tot, but mdot3 has to be zero for P(3) to be zero. Your equations are inconsistent.
2 Commenti
Walter Roberson
il 25 Mag 2018
What nonlinear form do they have? The equations you posted do not use trig or exp or sqrt, just using linear and squared terms. That leads to polynomial equations, and those can be solved down to roots of polynomials to find all possible solutions.
Vedere anche
Categorie
Scopri di più su Problem-Based Optimization Setup in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!