Title: Polymath Tutorial: Matrix and ODE
1Polymath TutorialMatrix and ODE
- By Kelvin WONG
- CENG 364 _at_ HKUST
- Feb, 2009
2Using Polymath to Solve Matrix(Linear Equations)
- An example, based on the TV program ?????, Jan
31, 2009 - Mr. A, Mr. B, Mr. C and Mr. D have some money.
They have 112 in total, i.e., A B C D
112. And we also know that - A 3 B - 3
- A 3 3 x C
- D 3 x (A 3).
- How much do Mr. A, Mr. B, Mr. C and Mr. D have?
- We can solve it by substitute the last three
equations into the first equation. - On the other hand, we can solve it by using
matrix(linear algebra).
3Matrix Example (1)
- Rearrange those four equations as
- A B C D 112 (eq. 1)
- A - B -6 (eq. 2)
- A - 3C -3 (eq. 3)
- 3A - D -9 (eq. 4)
- We have 4 equations and we need to solve for 4
unknowns. This system is determined. - If of equations gt of unknowns ?
overdetermined. - If of equations lt of unknowns ?
underdetermined.
4Matrix Example (2)
5Matrix Example (3)
- In Polymath, click the Linear Equation Problem
button - Since we have only 4 equations and 4 unknowns, we
need to change the Number of Equations as 4
6Matrix Example (4)
- Then start to input the matrix. Let x1 A, x2
B, x3 C, x4 D, and beta the product
vector. - Then, click the pink arrow button to solve
it.
7Matrix Example (5)
8Using Polymath to Solve ODE
- In many physical systems, we have differential
equations to describe the rate of change of the
system. In order to find the status of this
system at any time, we need to integrate those
differential equations. - E.g. batch reactor
- A ? B
- Assume first order kinetics
- We know the rate of consumption of species A is
- We can solve the problem by integrate the above
differential equation by hand (analytical
solution)
9Numerical Integration (1)
- For those differential equations with complicated
functions that cannot be integrate analytically,
or - When we use computer to solve those problems.
- We will need numerical integration to solve those
ODE.
10Numerical Integration (2)
- What we know
- Initial concentration A0
- Kinetic parameter k
- Rate of reaction at any given A.
- What we do not know
- Concentration At at any given time t.
11Numerical Integration (3)
- Then we can guess the new concentration A by
using the know reaction rate (slope)
At A0 - slope ? t
? t
12Numerical Integration (4)
- Repeat the above calculation and well have
approximate solution of the ODE
13Numerical Integration (5)
- Smaller steps ? more accurate result
- However, more computation time (resource) is
required. - Many numerical integration methods are developed
in order to improve accuracy. - We need to balance in between accuracy and
computation resource.
14Stiff Systems
- System of ODE where the dependent variables
change on various time (independent variable)
scales which differ by many orders of magnitude
are called Stiff systems. - We need to choice the appropriate method in
Polymath to handle this problem.
15Polymath Demonstration
- Independent variable
- Equation input (a) differential equation, (b)
explicit equation. - Parameter input as explicit equation
- Numerical integration method
- Typo error
- Limitation on number of equations
- Decision statement / step function
16ODE Example - Batch Reactor (1)
- Irreversible reaction
- A ? B
- First order kinetic rA -kA
- In Polymath click the Ordinary Differential
Equations Problem button
17ODE Example - Batch Reactor (2)
- Click the Add New Differential Equation button to
input the differential equation - Then type in the equation that describes the rate
of change of A per time. We also need to
provide the initial value of A0 (let say, 10M)
18ODE Example - Batch Reactor (3)
- Also need to input the differential equation for
dB/dt. - Then we need to define the rate of reaction rA
by input an explicit equation. Click the Add New
Explicit Equation button - Type in the rate equation
- Add one more explicit equation to define the
value of k.
19ODE Example - Batch Reactor (4)
- Finally, define the initial and find time (t0 and
tfinal). Click the Define Initial and Final
Values of the Independent Variable button - Once we have the sufficient information, Polymath
will show the Solve button. Click it to solve
this model
20ODE Example - Batch Reactor (5)
21Step Function
- Typical step function
- We can create a step function by using decision
making statement - if (t lt t1) then (0) else (1)
- OR
- if (t gt t1) then (1) else (0)
- Above two statements are identical.
22ODE Example - CSTR (1)
- A ? B
- First order kinetic rA -kA
- Flow rate F, reactor volume V, feed stream
reactant conc. Afeed. - Increase reactant conc. in feed stream at certain
time. - t lt t1, Afeed Af1t t1, Afeed Af2.
23ODE Example - CSTR (2)
- Define the feed stream reactant concentration by
using the step function - Of course, we need to define the time for the
step function.
24ODE Example - CSTR (3)
25ODE Example - CSTR (4)