Earth orbiting around the sun using Euler
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Signe Helene Tveitaskog Vesterøy
am 15 Feb. 2021
Kommentiert: Walter Roberson
am 16 Feb. 2021
I am not fluent in matlab, nor in physics, but I am trying to make a simple simulation of the earth orbiting around the sun, though it doesn't seem to work. I want to use Euler to calculate the coordinates in 2-D. I thought the points would end up in a more or less circular plot, but I am just getting a straight line... I'm using nasa to get the data, and I want the sun to be in origo. After doing some reading online, I still can't seem to figure what I am doing wrong..
Here is what I've got so far:
%bodies = {'sun','earth','moon'};
mass = [1.989e8 5.972e2 7.349].*1e22;
% The positions (x,y)
xx = [0 -7.461557189835504E-01];
yy = [0 6.451970837257494E-01];
% The velocities (vx,vy)
ux= [0 -1.154054959303684E-02];
uy= [0 -1.307896092314608E-02];
G = 6.67e-11;
%M = mass(1)*mass(2);
M = mass(1);
x0 = xx(2); y0 = yy(2); vx0 = ux(2); vy0=uy(2);
t0 = 0;
x(1)=x0;
y(1)=y0;
vx(1)=vx0;
vy(1)=vy0;
t(1) = t0;
fvx = @(x,y) -(G*M*x/((x^2+y^2)^(3/2)));
fvy = @(x,y) -(G*M*y/((x^2+y^2)^(3/2)));
steps = 1000;
dt = 1/steps;
for k=1:steps-1
vx(k+1) = vx(k) + fvx(x(k),y(k))*dt;
vy (k+1) = vy(k) + fvy(x(k),y(k))*dt;
x(k+1) = x(k)+vx(k+1)*dt;
y(k+1) = y(k)+vy(k+1)*dt;
t(k+1) = t(k) + dt;
%plot(x(k+1),y(1+k),'-b');
%drawnow;
end
figure
hold on
plot(x,y,'r')
drawnow;
0 Kommentare
Antworten (2)
Walter Roberson
am 15 Feb. 2021
Bearbeitet: Walter Roberson
am 15 Feb. 2021
The time unit for G is s^-2
Your maximum time is (steps-1)/steps which is going to be just less than 1. 1 what? Well since you do not apply any scaling to G we have to conclude "1 second"
Therefore you have carefully plotted orbits in thousands of a second for one second, and you are expecting visible curvature.
How far is your Earth from your Sun? Well the unit of G involves m^3 and your first object is 7e-1 away from the second, so we conclude that your simulated Earth is about 70 cm away from the center of mass of the Sun.
Unfortunately, if you concentrate the mass of the sun into that small of a radius then you would have a black hole and the radius of the black hole would be between 5 and 6 kilometres. Thus if you want to plot the orbit of the Earth 75 cm from the center of mass of the Sun, you either have to model conditions inside a black hole or else you have to reduce the effective mass of the Sun as much of it would be "above" the Earth and so pulling up on the Earth reducing the effective mass.
0 Kommentare
Signe Helene Tveitaskog Vesterøy
am 15 Feb. 2021
Bearbeitet: Walter Roberson
am 16 Feb. 2021
1 Kommentar
Walter Roberson
am 16 Feb. 2021
%plot(x(k+1),y(k+1),'r');
That would only plot one point at a time, and plot() only draws lines between plot points if there are at least two consecutive finite endpoints. If you had specified a marker such as 'r*-' then you would have seen the markers.
See also animatedline()
Siehe auch
Kategorien
Mehr zu Gravitation, Cosmology & Astrophysics finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!