plotting cone on matlab

990 Views Asked by At

Plot the portion of the cone $z=sqrt((x − 1)^2 + y^2)$ inside the cylinder $r = 2$

This is my matlab code. However, I get an error with the ezsurf line. Any ideas as to what I might be doing wrong?

clear all;
syms theta z;
rbar = [2*cos(theta),2*sin(theta),sqrt((2*cos(theta)-1)^2+2*sin(theta)^2)];
ezsurf(rbar(1),rbar(2),rbar(3),[0,2*pi,0,5])
view([10 10 10])
1

There are 1 best solutions below

0
On

It would help if you showed what error you are getting, but the crux of your problem is this: ezsurf requires your input functions to be in two variables. Your functions rbar are all simply functions of theta.

You might want to use ezplot3 instead. Example:

r1 = @(theta)2*cos(theta);
r2 = @(theta)2*sin(theta);
r3 = @(theta)sqrt((2*cos(theta)-1)^2+2*sin(theta)^2);
ezplot3(r1,r2,r3,[0,2*pi])

This technique uses function handles instead of the Symbolic Toolbox.

(My kingdom for people to stop using the Symbolic Toolbox).