Fill This Form To Receive Instant Help
Homework answers / question archive / Assignment #6 BME 3420 - Fall 2021 Another approach to solve an ODE using the Explicit Euler formula, is to use the formula to directly find an equation that predicts S(tj+1) given S(tj)
Assignment #6
BME 3420 - Fall 2021
Another approach to solve an ODE using the Explicit Euler formula, is to use the formula to directly find an equation that predicts S(tj+1) given S(tj). For example, for the linearized pendulum problem, where
dt = [ − g 0]S(t) dS(t) 0 1l
we can use the Explicit Euler Formula to obtain
[ |
S(tj+1) = S(tj) + hg ]S(tj)
− l 0
S(tj+1) = [ ]S(tj) + h[ g ]S(tj)
[ |
S(tj+1) =gh ]S(tj)
− 1
l
However, this solution has the same problem as before. Here is a code that implements this solution for the pendulum problem with with
1
S(0) = [ ]
0
and
√
l
import numpy as np import matplotlib.pyplot as plt
plt.style.use('seaborn-poster') h=0.1 time = np.arange(0,5+h,h) s0 = np.array([[1],[0]])
s = np.zeros((len(time),2)) s[0,:] = s0.T w = 4 #(g/l)^(1/2) for i in range(1,len(time)-1):
s[i,:] = np.array([[1, h],[-(w**2)*h, 1]])@s[i-1,:]
plt.figure(figsize = (5, 5)) plt.plot(time, np.cos(w*time),label='Exact Solution') plt.plot(time,s[:,0], label = 'Explicit Euler Formula') plt.xlabel('Time (s)') plt.ylabel('$\Theta(t)$') plt.legend() plt.show() |
In [6]:
An alternative is to implement the Intrinsic Euler Formula, which approximate the state S(tj+1) by
dS(tj+1)
S(tj+1) = S(tj) + (tj+1 − tj) , dt
dS(tj+1)
Note that this equation depends on which is unknonw! dt
However, we can use some algebra to solve this problem and obtain
dS(tj+1) 0 = [ g dt − l |
1 S(t 0] j+1) |
Reemplazing in the Implicit Euler formula we obtain
[ |
0 1
S(tj+1) = S(tj) + hg ]S(tj+1),
− 0 l
[ |
1 0 0 1
]S(tj+1) − h[ g ]S(tj+1) = S(tj)
[ |
g ]S(tj+1) = S(tj)
l
[ |
1 −h −1
S(tj+1) =gh ] S(tj)
1 l
Which allow us to compute S(tj+1) for any S(tj)
Hint : take a look at the code for the Extrinsic Euler Formula and make the necesary changes
As you observed in point a, the Intrisic Euler Formula does not provide a correct solution either. One approach overshoots the solution and another undershoots the solution. A reasonable approach then, is to find the average between the Intrinsic and Extrinsic formulas, this is called the trapezoidal formula, and is given by
h dS(tj) dS(tj+1)
S(tj+1) = S(tj) + [ + ],
2 dt dt
dS(tj) 0 = [ g dt − l |
1 ]S(t ) 0 j |
dS(tj+1) 0 = [ g dt − l |
1 S(t 0] j+1) |
the trapezoidal formula is given by
? |
1 |
h |
2 |
g |
h |
2 |
l |
S(tj+1) =
? |
gh 2 ?? ?? ??S(tj) 1 − h −1 1
1 −
2l
You should write the mathematical operations to derive this formula using pen and paper.
2- [5 points]
A model that describes the relation between position, velocity, and acceleration of a mass in a simple sprin-mass-damper system is given by
mx¨ + bx? + kx = F(t),
where F(t) is the force applied to the mass.
For this problem, assume that m = 1 and k = 5. The initial conditions are
x(0) = 1 x?(0) = 0
and you are interested in the solution between [0,20] with h = 0.01
Hint: Remember that numerical methods can only deal with first order equations, so you need to reduce the ODE order before solving the problem.
???0 if t < 3
F(t) = 1 if 4 ≤ t ≤ 8
0 otherwise
Solve the ODE to determine the position of the mass when b = 1 and b = 10. Create a plot for each condition and discuss your observations.
For this problem, assume that m = 1 and k = 5. The initial conditions are
x(0) = 1 x?(0) = 0
and you are interested in the solution between [0,20] with h = 0.01
In [ ]:
|
|
Please download the answer file using this link
https://drive.google.com/file/d/1XBNKO9edUP7n2lM2kDvXlubBytn1bxpi/view?usp=sharing