Hi I am trying to solve a system of equations using fsolve or something similar with 4 variables. Please help

2 ビュー (過去 30 日間)
Equations are
r(1)= sqrt((x-15600)^2+(y-7540)^2+(z-20140)^2)-(300000(0.07074-d))
r(2)=sqrt((x-18760)^2+(y-2750)^2+(z-18610)^2)-(300000(0.07220-d))
r(3)=sqrt((x-17610)^2+(y-14630)^2+(z-13480)^2)-(300000(0.07690-d))
r(4)=sqrt((x-19170)^2+(y-610)^2+(z-18340)^2)-(300000(0.07242-d))
I am trying to use fsolve
F=nle(x) ; I am actually substitution x,y,z,d as x(1)….x(4)
Then writing the equation for F and then i do x0= a range which i dont understand at all what to pick.
And then fsolve(@nle,x0)
I am getting a lot of errors and nowhere near to my answer.

採用された回答

Mischa Kim
Mischa Kim 2014 年 3 月 3 日
編集済み: Mischa Kim 2014 年 3 月 3 日
Rishav, try
function r = test(r0)
% options = optimoptions('fsolve','Display','iter'); % new as of R2013a
% options = optimset('Display','iter','TolFun',1e-8); % before R2013a
% [r,fval] = fsolve(@myfun,r0,options)
[r,fval] = fsolve(@myfun,r0)
end
function F = myfun(r)
x = r(1);
y = r(2);
z = r(3);
d = r(4);
F = [sqrt((x-15600)^2+(y-7540)^2 +(z-20140)^2)-(300000*(0.07074-d));...
sqrt((x-18760)^2+(y-2750)^2 +(z-18610)^2)-(300000*(0.07220-d));...
sqrt((x-17610)^2+(y-14630)^2+(z-13480)^2)-(300000*(0.07690-d));...
sqrt((x-19170)^2+(y-610)^2 +(z-18340)^2)-(300000*(0.07242-d))];
end
and use in the MATLAB command window
r0 = [15000 10000 20000 0];
r = test(r0)
  4 件のコメント
Rishav
Rishav 2014 年 3 月 3 日
I only need values for x,y and z. I think in my assignment there is a hint that says to subtract equation 1 from the last 3. I think that makes them equal to zero. Not sure again why x=r(1)…… Sorry, i am still a rookie.
Mischa Kim
Mischa Kim 2014 年 3 月 3 日
編集済み: Mischa Kim 2014 年 3 月 3 日
OK. The above code should work, the options part is now commented out. Once you have this code running, you can use optimset, instead of optimoptions (new as of R2013a).
The starting values used above, r0 = [15000 10000 20000 0], seem to work.

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

その他の回答 (0 件)

カテゴリ

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