3

I am trying to solve equations with this code:

a = [-0.0008333 -0.025 -0.6667 -20];
length_OnePart = 7.3248;
xi = -6.4446;
yi = -16.5187;
syms x y
[sol_x,sol_y] = solve(y == poly2sym(a), ((x-xi)^2+(y-yi)^2) == length_OnePart^2,x,y,'Real',true);

sol_x = sym2poly(sol_x);
sol_y = sym2poly(sol_y);

The sets of solution it is giving are (-23.9067,-8.7301) and (11.0333,-24.2209), which are not even satisfying the equation of circle. How can I rectify this problem?

horchler
  • 18,384
  • 4
  • 37
  • 73
Ankush
  • 235
  • 3
  • 14

1 Answers1

0

If you're trying to solve for the intersection of the cubic and the circle, i.e., where y==poly2sym(a) equals (x-xi)^2+(y-yi)^2==length_OnePart^2 it looks like solve may be confused about something when the circle is represented parametrically rather than as single valued functions. It might also have to do with the fact that x and y are not independent solutions, but rather that the latter depends on the former. It also could depend on the use of a numeric solver in this case. solve seems to work fine with similar inputs to yours, so you might report this behavior to the MathWorks to see what they think.

In any case, here is a better, more efficient way to to tackle this as a root-solving problem (as opposed to simultaneous equations):

a = [-0.0008333 -0.025 -0.6667 -20];
length_OnePart = 7.3248;
xi = -6.4446;
yi = -16.5187;
syms x real
f(x) = poly2sym(a);
sol_x = solve((x-xi)^2+(f(x)-yi)^2==length_OnePart^2,x)
sol_y = f(sol_x)

which returns:

sol_x =

 0.00002145831413371390464567553686047
    -13.182825373861454619370838716408


sol_y =

 -20.000014306269544436430325843024
 -13.646590348358951818881695033728

Note that you might get slightly more accurate results (one solution is clearly at 0,-20) if you represent your coefficients and parameters more precisely then just four decimal places, e.g., a = [-1/1200 -0.025 -2/3 -20]. In fact, solve might be able to find one or more solutions exactly, if you provide exact representations.

Also, in your code, the calls to sym2poly are doing nothing other than converting back to floating-point (double can be used for this) as the inputs are not in the form of symbolic polynomial equations.

horchler
  • 18,384
  • 4
  • 37
  • 73
  • Thanx alot... could you plz help me to understand why is it not giving answer with `solve()` function. Bcoz it looks like solving same equations from both the above mentioned methods. – Ankush May 25 '14 at 18:11
  • 1
    @Ankush: I've updated the first part of my answer to be more nuanced. You really should be solving in a manner similar to what I show, but I think that `solve` still should be able to handle what what you gave it (usually it does in some tests I tried) and return sensible output or an error – I have no idea what the values you got pertain to. – horchler May 25 '14 at 18:51