How can I accurately model gravity using vector fields in Matlab?

In summary, the conversation is about trying to model gravity using vector field lines in Matlab. The person has tried both 2D and 3D plots, but is struggling with understanding the "scale" field in the quiver function. They have shared their code for both plots and are asking for help or a better way to approach the problem.
  • #1
Dirty D
6
0
I am trying to model gravity with vector field lines in Matlab. I can kinda do it with a 2D plot, but I can't 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:
Physics news on Phys.org
  • #2
Prehaps you could post an image file of some sort. I cannot open your .m file and will not aprove it without doing so.
 
  • #3
is this better?
 

1. How can I use Matlab to model gravitational forces between objects?

Matlab has built-in functions and tools that allow you to create models of gravitational forces between objects. You can use the "gravitational constant" function and the "force of gravity" function to calculate the forces between two objects. You can also use the "plot" function to create visual representations of the gravitational forces.

2. Can I use Matlab to simulate the motion of objects under the influence of gravity?

Yes, you can use Matlab to simulate the motion of objects under the influence of gravity. You can use the "ode45" function to solve the equations of motion for an object in a gravitational field. You can also use the "animate" function to create animations of the object's motion.

3. How do I incorporate variables such as mass and distance into my gravity model?

In Matlab, you can use variables to represent mass and distance in your gravity model. You can also use arrays to represent multiple objects with different masses and distances. By incorporating these variables, you can create more complex and realistic gravity models.

4. Can I use Matlab to compare different models of gravity?

Yes, you can use Matlab to compare different models of gravity. By using the "plot" function, you can create visualizations of the different models and compare them side by side. You can also use the "error" or "residuals" functions to analyze the accuracy of each model.

5. Are there any resources available for learning how to model gravity with Matlab?

Yes, there are plenty of resources available for learning how to model gravity with Matlab. The MathWorks website has tutorials and examples specifically for modeling gravity. There are also many online forums and communities where you can ask questions and learn from others who have experience with modeling gravity in Matlab.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
565
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
993
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top