Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Modeling Gravity with Matlab

  1. Sep 1, 2006 #1
    I am trying to model gravity with vector field lines in Matlab. I can kinda do it with a 2D plot, but I cant quite grasp the "scale" field in the quiver function. I then tried to model in 3D vectors and I just made a mess w/ that. Below is my simple 3D and 2D code.

    Help w/ this code or if you know a better way to do this would be nice!

    non working 3D plot
    [X Y Z] = meshgrid(-3:.1:3);
    r = sqrt(X.^2 + Y.^2 + Z.^2);
    ag = 1./r.^2;
    [ax ay az] = gradient(ag);
    quiver3(X, Y, Z, ax, ay, az)

    Poor 2D plot
    M = 1; %Mass of Earth in kg
    G = 1; %Gravitational Constant
    R = 1; %Radius of Earth in m
    [x y] = meshgrid(-3:.75:3);
    r = sqrt(x.^2 + y.^2);
    ag = G*M./r.^2;
    [ax ay] = gradient(ag);
    contour(x,y,r,[R R])
    colormap cool
    hold on
    scale = 0;
    quiver(x,y,ax,ay,scale)
    hold off
     
    Last edited: Sep 1, 2006
  2. jcsd
  3. Sep 1, 2006 #2

    Integral

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Prehaps you could post an image file of some sort. I cannot open your .m file and will not aprove it without doing so.
     
  4. Sep 1, 2006 #3
    is this better?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Modeling Gravity with Matlab
  1. Modeling and Matlab (Replies: 3)

  2. 3D modelling in MATLAB (Replies: 2)

Loading...