symbolically/parametric solving a nonlinear equation in Matlab

3.1k Views Asked by At

I have these two equations where x, y and z are variables and p1, p2 and p3 are parameter. Can MATLAB find parametric/symbolic solutions for x y z based on p1, p2, p3?

  • 2(x−p1)+2(xy−p3)y = 0
  • 2(y−p2)+2(xy−p3)x = 0
1

There are 1 best solutions below

11
On BEST ANSWER

Simply put yes. Take all of your variables, use syms to define each of your variables so that they are symbolic variables, then use solve to solve the equation for you. You specify the two equations as two parameters into solve. The output (which we will store in sol) will return a structure that contains an x field and a y field, as your equation is defined with respect to two variables, and p1,p2,p3 are parameters. In other words, do this:

syms p1 p2 p3;
syms x y;
sol = solve(2*(x-p1)+2*(x*y-p3)*y == 0, 2*(y-p2)+2*(x*y-p3)*x == 0);

You can access the solution of what x and y are by accessing each of their respective fields:

>> sol.x

ans =

(p1^3 + p3*p1^2*z1 + p1*z1^4 - 1.0*p2*p1*z1^3 + p1*z1^2 - 1.0*p2*p1*z1 + p3*z1^3 - 1.0*p2*p3*z1^2 + p3*z1 - 1.0*p2*p3)/(p1^2 + p3^2)

>> sol.y

ans =

z1

You will get a warning though, stating that the solution is parametrized by symbols, but that is to be expected. Specifically:

Warning: The solutions are parametrized by the symbols:
z1 = RootOf(z^5 - p2*z^4 + 2*z^3 - z^2*(2*p2 - p1*p3) + z*(p1^2 - p3^2 + 1) - p1*p3 - p2, z)