Filter löschen
Filter löschen

How to use fsolve to solve this system of equations?

116 Ansichten (letzte 30 Tage)
Thien Son Phan
Thien Son Phan am 16 Feb. 2018
Kommentiert: Walter Roberson am 16 Feb. 2018
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 Kommentar
Matt
Matt am 16 Feb. 2018
Bearbeitet: Matt am 16 Feb. 2018
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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Matt
Matt am 16 Feb. 2018
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 Kommentare
Thien Son Phan
Thien Son Phan am 16 Feb. 2018
These codes don't seem to use fsolve though...
Walter Roberson
Walter Roberson am 16 Feb. 2018
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.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by