Solving set of nonlinear equations

1 view (last 30 days)
Stanley
Stanley on 11 Oct 2014
Answered: Matt J on 11 Oct 2014
Hi all,
I want to solve a set of non-linear equations (using fsolve), but the solver keeps giving errors. I am not much of a matlab user, but from what I've puzzled together I have written this in the editor, where I want to solve for x(1) and x(2):
function F = dep(x)
F = [log(1-(5.3e-3/2.1e-4))+x(1)-x(2)*(1-exp(-x(1)/x(2)));
log(1+2*x(1)*(1-exp(-x(1)/x(2))))-x(1)+x(2)*(1-exp(-x(1)/x(2)))];
end
I then define a range, and try to solve it, for example (I have played around with the numbers a bit):
x0=[1e-5 1e-1]
fsolve(@dep,x0)
, and I usually get an error referring to tolerances. I can't quite figure out what tolerances I should set, any help would be appreciated.
Many thanks!

Answers (1)

Matt J
Matt J on 11 Oct 2014
I don't get any errors, but I do end up with a complex-valued solution
>>[x,fval]=fsolve(@dep,x0)
x =
-3.1889 - 3.2233i 0.4995 - 0.5068i
fval =
1.0e-04 *
0.1903 + 0.1585i
-0.0021 - 0.0014i
because your equations contain the complex valued quantity
>> log(1-(5.3e-3/2.1e-4))
ans =
3.1879 + 3.1416i
I assume that that's a typo. The second equation also has a dangerous log expression that can become complex when the argument goes negative. It might be better to rewrite it as
(1+2*x(1)*(1-exp(-x(1)/x(2))))-exp(x(1)+x(2)*(1-exp(-x(1)/x(2)))) =0

Community Treasure Hunt

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

Start Hunting!