• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to loop and store values from physics equations  RSS feed

 
Michael Berthaud
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so i want to do these equations in these steps



>1. q1*q3*k/(r^2)= F1_3(this is the electric force between 1 and 3)

>2. q2*q3*k/r^2)= F1_2(force between particle 1 and 2)

>3. from there i can find the net force between the two charges with f1_3+f1_2=fnet

>4. with the net force i would then find the acceleration using a=fnet/m (with m being the mass. (now everything above i was okay with doing but now heres where i get confused)

>5. take the acceleration just found and find velocity. v=-(at) being time intervals (i got that equation aver deriving it from the equation in step 6 and the initial equation was x(.05)=at+v

>6. take that velocity and previous acceleration and find new position: x=1/2at^2+v*t+x

>7. the value for x becomes the new position for particle 3 and now i go back to to the top in order to calculate electric force then acceleration etc rinse and repeat.

Is what I'm trying to do not possible? I just dont know how i would take the new position i get and re-implement it back into the other methods to spit out another value at the end  what i have in the code below is just one rotation of a equations that i would like to use numerous amount of time. The reason for me doing this is because for every position and time I want to save those values and plot them later. Someone recomended to me an using an array but im do not know how to use them nor do I understand how that may help

 
Junilu Lacar
Sheriff
Posts: 11485
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your explanation is not very clear but from what I got out of it, assuming q3 needs to take the value of wow for the next round of calculations, you would simply assign the value of wow to q3 (line 8 below)


Your names seem very cryptic to me. Why use names like "wow" and "q3"? Unless these are names like "delta" and "lambda" that have common, well-known meanings, they don't make your code very readable.
 
Michael Berthaud
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in physics q is the symbol used for charge delta would be harder to read because in physics delta means change
 
Michael Berthaud
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and thank you im sorry for the difficult to read coding im very new to all of this I will not lie im a physicist at heart. the reason I did not want to do it that way is because than i would have to manually put in the new iterations for ever time interval would i not? and what does while do in java?
 
Junilu Lacar
Sheriff
Posts: 11485
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, this code can be simplified and cleaned up:

Cleaner:

 
Junilu Lacar
Sheriff
Posts: 11485
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Berthaud wrote:and thank you im sorry for the difficult to read coding im very new to all of this I will not lie im a physicist at heart. the reason I did not want to do it that way is because than i would have to manually put in the new iterations for ever time interval would i not? and what does while do in java?

Well, you could make it easier for people to help you if you used some punctuation, proper capitalization, and apostrophes. Most folks prefer to read posts that don't make them do a lot of copyediting on the fly.

A while-loop is one way you can repeat a set of instructions. It terminates when its loop condition evaluates to false. You can read more about while-loops here: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html
 
Junilu Lacar
Sheriff
Posts: 11485
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome to the Ranch!
 
Junilu Lacar
Sheriff
Posts: 11485
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Berthaud wrote:the reason I did not want to do it that way is because than i would have to manually put in the new iterations for ever time interval would i not?

Like I said, the calculations and the progression is not very evident to me from your code. Maybe it will help if you give examples of a few iterations of calculations so that we can see the relationships and patterns of change between one iteration and the next.
 
Junilu Lacar
Sheriff
Posts: 11485
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have to write the examples in Java. Just write it out as you would with pen and paper, e.g.:

Let:
q1 = ...
q2 = ...
mq1 = ...

Do the following:
1. Calculate force, f1, as ...
2. Then ...
3. Finally, let wow be ...
4. Repeat from step 1 using wow from step 3 as the new q3

For example:

First iteration:
... detailed calculations that go through steps 1-3

Second iteration:
... detailed calculations that go through steps 1-3

Something like that
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!