Mathcad - Mathcad_Examples of programming.pdf
April 22, 2017 | Author: bracilides82 | Category: N/A
Short Description
Download Mathcad - Mathcad_Examples of programming.pdf...
Description
Programming and Numerical Numeri cal Algorithms with MathCAD -- An Example To show how we can do some elementary elementary programming programming with MathCAD, we will wil l look at the problem of calculating the trajectory trajectory of a projectile. projectile. This is a classic cl assic physics problem and is relevant to the Lego Pentathlon Pentathlon task "Free Shot" As usual with mechanics problems, we begin with Newton: F
=
a
=
m a
(the arrows indicate indi cate vector quantities) quantiti es)
or F m
It is easiest to divide the trajectory into its vector components: the x-component (or range) and the y-component (or elevation). elevation ). Refer to the notes on the trajectory problem to see the details. Treating Treating the frictional frictional forces forces arising from collision collisi on with wi th air particles analytically as a Taylor expansion, we can to first order write: Ffriction
=
α v
where is called cal led the coefficient of friction friction and v
is the velocity Notice that this is just j ust the first (linear) term in the Taylor Taylor expansion exp ansion.. It makes makes sense because we expect the frictional forces to increase as the velocity increases (i.e., (i.e., more more collisions colli sions per unit time) and to vanish when the projectile i s at rest. However, it is important to remember that there may be other "high-order" "hi gh-order" terms that, that, for now, we are neglecti ne glecting. ng. Now, lets set up the equations equa tions that need to be solved. We will do this "numerically" to show how the calculation can be done. We will also compare it to to the analytical solution that is given in the additional notes accompanying this MathCAD worksheet. worksheet.
V 10
m
"Muzzle velocity" of the launcher in m/s
s
θ π 180
X-component of t he velocity. velocity. is the elevation angl in degrees
θ π 180
Y-component of the velocity. is the elevation angl in degrees
Vx ( θ) V cos Vy( θ) V sin
Recall that the equations of motion for the projectile can be written as: d d t
Vx
=
α m
Vx
d d t
Vy
=
g
α m
Vy
where is the coefficient of friction (units of kg/s) and m is the mass of the projectile (units of kg). To solve differential equations like this numerically, we can convert the derivatives into "finite differences." Recall the definition of a derivative: d d x
f ( x)
f ( x ∆x ) f ( x )
lim
=
∆x
∆x 0
if we take the value of f at x+ x to be f i+1 and the value at x to be f i, then we can approximate this derivative with the finite difference expression: d d x
f ( x)
f
i 1
f i
x
i 1
xi
=
Applying this formula to our equations of motion above, we get
Vx Vx i 1
t
ti i 1
i
=
α m
Vx
Vy Vy i 1
t
i
ti i 1
i
=
g
α m
Vy
i
These can be rearranged into a more convenient form:
Vx
=
i 1
Vy
i 1
=
1
α m
ti1 ti Vx
g ti1 ti 1
i
α m
ti1 ti Vy
i
These are known as "finite difference" equations and they tell you how to calculate the next value of Vx or Vy given the preceding value. The discrete time difference, t
i 1
ti
can be written as t, and we should make this
interval as small is possible to get a good approximation to the derivative. Of course, if it is too small, then the problem will take longer to solve and MathCAD may have
. Let's proceed to solving for the velocity. First we set our discrete time interval and the constants:
α 1
kg
Coefficient of friction
s
Mass of the projectile in kg
m 1 kg
2
∆t 5 10
Time interval in seconds
s
Number of points to evaluate
n 500
To solve for the velocity, we will set up a small programming loop in MathCAD:
Vx ( θ)
Here we have begun to define the x-component of the velocity. The programming bar is added by clicking on the programming toolbar and then clicking on "Add Line" Vx ( θ)
Vx V cos( θ) 0
Now, we have assigned the ini tial value of the velocity as the x-component of the muzzle velocity. We will need some additional statements in our program, so on the red square we once again click "Add Line": Vx ( θ)
Vx V cos( θ) 0
i1
Here we have defined our "counter" integer i and assigned its initial value of 1. N we extend our programming line again with "Add Line" and set up a "for-next" loo This loop is executed for all values of i that are less than the maximum of n. Inside the loop, the counter integer is incremented and the subsequent values of Vx are calculated:
Vx ( θ)
Vx V cos θ 0
180 π
i0 for i 0 n Vx
i 1
1
α m
( ∆t) Vx
i
ii 1 Vx
This last step tells MathCAD where to put the data from the calculation. It seems a bit redundant to me, but this is the way the program's syntax is set up. Now we do the same thing for the y-component of the velocity:
Vy ( θ)
Vy V sin θ 0
180 π
i0 for i 0 n Vy
i 1
g ( ∆t) 1
α m
( ∆t) Vy
i
ii 1 Vy
We can list out the values of Vx and Vy by just using the "=" sign :
0
Vx ( 45)
0
0
7.071
0
7.071
1
6.718
1
6.227
2
6.382
2
5.425
3
6.063
3
4.664
4
5.759
4
3.94
5
5.471
5
3.253
6
5.198
6
2.6
7
4.938
7
1.98
8
4.691
8
1.39
9
4.457
9
0.831
10
4.234
10
0.299
m s
Vy ( 45)
m s
.
- .
12
3.821
12
-0.687
13
3.63
13
-1.143
14
3.448
14
-1.576
15
...
15
...
Now that we have found the x and y components of the velocity, we can calculate the position coordinates, x and y. x
i 1
x i Vx ∆t
y
i
i 1
yi Vy ∆t i
To evaluate these quantities, we set up a loops as before: Xinitial 0 m x ( θ)
Yinitial 0 m
i0
y ( θ)
i0
x Xinitial 0
y Yinitial 0
for i 0 n
for i 0 n
x
i 1
x i Vx ( θ) ∆t
y
i
ii 1
i 1
yi Vy ( θ) ∆t i
ii 1
x
y
Now, let's plot the trajectory for several launch angles. We will also compare the numerical solution to the exact solution derived in the accompanying notes:
m 1 exp α τ 180 α m
χ( τ θ) V cos θ
m g m V sin θ π 1 exp α τ g m τ α α α 180 m
ψ( τ θ)
3
τ 0 s 1 10
π
s 10 s
Give the time parameter a range of values
3 y( 60)
ψ( t 60)
2.7 2.4 2.1
y( 45)
1.8 ψ( t 45) 1.5 y( 30)
1.2
ψ( t 30) 0.9 0.6 0.3 0
0
0.6
1.2
1.8
2.4
3
3.6
4.2
4.8
x( 60) χ ( t 60) x( 45) χ ( t 45) x( 30) χ ( t 30)
5.4
6
View more...
Comments