필터 지우기
필터 지우기

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 CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by