Problem with the fsolve function in MatLab

조회 수: 3(최근 30일)
Andrian Mirza
Andrian Mirza 2020년 10월 6일
답변: Walter Roberson 2020년 10월 6일
This is the function I try using for determining both CA0 and CB0
function F = root2d(x)
T12 = 22 + 273.15;
R = 8.314;
k1 = 74900*exp(-8050/(R*T12));
xA1 = 0.788;
xA2 = 0.974;
xA0 = 0;
t1 = 30;
t2 = 120;
%x(1) = CA0
%x(2) = CB0
F(1) = (2*log(1-xA1) - 2 * log(-x(1)*xA1 + 2*x(2))) - (2*log(1-xA0) - 2 * log(2*x(2))) - k1*t1*(x(2)-2*x(1));
F(2) = (2*log(1-xA2) - 2 * log(-x(1)*xA2 + 2*x(2))) - (2*log(1-xA0) - 2 * log(2*x(2))) - k1*t2*(x(2)-2*x(1));
Then I input it in this program:
fun = @root2d
x0 = [0,0];
x = fsolve(fun,x0)
Can someone help with what is going wrong here?
Why the problem can't be solved?
May it be related to the values [0,0]?
Because if both of them are 0 at the same time the equation can't be solved.
Thanks everyone in advance!
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 10월 6일
Yes, you will need to use a different initial conditon.
Also you will probably need to use an options structure to increase the iterations limit.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 6일
fsolve can solve the system, but it requires that the second x input be between about 5e-6 and 1.1e-5 . Smaller values will lead to complex solutions; larger values will lead to no solution with the results not being even remotely close.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by