フィルターのクリア

How to use fsolve to solve this system of equations?

116 ビュー (過去 30 日間)
Thien Son Phan
Thien Son Phan 2018 年 2 月 16 日
コメント済み: Walter Roberson 2018 年 2 月 16 日
So I need to use fsolve on this to solve the following system of four equations:
2x=-2kx
2y=-ky
2z=-k
2-(x^2)-(1/2)(y^2)-z=0.
I therefore assigned x(1) to x, x(2) to y, x(3) to z, and x(4) to k. This is what I typed:
x0=[0,0,2,0];
fsolve(@(x)[2.*x(1)+2.*x(2).*x(4);2.*x(2)+x(2).*x(4);2.*x(3)+x(4);2-(x(1).^2)-0.5.*(x(2).^2)-x(3)],[x0])
Apparently, there should be five solutions, but matlab is only returning one:
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
ans =
-0.0000 0 2.0000 -4.0000
How can I get matlab to compute and display the other solutions?
  1 件のコメント
Matt
Matt 2018 年 2 月 16 日
編集済み: Matt 2018 年 2 月 16 日
Hi Thien,
The fsolve function will give you a solution to your equations, but it's an optimization type function. So it tries to find a minimum around the initial guess you provide it. For instance, if you change it to x0 = [-1,-1,-1,-1], you will get a different solution.
Matt

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

回答 (1 件)

Matt
Matt 2018 年 2 月 16 日
If you have the Symbolic Math Toolbox in MATLAB, you can get all 5 solutions exactly.
syms k x y z
eqns = [2*x == -2*k*x,...
2*y == -k*y,...
2*z == -k,...
2-(x^2)-(1/2)*(y^2)-z == 0];
vars = [k,x,y,z];
[solk,solx,soly,solz] = solve(eqns,vars);
solutions = [solk,solx,soly,solz]
  2 件のコメント
Thien Son Phan
Thien Son Phan 2018 年 2 月 16 日
These codes don't seem to use fsolve though...
Walter Roberson
Walter Roberson 2018 年 2 月 16 日
It is never possible to get fsolve() to display more than one solution. The closest you can get is to run fsolve on different equations or on different starting points, hoping that you manage to find all of the solutions.

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

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by