First of all, I would like to apologize for not writing for a few days (due to some personal issues). Thanks to everyone who contributed, your advice helped me quite a bit. I don't feel as lost as I felt when I posted my previous post anymore.Yakk, could I keep the values that would represent "the state of the universe at a particular point in time" in a vector, without using classes or structs?
I did that before posting about being stuck. Of course, I could try to modify my code (and use classes or structs) if it would make further work much easier. I am highly inexperienced, so I'm unable to predict which would be better, although I
am hoping that only vectors would be fine enough.
I wrote something that asks the user to enter the initial conditions, and then saves those values to a .txt file. Thanks for that direction. It seems like a pretty obvious thing, but didn't come to my mind back then when I had asked.
[I might add the option of taking the values from a file on my disk after I make something functional, but this user-interactive thing works for me for now.]
My intention is to make a program that would allow the user to choose initial conditions and see what happens when which initial conditions are chosen.
Yakk, are you basically suggesting that I should calculate (delta) momentum values and work with them? In other words, when you say "apply force on free body for delta t time", are you referring to dp=Fdt? I'm not quite sure whether I have understood you correctly. Sorry for having so much (elementary) questions.
[From this identity, I believe, I'd get the velocity as v=p/m.]
Sagekilla, are you talking about
- Code: Select all
r12 = sqrt((x1 - x2)*(x1 - x2) + (z1 - z2)*(z1 - z2)),
r13 = sqrt((x1 - x3)*(x1 - x3) + (z1 - z3)*(z1 - z3)),
r23 = sqrt((x2 - x3)*(x2 - x3) + (z2 - z3)*(z2 - z3));
ax3 = - G*m1*(x3 - x1)/(r13*r13*r13) - G*m2*(x3 - x2)/(r23*r23*r23)
az3 = - G*m1*(z3 - z1)/(r13*r13*r13) - G*m2*(z3 - z2)/(r23*r23*r23);
something like this?
These would obviously be the second derivatives of position, that is, the x and z components of position; I'm working with a plane defined by the axes x and z.
The vector form would be a=ax*ex+az*ez, where ex and ez are unit vectors.
P. S.
Zamfir, although I hadn't replied to your post, I'd just like to say that I value that advice of yours and have decided to listen to it.
You're right, I would definitely learn coding better than if just applying RK4 or any other method as soon as I get to that part of work.