Using Fsolve to find value of 2 variables with different functions
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Walter Roberson
2020년 5월 8일
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
Walter Roberson
2020년 5월 9일
[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 ?
참고 항목
카테고리
Help Center 및 File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!