hamid
hamid

Reputation: 1

Plot surface in cylindrical coordinate system in matlab

I have a function and want to plot it on cylindrical coordinate.

w(z,theta)=sin(n.pi.z/a).sin(m.theta) 

The limits of variables are: z=0..a , theta=0..theta_0 and radius of cylinder is R=1.

As a physical sense I can explain that if we in the Cartesian coordinate, z & theta are x,y axis and w is surface on this rectangular domain. But in cylindrical coordinate z & theta restrict one cylindrical piece of cylinder with radius=1 that w is surface on this domain.

Upvotes: 0

Views: 8739

Answers (1)

brainkz
brainkz

Reputation: 1345

Plotting using cylindrical or spherical coordinates involves several steps:

  1. Create vectors for theta and z:

    theta = linspace(0,2*pi); z = linspace(0,10);

  2. Create a meshgrid from theta and z:

    [TH,Z] = meshgrid(theta,z);

  3. Write your function R(TH,Z):

    R = sin(Z)+1+5*sin(TH); %// For cylinder it would be simply R = ones(size(Z));

  4. Convert cylindrical coordinates to cartesian:

    [x,y,z] = pol2cart(TH,R,Z);

  5. Plot the result using surf, mesh or whatever:

    mesh(x,y,z); axis equal

This is the result you get: enter image description here

Upvotes: 2

Related Questions