MATLAB Answers

plotting a nonlinear curve in matlab

5 views (last 30 days)
MatG on 11 Aug 2015
Commented: Walter Roberson on 12 Aug 2015
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


Sign in to comment.

Accepted Answer

Walter Roberson
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)


MatG on 12 Aug 2015
Thanks for the reply Walter.
The code I wrote:
a= -10; b=-10; d=-10; c = 2; r= 50; syms x y z [Sx,Sy,Sz] = solve( [(x-a)^2 + (y-b)^2+(z-d)^2 == (r^2), x^2+y^2 - (c^2)*z^2 == 0],[x,y,z]);
The output is:
??? Error using ==> char Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 165 vc = char(v);
Error in ==> solve at 67 [eqns,vars] = getEqns(varargin{:});
Error in ==> Quadric at 9 [Sx,Sy,Sz] = solve( [(x-a)^2 + (y-b)^2+(z-d)^2 == (r^2), x^2+y^2 - (c^2)*z^2 == 0],[x,y,z]);
Can any one help with this?
Walter Roberson
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".

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!