Using Fsolve to find value of 2 variables with different functions
1 view (last 30 days)
Show older comments
I am trying to solve a system of equations with variables xp and xq. Each is defined by a different function and has a different value at 4 stages: xp(1), xp(2), xp(3), xp(4) ect.
I tried to find a solution by writing out all the equations and using vpasolve but there were 16 equations and no solution was found after 20 minutes. I have found similar examples using fsolve but I don't know how to adapt this code to solve for two variables (xp and xq). Any help or suggestions of an alternative approach would be appreciated.
function x =LLESolver(xp,xq)
N=4
x0=ones(N*2,1);
[x,fval]=fsolve(@LLE,x0,xp,xq)
function P=LLE(xp,xq)
xpa = 1.2; % kg/m3, conc. of solute in entering aqueous stream
ypb = 0.0;
L = 2.0; % m3/s
V = 1.0; % m3/s
N = 4;
xqa = 1.6; % kg/m3, conc. of solute in entering aqueous stream
yqb = 0.0;% kg/m3, conc. of solute in entering organic stream
for i=1:4
if i==1
P(i)=L*(xpa-x(i))-V*(EquRel_P(i)-EquRel_P(i+1))
elseif i==N
P(i)=L*(xp(i-1)-x(i))-V*(EquRel_P(i)-ypb)
else
P(i)=L*(xp(i-1)-x(i))-V*(EquRel_P(i)-EquRel_P(i+1))
end
end
for i=5:8
if i==5
P(i)=L(xqa-x(i))-V*(EquRel_Q(i)-EquRel_Q(i+1))
elseif i==8
P(i)=L*(x(i-1)-x(i))-V*(EquRel_Q(i)-yqb )
else
P(i)=L(xqa-x(i))-V*(EquRel_Q(i)-EquRel_Q(i+1))
end
end
2 Comments
Answers (1)
Walter Roberson
on 8 May 2020
function x =LLESolver(xp,xq)
N = 4;
x0 = ones(N*2,1);
[x,fval]=fsolve(@(x) LLE(x, xp, xq), x0)
function P = LLE(x, xp, xq)
3 Comments
Walter Roberson
on 9 May 2020
[x,fval]=fsolve(@(xp) LLE(xp, xq), x0)
with
function P = LLE(xp, xq)
However, what do you want to do with the xp that was passed into LLESolver ?
See Also
Categories
Find more on Systems of Nonlinear Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!