The Loop

The Loop

In my previous article I described how one can use a differential equation to calculate the trajectory of the Earth around the Sun. But at the end it was quite tedious so I decided to use a computer instead. Because they are good at repeating things. One way to make a computer do the same things again and again is to use a loop. In the program below we will show how a for loop works:

What the program does is to draw a planet 18 times using a for loop.

In each iteration of the loop first of all you calculate the distance from the sun to the planet, after you need to calculate the acceleration then you should find the speed of the planet at the end you can find the position of the planet.


This video explains about the code above:

About the Author