Improved Euler Method for Rocket Position Vector Calculation

  • Thread starter Thread starter Hoofbeat
  • Start date Start date
  • Tags Tags
    Loops
Click For Summary

Discussion Overview

The discussion revolves around the application of the improved Euler method for calculating the position vector of a rocket traveling from Earth to the moon. Participants are exploring how to implement this method in C programming, particularly focusing on the use of old and new acceleration and velocity values within loops to compute position and velocity updates over time.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks guidance on incorporating the improved Euler method into a loop, expressing confusion about using both old and new acceleration values.
  • Several participants provide programming examples, discussing the syntax and functionality of loop constructs in C.
  • There is a clarification on the notation 'a += b', explaining it as a shorthand for 'a = a + b'.
  • Participants express uncertainty about how to retain old values while updating variables in a loop, with one suggesting the use of arrays to store multiple values.
  • Another participant mentions that the improved Euler method involves averaging velocities at the beginning and end of a time segment, which raises questions about the necessity of old acceleration values.
  • One participant emphasizes the importance of the order of operations in programming when updating variable values.

Areas of Agreement / Disagreement

Participants express varying opinions on the necessity of using old acceleration values in the improved Euler method, with some arguing that only new velocities are relevant. The discussion remains unresolved regarding the best approach to implement the method in programming.

Contextual Notes

Participants highlight the potential confusion arising from the need to use both old and new values in calculations, indicating that the implementation may depend on specific details of the improved Euler method that are not fully agreed upon.

Hoofbeat
Messages
48
Reaction score
0
I'm trying to use the improved euler method to calculate the position vector of a rocket on a mission from the Earth to the moon. The method involves calculating new values of acceleration whilst time is incremented and using this IN ADDITION to the previous values of acceleration to find the new velocities, and similarly using the new and old velocities to find yet ne position vectors etc. Being a novice at C-programming and a complete newcomer to the improved euler method, I was hoping that someone would be able to advise me how I actually incorporate that into a loop?! Surely, as time increments my old acceleration values will be replaced by new ones and thus how can I use both!

You can see my previous formulae for acceleration in the following thread:
https://www.physicsforums.com/showthread.php?t=63800

& here is the image of the page from my project problem sheet, explaining the method I have to use. Thanks
 

Attachments

  • Page3 Scan.jpg
    Page3 Scan.jpg
    8.3 KB · Views: 499
Computer science news on Phys.org
You do something like this:

int a=0,b;

for (i=1; i++; i<10);
{
b=10+1;
a+=b;
}

Every iteration of the loop b is set to 11 (or any value you'd like it to be), then a+=b is used which is equivalent to a=(a+b). This tells the program to take whatever value is stored in a add that to b then restore the value back into a.

Hope this helped.
 
faust9 said:
You do something like this:

int a=0,b;

for (i=1; i++; i<10);
{
b=10+1;
a+=b;
}

Every iteration of the loop b is set to 11 (or any value you'd like it to be), then a+=b is used which is equivalent to a=(a+b). This tells the program to take whatever value is stored in a add that to b then restore the value back into a.

Hope this helped.

Ok...I think I might understand that. So what does the notation 'a+=b' actually mean?
 
Hoofbeat said:
Ok...I think I might understand that. So what does the notation 'a+=b' actually mean?

a+=
is the same as
a=a+

similarly
a-=
is
a=a-

also
a*=
a/=
and
a%=
 
NateTG said:
a+=
is the same as
a=a+

Ok, I'm probably being really thick asking this, but what does a=a+ mean then?! lol
 
a+=b => a = a + b

similarly for things like -=, /=, *=
 
faust9 said:
for (i=1; i++; i<10);

BTW, I just noticed, this should really be
for(i=1;i<10;i++)

Since the second statement is the test condition. Otherwise, the loop will run for a good long while longer than 9 times.
 
Yeah, I understand the order of things in the loop. I'm still really confused though with how I can use both the new variables and old variables within the same loop to compute something. Surely by using "a=a+b" I'm defining a new value of a so then if I want to calculate say "c = a old + a new" surely with such a code I'll just get "c=a new + a new"?
 
NateTG said:
BTW, I just noticed, this should really be
for(i=1;i<10;i++)

Since the second statement is the test condition. Otherwise, the loop will run for a good long while longer than 9 times.

Yes, thanks.
 
  • #10
Hoofbeat said:
Yeah, I understand the order of things in the loop. I'm still really confused though with how I can use both the new variables and old variables within the same loop to compute something. Surely by using "a=a+b" I'm defining a new value of a so then if I want to calculate say "c = a old + a new" surely with such a code I'll just get "c=a new + a new"?

That's why you don't want to write it as c=ao+an... You want to write it as an=ao+c or as above you can dispense with the old new and simply use a+=c. Math functions are performed on the right side of the = then stored into the variable on the left. so if you have a=a+c then what the computer does is it takes the old value for 'a' adds that to 'c' then stores this new value back into a thus erasing the old a and creating a new a (except new variables are not really created only their values changed). The a+=c is simply a shorthand notation for a=a+c. If you want to retain all of your values from the first iteration to the last then you will need to a) make a whole bunch of variables to store each element (don't do this) or the better solution b) use an array. If you only care about the end result then use the a+=(some_variable_here) scheme.
 
  • #11
Hoofbeat said:
Yeah, I understand the order of things in the loop. I'm still really confused though with how I can use both the new variables and old variables within the same loop to compute something. Surely by using "a=a+b" I'm defining a new value of a so then if I want to calculate say "c = a old + a new" surely with such a code I'll just get "c=a new + a new"?

Well, the first thing to keep in mind is that you have to be careful about the order you do things in when you're programming. If you do something like (pseudocode):
Code:
while (thereisstillstufftodo()) {
   a_new=calculatenewacceleration();
   furtzwithnewandoldacceleration();
   a_old=a_new;
}
Then you'll have the old and new acceleration to futz with simultaneously. Since I'm guessing you're doing question 4.2 things are actually not that complicated.

Regarding variables:
Variables (more or less) are contained by the curly braces. This example isn't something you'd typically see, (people don't typically throw braces around for no apparent reason) but it should give you some idea:
Code:
int global; /*global variables exist everywhere */
int main () {
   int i; /* clearly i exists here */
   /* global exists here also */
   {
      int j;
      /* i,j and global exist here */
    }
    /* no more j */
}
/* i does not exist here */

Cheat section here:

Really, all you should need to do is change xm and ym to be floats rather than constants, add constants for R and omega, and add something like the following lines in the interior loop:
xm=R*cos(omega*t);
ym=R*sin(omega*t);
[/color]
 
  • #12
I'd already included the bit in your "cheat section" in my new formulae. The real problems lay with how I could use both the new and old accelerations in the same formula for the velocity
 
  • #13
Hoofbeat said:
I'd already included the bit in your "cheat section" in my new formulae. The real problems lay with how I could use both the new and old accelerations in the same formula for the velocity

Unless you're doing something weird, you shouldn't care at all about the old acceleration.
 
  • #14
NateTG said:
Unless you're doing something weird, you shouldn't care at all about the old acceleration.

Well I'm trying to use the improved Euler Method and it says I have to use both old values of x and y to calculate new velocity and likewise the new and old velocities to calculate the acceleration. ARGHHHHH I'm so confused (and I've just met another girl doing same project as me who is even more confused!) :bugeye:
 
  • #15
Not all that familiar with the improved Euler method, but after a quick google, I still am not that sure you'd want to deal with the old acceleration, but rather, it's old and new velocities that you're interested in.

The improved Euler method (more or less) apparently involves averaging the velocity at the beginning and end of the segment instead of using the velocity at just one of the endpoints. This is a little circular, since you might need to know where the rocket ends up (which is affected by the velocity ) in order to figure out the velocity at the end. Fortunately, I don't think you have to worry about that.

v_{new} = v_{old} + a t
p_{new}=p_{old}+t \times \frac{v_{new}+v_{old}}{2}

This should look suspiciously like the trapezoid method for numerical integration if you're familiar with that.

If you can, try to get a handle on how this works before you start trying to implement it in your program.

In the program that might look something like this:

Code:
for(t=0;t<1000;t+=time_increment) {
   .
   .
   .
   v_new_x=v_old_x+a_x*time_increment;
   p_x=p_x+time_increment*(v_new_x+v_old)/2;
   .
   .
   .
   v_old_x=v_new_x;
}

Since the statements are executed in order, it doesn't change v_old_x until it's been used to update the position.
 
  • #16
Thanks, that makes more sense now
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
Replies
5
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 5 ·
Replies
5
Views
10K
  • · Replies 233 ·
8
Replies
233
Views
24K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 33 ·
2
Replies
33
Views
3K
Replies
9
Views
3K