Using fsolve to solve a constrained system of nonlinear equations

1 次查看(过去 30 天)
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.

回答(1 个)

Walter Roberson
Walter Roberson 2018-5-25
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 个评论
Mitchell Shinn
Mitchell Shinn 2018-5-25
HI Walter,
Thanks for the assistance. Can you point me to some additional resources that might help me restructure my equations for input?
The purpose of this script is to solve a multiple pipe path problem. This involves fluid flowing through a pipe and then branching off into parallel branches that recombine downstream. This is similiar to solving an electrical circuit via nodal and loop analysis, however the equations are inherently non-linear, and must be solved iterratively and not simply with inv().
Walter Roberson
Walter Roberson 2018-5-25
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Problem-Based Optimization Setup 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by