MATLAB: Solve nonlinear equations within range

nonlinear equations

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.

Best Answer

  • syms x y
    assume(x>=-1 & x<=1)
    f1 = x^2 + y^2 + x == 4
    f2 = x^3 + y*2 == 2