# Pseudo coding a function help

2 Ansichten (letzte 30 Tage)
Abdullaziz Errayes am 10 Mai 2018
Bearbeitet: Jan am 11 Mai 2018
I have a code that i need to pseudo code and i am not fully understanding the script can someone please explain what the script is doing exactly.
Grav=6.67408*10^-11;
Mass=5.9722*10^24;
sat_mass=1000;
dt=10;
r(1,:)=[8*10^6,0,0];
r0=[8*10^6,0,0];
v(1,:)=[0, sqrt(Grav*Mass/norm(r0,2)),0];
for i=2:10000
a(i,:)=(-Grav*Mass)/norm(r(i-1,:),2)^2*r(i-1,:)/norm(r(i-1,:),2);
v(i,:)=v(i-1,:)+a(i-1,:)*dt;
r(i,:)=r(i-1,:)+v(i-1,:)*dt;
end
plot(r(:,1),r(:,2))
##### 3 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Abdullaziz Errayes am 11 Mai 2018
yeah i thought that too but i cant just say plotting locus of a satellite around the earth in the code haha
Siyu Guo am 11 Mai 2018
The code should be quite clear. r stands for the 3D coordinates of the sat, v its velocity vector, and a its acceleration vector. A straightforward Euler method to solve the Newtonian equation (an ODE).

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Jan am 11 Mai 2018
Bearbeitet: Jan am 11 Mai 2018
1. Some parameters are defined
2. The start point is set to r0 and the initial velocity to v(1,:)
3. A loop runs over 10000 time steps
4. Inside the loop, the current acceleration a is calculated by the law of gravity
5. The acceleration multiplied by a time step changes the current velocity
6. The current velocity multiplied by a time step changes the current position
7. Next iteration of the loop
8. Plot the trajectory
"not fully understanding the script" is not useful as a question in the forum. Should we explain "sat_mass=1000;" also?! Prefer to ask a specific question.
By the way, isn't it suspicious that sat_mass is defined, but not used anywhere?
Maybe I've solved your homework now. This would be a pity. But you are working with Matlab for at least 1.5 years now, so you should be familiar with the basics.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Reference Applications 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!

Translated by