how to use fsolve function

7 views (last 30 days)
sermet
sermet on 24 Feb 2014
Edited: Matt J on 24 Feb 2014
%I have 3 nonlinear equation. I need to find unknowns I tried fsolve function but I couldn't use it properly, could anyone explain for me how can I use fsolve function?
(-4.71777*10^21)+(2.10263*(10^15)*x0)-(3.49196*(10^8)*(x0^2))+(28*x0^3)+(1.56321*(10^14)*y0)-(3.76035*(10^7)*x0*y0)-(1.16399*(10^8)*y0^2)+(28*x0*y0^2)+(1.11156*(10^15)*z0)-(2.6739*(10^8)*x0*z0)-(1.16399*(10^8)*z0^2)+(28*x0*z0^2)==0
(-7.62057*10^20)+(1.56321*(10^14)*x0)-(1.88017*(10^7)*x0^2)+(1.16012*(10^15)*y0)-(2.32797*(10^8)*x0*y0)+(28*(x0^2)*y0)-(5.64052*(10^7)*y0^2)+(28*y0^3)+(1.7955*(10^14)*z0)-(2.6739*(10^8)*y0*z0)-(1.88017*(10^7)*z0^2)+(28*y0*z0^2)==0
(-5.41882*(10^21)+(1.11156*(10^15)*x0)-(1.33695*(10^8)*x0^2)+(1.7955*(10^14)*y0)-(1.33695*(10^8)*y0^2)+(2.41161*(10^15)*z0)-(2.32797*(10^8)*x0*z0)+(28*(x0^2)*z0)-(3.76035*(10^7)*y0*z0)+(28*(y0^2)*z0)-(4.01085*(10^8)*z0^2)+(28*z0^3)==0
%x0,y0,z0 are the unknowns.
  2 Comments
Star Strider
Star Strider on 24 Feb 2014
Post the code you used.
sermet
sermet on 24 Feb 2014
function F = myfun(x)
F = [(-4.71777*10^21)+(2.10263*(10^15)*x0)-(3.49196*(10^8)*(x0^2))+(28*x0^3)+(1.56321*(10^14)*y0)-(3.76035*(10^7)*x0*y0)-(1.16399*(10^8)*y0^2)+(28*x0*y0^2)+(1.11156*(10^15)*z0)-(2.6739*(10^8)*x0*z0)-(1.16399*(10^8)*z0^2)+(28*x0*z0^2;(-7.62057*10^20)+(1.56321*(10^14)*x0)-(1.88017*(10^7)*x0^2)+(1.16012*(10^15)*y0)-(2.32797*(10^8)*x0*y0)+(28*(x0^2)*y0)-(5.64052*(10^7)*y0^2)+(28*y0^3)+(1.7955*(10^14)*z0)-(2.6739*(10^8)*y0*z0)-(1.88017*(10^7)*z0^2)+(28*y0*z0^2);(-5.41882*(10^21)+(1.11156*(10^15)*x0)-(1.33695*(10^8)*x0^2)+(1.7955*(10^14)*y0)-(1.33695*(10^8)*y0^2)+(2.41161*(10^15)*z0)-(2.32797*(10^8)*x0*z0)+(28*(x0^2)*z0)-(3.76035*(10^7)*y0*z0)+(28*(y0^2)*z0)-(4.01085*(10^8)*z0^2)+(28*z0^3)]
x0 = [-5; -5]; y0=[1 1] z0=[1 1]
options=optimset('Display','iter');
[x0,y0,z0,fval] = fsolve(@myfun,x0,y0,z0,options) % Call solver

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 24 Feb 2014
eqn1 = @(x0, y0, z0) (-4.71777*10^21)+(2.10263*(10^15)*x0)-(3.49196*(10^8)*(x0^2))+(28*x0^3)+(1.56321*(10^14)*y0)-(3.76035*(10^7)*x0*y0)-(1.16399*(10^8)*y0^2)+(28*x0*y0^2)+(1.11156*(10^15)*z0)-(2.6739*(10^8)*x0*z0)-(1.16399*(10^8)*z0^2)+(28*x0*z0^2);
eqn2 = @(x0, y0, z0) (-7.62057*10^20)+(1.56321*(10^14)*x0)-(1.88017*(10^7)*x0^2)+(1.16012*(10^15)*y0)-(2.32797*(10^8)*x0*y0)+(28*(x0^2)*y0)-(5.64052*(10^7)*y0^2)+(28*y0^3)+(1.7955*(10^14)*z0)-(2.6739*(10^8)*y0*z0)-(1.88017*(10^7)*z0^2)+(28*y0*z0^2);
eqn3 = @(x0, y0, z0) (-5.41882*(10^21)+(1.11156*(10^15)*x0)-(1.33695*(10^8)*x0^2)+(1.7955*(10^14)*y0)-(1.33695*(10^8)*y0^2)+(2.41161*(10^15)*z0)-(2.32797*(10^8)*x0*z0)+(28*(x0^2)*z0)-(3.76035*(10^7)*y0*z0)+(28*(y0^2)*z0)-(4.01085*(10^8)*z0^2)+(28*z0^3);
fun = @(x) [eqn1(x(1), x(2), x(3)); eqn2(x(1), x(2), x(3)); eqn3(x(1), x(2), x(3))];
now you can fsolve(fun, x0)

More Answers (1)

Matt J
Matt J on 24 Feb 2014
Edited: Matt J on 24 Feb 2014
Your initial guesses x0, y0, z0 should not be passed in separate scalar arguments to myfun (notice your myfun also accepts only a single input argument vector, as it should!). Also, fsolve will not return the solution vector components as separate scalar arguments.
  2 Comments
sermet
sermet on 24 Feb 2014
could you write the codes I need please
Matt J
Matt J on 24 Feb 2014
Edited: Matt J on 24 Feb 2014
[solution,fval] = fsolve(@myfun,[x0,y0,z0],options) % Call solver

Sign in to comment.

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!