Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Programming challenge, gravity
Message
From
22/06/2004 22:50:18
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
22/06/2004 12:47:39
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00916106
Message ID:
00916279
Views:
20
The movement of the planets make sense. According to Kepler's Laws, the planets move around the Sun in an ellipse, and they move faster when they are closer to the sone. This makes the entire model quite reasonable.

I don't want to take the time now to analyze the program in detail, but let me review the physical principles, just to make sure you didn't overlook anything.

The Sun attracts the planets. The planets attract each other, unless you make the simplified assumption that the planets have an insignificant mass, compared to the Sun. This assumption is correct, as a first approximation. Even Jupiter has only about 1/1000 the mass of the Sun.

The planets, of course, also attract the Sun, so they would affect its movement, too.

(You may want to experiment with larger masses for the planets, to observe this effect. In the real World, this actually happens; several cases of double stars, triple stars, and larger groups, are known).

Inertia means that, in the absence of any force, a body will continue to move in a straight line, at a constant speed.

The application of a force, on the other hand, will accelerate a body - that is, change its velocity.

The force of gravitation is proportional to the masses, and inversely proportional to the square of the distance.

Well, after all, I did risk a quick look at your code, and it does consider all these factors.

One minor correction, but this only affects the comments in the code: the acceleration due to gravitation, close to the Earth's surface, is not 4.9, but twice this value: ca. 9.8 m/s^2. 4.9 is the distance the apple falls after one second - the average of its initial velocity (0), and its final velocity (9.8 m/s).

>Hey all,
>
>If anyone's got some spare time, and wants a challenge.
>
>I wrote this program almost a month ago now thinking I'd have plenty of time to play with it (hahahah!) but I haven't.
>
>So I thought I'd post it here. Its real "raw", I just slapped it together in a couple hours, about an hour of coding after about an hour of scribbling numbers and triangles on paper. Since I haven't been able to play with it, I thought maybe someone here might.
>
>I'm wondering a couple things:
>
>1. How can this program be written for awesome performance?
>2. How can this program be written so that the physical units can be made adjustable?

Perhaps some unit conversion utility?

>3. How can this program be written to calculate the elapsed time in second given physical units like meter and kilogram?

That looks like quite a different challenge. Elapsed time for what?

>4. Can anyone get the program to do all of the above, giving us a single program that with the appropriate parameters gives us the following three models:
>
>a. An apple falling to the ground

For this exercise, constant acceleration is often assumed; which, of course, is again an approximation.

The real problem, as I see it, is one of scales; the apple is very small, compared to the planets; also, the time scales involved for the exercises (planets moving around the Sun, vs. apple falling to Earth) are quite different.

>b. The moon orbiting the earth
>c. The first three planets (all nine would be nice of course) orbiting the sun

With the nine planets, you again have a problem with your scales... for instance, Pluto's distance to the Sun is about 40 AU. You may want to have two or even three "views" of the same Solar System; one that focuses on the central part, and one that shows the general pictures (but may lack the resolution to show Mercury!).

>5. How else can this program be made "cool"? What languages do you think would be best suited for it?
>
>In the program I'm posting I'm not even sure if I'm doing Newton's law correctly so that would have to be checked too.

As stated above, the observed movements make it quite plausible that you got it right. IMO, any formula that is way off would NOT result in an ellipse, where the planet returns to its starting point, or close to it. For example, just changing the inverse-square law to an inverse-cube law would have the effect that in the case of the slightest deviation from a circular path, the planet would either escape into space or fall into the Sun.

Regards,

Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform