how to use fsolve function

8 ビュー (過去 30 日間)
sermet
sermet 2014 年 2 月 24 日
編集済み: Matt J 2014 年 2 月 24 日
%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 件のコメント
Star Strider
Star Strider 2014 年 2 月 24 日
Post the code you used.
sermet
sermet 2014 年 2 月 24 日
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

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2014 年 2 月 24 日
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)

その他の回答 (1 件)

Matt J
Matt J 2014 年 2 月 24 日
編集済み: Matt J 2014 年 2 月 24 日
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 件のコメント
sermet
sermet 2014 年 2 月 24 日
could you write the codes I need please
Matt J
Matt J 2014 年 2 月 24 日
編集済み: Matt J 2014 年 2 月 24 日
[solution,fval] = fsolve(@myfun,[x0,y0,z0],options) % Call solver

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSystems of Nonlinear Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by