Professional Documents
Culture Documents
CH4404 Lecture 07 NumericalIntegration
CH4404 Lecture 07 NumericalIntegration
CH4404 Lecture 07 NumericalIntegration
Numerical integration
Orest Shardt
Part 3. Numerical integration
• Numerical solutions for ODEs
• Excel and MATLAB
2
Simulating process dynamics
𝑑ℎ 𝑉ሶ𝑖𝑛 1
= − ℎ
𝑑𝑡 𝐴 𝜏
• Estimate derivative as:
𝑑ℎ ℎ 𝑡 + Δ𝑡 − ℎ(𝑡)
≈
𝑑𝑡 Δ𝑡
• Then
ℎ 𝑡 + Δ𝑡 − ℎ(𝑡) 𝑉ሶ𝑖𝑛 (𝑡) 1
≈ − ℎ(𝑡)
Δ𝑡 𝐴 𝜏
𝑉ሶ𝑖𝑛 𝑡 1
ℎ 𝑡 + Δ𝑡 ≈ ℎ 𝑡 + Δ𝑡 − ℎ(𝑡)
𝐴 𝜏
• A way to estimate the evolution of ℎ
• Expect an accurate solution if Δ𝑡 is small enough
3
Simulating process dynamics
4
Simulating process dynamics
5
Simulating process dynamics
6
Higher order processes
• Suppose
𝑑2 𝑦 𝑑𝑦
= 𝑓 𝑦,
𝑑𝑡 2 𝑑𝑡
• Re-write as
𝑑 2 𝑦1
2
= 𝑓 𝑦1 , 𝑦2
𝑑𝑡
𝑑𝑦1
𝑦2 =
𝑑𝑡
• Then
𝑑𝑦2 𝑑 2 𝑦1
=
𝑑𝑡 𝑑𝑡 2
• We have two coupled first order equations:
𝑑𝑦1 𝑑𝑦2
= 𝑦2 , = 𝑓 𝑦1 , 𝑦2
𝑑𝑡 𝑑𝑡
• nth order differential equation: n coupled first order equations
7
Choosing the time step
• Need to choose Δ𝑡
• Small*: accurate but many calculations
• Large*: inaccurate but quick to calculate
• *compared to the time constant of the process
• Adaptive time-stepping
• Algorithms are available to automatically vary Δ𝑡 so that it is small when the derivative
is high and larger when the derivative is smaller
• For example, compare the values of RK4 and RK5, and use a smaller Δt if the
difference is too large
• Many libraries provide implementations
• Matlab: ode45
• Python: scipy.integrate.solve_ivp(fun, t_span, y0, method='RK45’, etc)
8
Stability
9
Example
• Tank 1:
𝑑ℎ1
𝜏 = 𝐾 𝑉ሶ𝑖𝑛,1 − ℎ1
𝑑𝑡
• Tank 2:
𝑑ℎ2
𝜏 = 𝐾𝑉ሶ𝑖𝑛,2 − ℎ2 , 𝑉ሶ𝑖𝑛,2 = ℎ1 /𝐾
𝑑𝑡
• Initial steady state:
ℎ1 = ℎ2 = 2 𝑚, 𝑉ሶ𝑖𝑛,1 = 400 𝐿/𝑠
• Change 𝑉ሶ𝑖𝑛,1 to 450 L/s at 𝑡 = 0
• Exact solution
ℎ2 𝑡 = 2.25 + exp(−𝑡/𝜏) −0.01𝑡 − 0.25
10
Example
11
Simulation of Process with Controller
• Part 2 of Experiment A
• Analyse the experimental data to determine process dynamics
• Design a controller
• Simulate the behaviour of the controlled process
• How does the level evolve over time if you change the level setpoint?
• See the effects of varying the controller’s parameters
• Matlab code on Brightspace (ode45)
• Use/modify it for your analysis
12
Next
• Controllers
13