Solve "For" Loops Problem with Mathcad 2001i

In summary, you are trying to simulate the motion of an object under the influence of the moon's gravity, and your approach using for loops can be improved by taking into account the changing position of the object and using an if statement to prevent further acceleration after passing the moon.
  • #1
Henriklm
8
0
"for" loops problem

Homework Statement



I would like Mathcad 2001i to calculate a trajectory for me.

The idea is to take initiating x,y coordinates and x,y velocity, calculate the x,y acceleration at that point and then calculate where it will be after 1 t, then calculate the new acceleration and velocity for the new position and so on.

mmåne = mass of moon
xmåne = x position of moon
ymåne = y position of moon
vx0 and vy0 = initiating velocities
v = angle to x-axis

Homework Equations



accx = G*(mmåne / distance to moon^2) * cos(v)
accy = G*(mmåne / distance to moon^2) * sin(v)

The Attempt at a Solution



I tried this

http://img404.imageshack.us/img404/4377/forloop.jpg" [Broken]

But it doesn't work like i want it to.

I think it takes the initiating coordinates and just multiply the acceleration at that point by t.

Which gives me this trajectory:

http://img138.imageshack.us/img138/1750/trajectory.jpg [Broken]

The green dots are plotted in the same time interval, so I can se, that it still accelerates after it passes the moon. Like it would, if it takes the initiating coordinates and just multiply the acceleration at that point by t.

Thank you :-)

Henrik
 
Last edited by a moderator:
Physics news on Phys.org
  • #2


Hello Henrik,

Thank you for sharing your problem with us. It seems like you are trying to simulate the motion of an object under the influence of a gravitational field, specifically the moon's gravity. Your approach using for loops is a good start, but there are a few things that can be improved upon.

Firstly, the equations for acceleration that you have used are correct, but they should be rewritten to take into account the changing position of the object as it moves. This means that the distance to the moon is not a constant, but rather a function of time. Therefore, the equations should be:

accx = G*(mmåne / (xmåne^2 + ymåne^2)^3/2) * xmåne
accy = G*(mmåne / (xmåne^2 + ymåne^2)^3/2) * ymåne

Where xmåne and ymåne are the x and y positions of the moon respectively.

Secondly, in order to calculate the new position of the object, you need to update the x and y coordinates using the following equations:

x = x + vx*t + 0.5*accx*t^2
y = y + vy*t + 0.5*accy*t^2

Where x and y are the new x and y coordinates, vx and vy are the velocities in the x and y directions, t is the time step, and accx and accy are the updated accelerations calculated from the previous equations.

Finally, to ensure that the object is not accelerated after passing the moon, you can use an if statement to check if the distance to the moon is greater than a certain value (for example, the radius of the moon). If it is, then the acceleration should be set to zero in both the x and y directions.

I hope this helps and good luck with your calculations! Feel free to ask if you have any further questions.
 

1. What is a "For" loop in Mathcad 2001i?

A "For" loop in Mathcad 2001i is a programming structure that allows you to repeat a set of instructions for a specified number of times. It is commonly used in solving mathematical problems where the same calculation needs to be performed multiple times with different input values.

2. How do I use a "For" loop in Mathcad 2001i?

To use a "For" loop in Mathcad 2001i, you first need to define the starting and ending values of the loop. Then, you can specify the instructions to be repeated within the loop. The loop will run until the ending value is reached, with the loop variable being incremented by 1 each time.

3. Can I use "For" loops to solve complex mathematical problems in Mathcad 2001i?

Yes, "For" loops can be used to solve complex mathematical problems in Mathcad 2001i. They are particularly useful when you need to solve a problem with a large number of data points or varying input values. By using a "For" loop, you can avoid having to manually input each value and perform the same calculation multiple times.

4. Are there any limitations to using "For" loops in Mathcad 2001i?

While "For" loops are a powerful tool in Mathcad 2001i, there are some limitations to keep in mind. One limitation is that the loop variable can only be incremented by a constant value in each iteration. Additionally, "For" loops may not be the most efficient solution for all types of problems, so it's important to consider other programming structures as well.

5. Can I nest "For" loops in Mathcad 2001i?

Yes, you can nest "For" loops in Mathcad 2001i, meaning you can have one loop within another loop. This can be useful when you need to perform a repetitive calculation with multiple variables. However, it's important to keep in mind that nesting too many loops can make your code difficult to read and potentially impact performance.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Introductory Physics Homework Help
Replies
14
Views
1K
  • Introductory Physics Homework Help
2
Replies
38
Views
1K
  • Advanced Physics Homework Help
Replies
3
Views
1K
  • General Math
Replies
11
Views
1K
Replies
1
Views
913
  • Introductory Physics Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Calculus
Replies
3
Views
952
Back
Top