Hello,
I have two nonlinear equations to solve simultaneously:
syms x, y
f1 = x^2 + y^2 + x == 4
f2 = x^3 + y*2 == 2
I want to find the solutions (if there's any), when x belongs to the range of [-1,1]. And I don't want to make another matlab file whose purpose is to group the above equations. Because most of the time, the equations are derived from the using symbolic tools earlier in same matlab script and it would be inconvenient to make a separate file.
In this case, what is the way to achieve my goal?
Thanks in advance.
Steph

 채택된 답변

Matt J
Matt J 2018년 10월 17일

2 개 추천

syms x y
assume(x>=-1 & x<=1)
f1 = x^2 + y^2 + x == 4
f2 = x^3 + y*2 == 2
[solx,soly]=vpasolve(f1,f2,x,y)

댓글 수: 8

Stephen
Stephen 2018년 10월 17일
Fantastic! Thank you very much.
madhan ravi
madhan ravi 2018년 10월 17일
편집: madhan ravi 2018년 10월 17일
Are you sure solx and soly return empty values
Matt J
Matt J 2018년 10월 17일
Empty values are the correct answer here. The equations have no solution for -1<=x<=+1.
madhan ravi
madhan ravi 2018년 10월 17일
+1 Oh thank you @Matt learnt a new method using vpasolve()
Stephen
Stephen 2018년 10월 19일
편집: Stephen 2018년 10월 19일
Following up this thread.
If I would like to use "fsolve" command for these non-linear equations, do I have to define all the functions in a seperate m-file? Can I use "function handle" for the task?
I use fsolve because I want to adjust the stopping criteria for vpasolve. I don't really need it to be as accurate as 10^-12.
Matt J
Matt J 2018년 10월 19일
편집: Matt J 2018년 10월 19일
You can't apply bounds with fsolve, but you can with lsqnonlin. Yes, the input is to be a function handle. The function can reside anywhere that a function handle can find it, e.g., it can be a separate mfile, or a nested function, or an anonymous function, or a local function, or a class method, or a class-related function.
Stephen
Stephen 2018년 10월 19일
편집: Stephen 2018년 10월 19일
Isn't that function is supposed to be used for curve fitting?
How do I convert those two non-linear equations so that I can use lsqnonlin?
Matt J
Matt J 2018년 10월 19일
편집: Matt J 2018년 10월 19일
Example:
fun=@(p) [p(1)^2+p(2)^2+p(1)-4; p(1)^2+2*p(2)-2];
[p,resnorm,~,exitflag]=lsqnonlin(fun,[0,0],[-3,-inf],[+3,+inf])
if resnorm>TOO_BIG
warning 'The result does not satisfy equations well.'
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

질문:

2018년 10월 17일

편집:

2018년 10월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by