0

I'm trying to program a smooth(?) cone in matlab where

z = x^2+y^2

x^2+y^2 = C

C = [1 1.4 1.7 2 2.2]

I've already realised I should use polar coordinates since it's a circular figure

clear all, clc, clf


theta = linspace(0,2*pi,1000)
r = [1 1.4 1.7 2 2.2] % De olika radierna

[r,theta] = meshgrid(r,theta)
z = r
x = r.*cos(theta)
y = r.*sin(theta)
figure
grid on
meshc(x,y,z)
xlabel('x')
ylabel('y')
zlabel('z')

However the problem that it's modelled from seems to be more of a smooth curve and I get a linear curve, not sure if I got it right and the original problem is not

If anyone has the book Calculus by Adams/Essex 8th Edition it's Figure 12.5 on page 674 that I'm trying to model in matlab.

NoeZ1
  • 3
  • 2
  • 1
    Despite its name, the [`cylinder`](http://es.mathworks.com/help/matlab/ref/cylinder.html) function might prove useful. You can specify an arbitrary generator curve as input, thus producing a cylinder – Luis Mendo Mar 27 '15 at 16:12

1 Answers1

0

Your code is great, actually. I would just add semicolons so it doesn't display all the variables (plus it runs a little faster). The issue is that you plotted the Z values directly in a linear fashion. You actually wanted to preserver the square term. Just look at my code, i only changed 2 lines

clear all, clc, clf

theta = linspace(0,2*pi,1000);
%i added extra terms .1 through .7
r = sqrt([.1,.2,.7,1,2,3,4,5]);
%r = [1 1.4 1.7 2 2.2] % De olika radierna

[r,theta] = meshgrid(r,theta)
z = r.*r;        %this restores the curve
%z = r
x = r.*cos(theta);
y = r.*sin(theta);
figure
grid on
meshc(x,y,z)
xlabel('x')
ylabel('y')
zlabel('z')

I added a few more points to r so the curve is more visible

from book plot

andrew
  • 2,451
  • 1
  • 15
  • 22