plotting a nonlinear curve in matlab
5 views (last 30 days)
Show older comments
I would like MATLAB to draw the plot for the curve described by the following equation, where for instance (a,b,d) = (-10,-10,-10) is a point in 3D cartesian space and c = 2. x and y are the variables. Are there any thoughts?
x^2(1+1/c.^2) -2ax + y^2(1+1/c.^2) - 2by+(a^2+b^2+d^2-r^2)-2d/c(sqrt(x^2+y^2)) = 0
ps. the equation is actually the intersection of a sphere and cone and can be seen in http://mathworld.wolfram.com/Cone-SphereIntersection.html
0 Comments
Accepted Answer
Walter Roberson
on 12 Aug 2015
If you have the Symbolic Toolbox, you can use solve(). But the solution involves a quartic so the solution will probably be in terms of RootOf(). You need two of the roots. Be careful, two of the roots might be spurious (and might be real-valued) so back-substitute and test before you accept a root at any given location.
For any given x you can use roots() to find the 4 y numerically:
roots([c^4+2*c^2+1, (-4*c^4-4*c^2)*b, (2*c^4+2*c^2)*a^2+(-4*c^4*x-4*c^2*x)*a+(6*c^4+2*c^2)*b^2+(2*d^2-2*r^2+2*x^2)*c^4+(-2*d^2-2*r^2+4*x^2)*c^2+2*x^2, -4*a^2*b*c^4+8*a*b*c^4*x-4*b^3*c^4+((-4*d^2+4*r^2-4*x^2)*c^4-4*c^2*x^2)*b, a^4*c^4-4*a^3*c^4*x+(2*b^2*c^4+(2*d^2-2*r^2+6*x^2)*c^4+2*c^2*x^2)*a^2+(-4*x*c^4*b^2+(-4*d^2*x+4*r^2*x-4*x^3)*c^4-4*x^3*c^2)*a+b^4*c^4+((2*d^2-2*r^2+2*x^2)*c^4+2*c^2*x^2)*b^2+(d^4+(-2*r^2+2*x^2)*d^2+r^4-2*x^2*r^2+x^4)*c^4+(-2*d^2*x^2-2*r^2*x^2+2*x^4)*c^2+x^4])
Be sure to cross-check the values.
For the a, b, c, d that you provide, the smallest positive r for which there are real-valued x and y that are solutions is r = 4*sqrt(5)+2*sqrt(5)*sqrt(2)
2 Comments
Walter Roberson
on 12 Aug 2015
I do not know at the moment why char is being mentioned. The code you posted is not the same as the code the error message was generated for: the code you posted is all on one line but the error message was for line 9. This does make a difference because you have no ";" between the "syms" and the assignment following in the code you posted.
If your MATLAB version is before (I think it is) R2010b, you might have to rewrite your comparisons A==B as (A)-(B) and allow it to assume the implicit "== 0".
More Answers (0)
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!