Results 1 to 4 of 4

Math Help - Matlab mesh problem

  1. #1
    Newbie
    Joined
    Mar 2009
    Posts
    2

    Matlab mesh problem

    Hi,
    I'm having a problem with the mesh & surf commands in Matlab. I am trying to plot a 3D contour, Z, in a limited area.

    Using plot3 as follows works fine:

    Code:
     
    for theta1 = -0.5:0.05:2.5
    for theta2 = -0.5:0.05:2.5
     
    Z = ((0.1150 * sin(theta1) * cos(theta2) * 9.81 + 0.1150 * cos(theta1) * sin(theta2) * 9.81 + 0.3990 * sin(theta1) * g) ^ 2 / 20) + (0.00013)
     
    plot3(theta1,theta2,Z);
     
    end
    end
    But as mesh is clearer I'd prefer to use that.
    However when I try following the Matlab example my plot seems to ignore one of my input arguments producing a Z matrix where all the rows are identical? I've spent quite a bit of time on this and just can't get the bottom of it. I'd realy appreciate any suggestions...

    Here is my code:
    Code:
     
    [theta1,theta2] = meshgrid(-0.5:0.05:2.5);
    Z = ((0.1150 * sin(theta1) * cos(theta2) * 9.81 + 0.1150 * cos(theta1) * sin(theta2) * 9.81 + 0.3990 * sin(theta1) * g) ^ 2 / 20) + (0.00013)
    mesh(theta1,theta2,Z);
    Strangely ezmesh seems to work fine but I'd like to know why mesh doesn't like my equation (which plot3 does like).

    Many Thanks,

    Ad

    Follow Math Help Forum on Facebook and Google+

  2. #2
    Newbie
    Joined
    Mar 2009
    Posts
    2

    Sort of a solution

    Just as a follow up for anyone else who is having this problem...

    This method gives the result I wanted but I still don't know why my first method didn't work?

    Code:
     
    t1 = -0.5:0.1:3;
    t2 = -0.5:0.1:3;
     
    Z = zeros(length(t1)); % create a matrix of n*n dimension
     
    for(i = 1:length(Z2))
     for(j = 1:length(Z2))
      th1 = t1(i);
      th2 = t2(j);
     
      Z(i,j) = (my equation);
     
     end
    end
     
    mesh(t2,t1,Z)

    Ad
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by ADNL View Post
    Hi,
    I'm having a problem with the mesh & surf commands in Matlab. I am trying to plot a 3D contour, Z, in a limited area.

    Using plot3 as follows works fine:

    Code:
     
    for theta1 = -0.5:0.05:2.5
    for theta2 = -0.5:0.05:2.5
     
    Z = ((0.1150 * sin(theta1) * cos(theta2) * 9.81 + 0.1150 * cos(theta1) * sin(theta2) * 9.81 + 0.3990 * sin(theta1) * g) ^ 2 / 20) + (0.00013)
     
    plot3(theta1,theta2,Z);
     
    end
    end
    But as mesh is clearer I'd prefer to use that.
    However when I try following the Matlab example my plot seems to ignore one of my input arguments producing a Z matrix where all the rows are identical? I've spent quite a bit of time on this and just can't get the bottom of it. I'd realy appreciate any suggestions...

    Here is my code:
    Code:
     
    [theta1,theta2] = meshgrid(-0.5:0.05:2.5);
    Z = ((0.1150 * sin(theta1) * cos(theta2) * 9.81 + 0.1150 * cos(theta1) * sin(theta2) * 9.81 + 0.3990 * sin(theta1) * g) ^ 2 / 20) + (0.00013)
    mesh(theta1,theta2,Z);
    Strangely ezmesh seems to work fine but I'd like to know why mesh doesn't like my equation (which plot3 does like).

    Many Thanks,

    Ad

    Check the sizes of theta1, theta2 and Z in all cases.

    CB
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Super Member Showcase_22's Avatar
    Joined
    Sep 2006
    From
    The raggedy edge.
    Posts
    782
    For your first method you never defined g.

    g=9.81?

    Also, sin(theta1) and sin(theta2) have the same dimension of 1x60 so they can't be multiplied together. You're going to have to do sin(theta1)*sin(theta2)' to make the matrix dimensions agree.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Divergence and Laplacian of a FEM mesh?
    Posted in the Differential Equations Forum
    Replies: 2
    Last Post: April 10th 2011, 05:55 AM
  2. Transform a Mesh (Grid)
    Posted in the Algebra Forum
    Replies: 4
    Last Post: October 16th 2010, 12:52 AM
  3. Replies: 17
    Last Post: August 22nd 2010, 11:40 PM
  4. Mesh and Nodal Analysis
    Posted in the Advanced Applied Math Forum
    Replies: 0
    Last Post: January 24th 2010, 08:18 AM
  5. mesh
    Posted in the Calculus Forum
    Replies: 1
    Last Post: March 4th 2008, 01:55 PM

Search Tags


/mathhelpforum @mathhelpforum