Improved Euler Method for Rocket Position Vector Calculation

  • Thread starter Hoofbeat
  • Start date
  • Tags
    Loops
In summary: Additionally, what you're trying to do is basically create two new variables (a new a and a new c) and assign them the values of a and c from the previous iteration, respectively. Well, the first thing to keep in mind is that you have to be careful about the order... a+=b can actually mean something different depending on where the = is placed in the code. Additionally, what you're trying to do is basically create two new variables (a new a and a new c) and assign them the values of a and c from the previous iteration, respectively.
  • #1
Hoofbeat
48
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: 407
Computer science news on Phys.org
  • #2
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.
 
  • #3
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?
 
  • #4
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%=
 
  • #5
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
 
  • #6
a+=b => a = a + b

similarly for things like -=, /=, *=
 
  • #7
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.
 
  • #8
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"?
 
  • #9
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);
 
  • #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 wierd, you shouldn't care at all about the old acceleration.
 
  • #14
NateTG said:
Unless you're doing something wierd, 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.

[tex]v_{new} = v_{old} + a t[/tex]
[tex]p_{new}=p_{old}+t \times \frac{v_{new}+v_{old}}{2}[/tex]

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
 

1. What is the Improved Euler Method for Rocket Position Vector Calculation?

The Improved Euler Method is a numerical method used to approximate the position vector of a rocket during its flight. It is an improvement upon the basic Euler Method, which is known to have errors in its calculations. The Improved Euler Method takes smaller time intervals and uses a combination of the forward Euler and backward Euler methods to provide a more accurate approximation of the position vector.

2. How does the Improved Euler Method work?

The Improved Euler Method uses a two-step process to approximate the position vector. First, it uses the forward Euler method to calculate the position vector at the midpoint of the time interval. Then, it uses the backward Euler method with this midpoint position to calculate the position vector at the end of the time interval. This process is repeated for smaller time intervals to provide a more accurate approximation of the position vector.

3. What are the advantages of using the Improved Euler Method?

The Improved Euler Method has several advantages over the basic Euler Method. It provides a more accurate approximation of the position vector, especially for longer flight times. It also has a smaller error than the basic Euler Method. Additionally, it is a simple and easy-to-implement method.

4. Are there any limitations to using the Improved Euler Method?

Like any numerical method, the Improved Euler Method has its limitations. It may still have errors in its calculations, although they are smaller than the errors in the basic Euler Method. It is also a time-consuming method, as it requires multiple calculations for smaller time intervals. It may not be suitable for all types of rocket trajectories and may not be as accurate as more advanced numerical methods.

5. How is the accuracy of the Improved Euler Method determined?

The accuracy of the Improved Euler Method can be determined by comparing the calculated position vector with the actual position vector of the rocket. The smaller the error between the two, the more accurate the method is. Additionally, the accuracy can be improved by using smaller time intervals. The method can also be compared with other numerical methods to determine its accuracy.

Similar threads

  • General Math
Replies
11
Views
1K
  • Introductory Physics Homework Help
Replies
5
Views
2K
  • Calculus
Replies
2
Views
1K
Replies
18
Views
2K
  • Special and General Relativity
Replies
33
Views
1K
Replies
9
Views
2K
Replies
2
Views
1K
  • Art, Music, History, and Linguistics
Replies
4
Views
956
  • STEM Educators and Teaching
7
Replies
233
Views
18K
Replies
14
Views
1K
Back
Top