Ordinary differential equations

Slides:



Advertisements
Similar presentations
Definition of the Derivative Using Average Rate () a a+h f(a) Slope of the line = h f(a+h) Average Rate of Change = f(a+h) – f(a) h f(a+h) – f(a) h.
Advertisements

Formal Computational Skills
Chapter 6 Differential Equations
However, some functions are defined implicitly. Some examples of implicit functions are: x 2 + y 2 = 25 x 3 + y 3 = 6xy.
Implicit Differentiation
Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE.
PART 7 Ordinary Differential Equations ODEs
Clicker Question 1 What is the derivative of f (x ) = e3x sin(4x ) ?
Constrained Fitting Calculation the rate constants for a consecutive reaction with known spectrum of the reactant A = (A A + A B + A C ) + R = C E T =
2.5 The Chain Rule If f and g are both differentiable and F is the composite function defined by F(x)=f(g(x)), then F is differentiable and F′ is given.
2.5 Implicit Differentiation. Implicit and Explicit Functions Explicit FunctionImplicit Function But what if you have a function like this…. To differentiate:
Modeling in the Time Domain - State-Space
Implicit Differentiation. Objectives Students will be able to Calculate derivative of function defined implicitly. Determine the slope of the tangent.
Converting a Chemical Engineering Problem into Excel VBA Program
Numerical Solution of Ordinary Differential Equation
PART 7 Ordinary Differential Equations ODEs
Section 6.1: Euler’s Method. Local Linearity and Differential Equations Slope at (2,0): Tangent line at (2,0): Not a good approximation. Consider smaller.
Numerical Solutions to ODEs Nancy Griffeth January 14, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis.
Introduction to Numerical Methods for ODEs and PDEs Methods of Approximation Lecture 3: finite differences Lecture 4: finite elements.
Most physically significant large-scale atmospheric circulations have time scales on the order of Rossby waves but much larger than the time scales.
1 EEE 431 Computational Methods in Electrodynamics Lecture 4 By Dr. Rasime Uyguroglu
Computational Biology, Part 15 Biochemical Kinetics I Robert F. Murphy Copyright  1996, 1999, 2000, All rights reserved.
Computational Method in Chemical Engineering (TKK-2109)
Example: Sec 3.7: Implicit Differentiation. Example: In some cases it is possible to solve such an equation for as an explicit function In many cases.
Section 2.5 Implicit Differentiation
Slope Fields. Quiz 1) Find the average value of the velocity function on the given interval: [ 3, 6 ] 2) Find the derivative of 3) 4) 5)
In this section, we will investigate a new technique for finding derivatives of curves that are not necessarily functions.
Copyright © Cengage Learning. All rights reserved.
Circuits Theory Examples Newton-Raphson Method. Formula for one-dimensional case: Series of successive solutions: If the iteration process is converged,
Numerical Analysis – Differential Equation
Implicit differentiation (2.5) October 29th, 2012.
Ch 8.2: Improvements on the Euler Method Consider the initial value problem y' = f (t, y), y(t 0 ) = y 0, with solution  (t). For many problems, Euler’s.
Today’s class Ordinary Differential Equations Runge-Kutta Methods
Calculus and Analytical Geometry
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapters 22 and 23.
Linear regression. Case study Galactose diffusion in silica mesopore.
CALCULUS REVIEW BME 3510 C PO-WEI CHEN 8/19/2014.
Part 7 - Chapter 25.
SLOPE FIELDS & EULER’S METHOD
SLOPE FIELDS & EULER’S METHOD
Chapter 30.
What is the differentiation.
Section 3.7 Implicit Functions
Used for composite functions
MTH1170 Implicit Differentiation
Ordinary Differential Equations
FE Exam Tutorial
Sec 3.5: IMPLICIT DIFFERENTIATION
47 – Derivatives of Trigonometric Functions No Calculator
Section 15.4 Partial Derivatives
College Algebra Chapter 2 Functions and Graphs
Class Notes 18: Numerical Methods (1/2)
BASIC DIFFERENTIATION RULES AND RATES OF CHANGE
Implicit Differentiation
Implicit Differentiation
Part 7 - Chapter 25.
2 Differentiation 2.1 TANGENT LINES AND VELOCITY 2.2 THE DERIVATIVE
Linear equations.
Absolute Value Functions
ML – Lecture 3B Deep NN.
Ordinary differentiall equations
Building the function from the derivative
30 – Instantaneous Rate of Change No Calculator
Coordinate Transformation in 3D Final Project Presentation
Do Now: Grab a calculator
APPLICATION OF LINEAR ALGEBRA IN MECHANICAL ENGINEERING
2.3 The Product Rule Notice the order doesn’t matter!
BASIC DIFFERENTIATION RULES AND RATES OF CHANGE
Presentation transcript:

Ordinary differential equations

Finite element method Divide macroscopic object into small pieces Can investigate real-size objects in real world time regimes Disregarding of atomic nature of matter and long-range interactions

Case study Reactor with reaction

More complicated problem Accumulation = inputs - outputs

More complicated problem Accumulation = inputs - outputs 𝑄 55 =2 𝑚 3 𝑚𝑖𝑛 inputs outputs 𝑄 15 =3 𝑚 3 𝑚𝑖𝑛 outputs 𝑐 5 𝑄 54 =2 𝑚 3 𝑚𝑖𝑛 outputs outputs 𝑄 25 =1 𝑚 3 𝑚𝑖𝑛 𝑄 44 =11 𝑚 3 𝑚𝑖𝑛 inputs outputs inputs outputs inputs outputs 𝑄 01 =5 𝑚 3 𝑚𝑖𝑛 𝑐 01 =20 𝑚𝑔/ 𝑚 3 𝑄 12 =3 𝑚 3 𝑚𝑖𝑛 𝑐 1 𝑐 2 𝑐 4 outputs 𝑄 23 =1 𝑚 3 𝑚𝑖𝑛 outputs 𝑄 31 =1 𝑚 3 𝑚𝑖𝑛 inputs outputs inputs 𝑄 34 =8 𝑚 3 𝑚𝑖𝑛 𝑄 03 =8 𝑚 3 𝑚𝑖𝑛 𝑐 03 =20 𝑚𝑔/ 𝑚 3 𝑐 3

How to solve that problem? Accumulation = inputs - outputs So? 𝑄 15 =3 𝑚 3 𝑚𝑖𝑛 outputs 𝑉 1 𝑑 𝑐 1 𝑑𝑡 = 𝑐 01 𝑄 01 + 𝑐 3 𝑄 31 − 𝑐 1 𝑄 12 − 𝑐 1 𝑄 15 inputs outputs 𝑄 01 =5 𝑚 3 𝑚𝑖𝑛 𝑐 01 =20 𝑚𝑔/ 𝑚 3 𝑄 12 =3 𝑚 3 𝑚𝑖𝑛 Q01c01 = 50 mg/min, Q03c03 = 160 mg/min, V1 =50 m3, V2 = 20 m3, V3 = 40 m3, V4 = 80 m3, and V5 = 100 m3 𝑐 1 outputs 𝑄 31 =1 𝑚 3 𝑚𝑖𝑛

How to solve that problem? Accumulation = inputs - outputs So? 𝑄 15 =3 𝑚 3 𝑚𝑖𝑛 outputs 𝑉 1 𝑑 𝑐 1 𝑑𝑡 = 𝑐 01 𝑄 01 + 𝑐 3 𝑄 31 − 𝑐 1 𝑄 12 − 𝑐 1 𝑄 15 inputs outputs 𝑄 01 =5 𝑚 3 𝑚𝑖𝑛 𝑐 01 =20 𝑚𝑔/ 𝑚 3 𝑄 12 =3 𝑚 3 𝑚𝑖𝑛 Q01c01 = 50 mg/min, Q03c03 = 160 mg/min, V1 =50 m3, V2 = 20 m3, V3 = 40 m3, V4 = 80 m3, and V5 = 100 m3 𝑐 1 𝑉 1 𝑑 𝑐 1 𝑑𝑡 =−0.12 𝑐 1 +0.02 𝑐 3 +1 outputs 𝑄 31 =1 𝑚 3 𝑚𝑖𝑛

How to solve that problem? Accumulation = inputs - outputs So? 𝑄 15 =3 𝑚 3 𝑚𝑖𝑛 outputs 𝑉 1 𝑑 𝑐 1 𝑑𝑡 = 𝑐 01 𝑄 01 + 𝑐 3 𝑄 31 − 𝑐 1 𝑄 12 − 𝑐 1 𝑄 15 inputs outputs 𝑄 01 =5 𝑚 3 𝑚𝑖𝑛 𝑐 01 =20 𝑚𝑔/ 𝑚 3 𝑄 12 =3 𝑚 3 𝑚𝑖𝑛 𝑄 01 𝑐 01 =50 𝑚𝑔 𝑚𝑖𝑛 , 𝑄 03 𝑐 03 =160 𝑚𝑔 𝑚𝑖𝑛 , 𝑉 1 =50 𝑚 3 , 𝑉 2 =20 𝑚 3 , 𝑉 3 =40 𝑚 3 , 𝑉 4 =80 𝑚 3 , 𝑉 5 =100 𝑚 3 𝑐 1 𝑑 𝑐 1 𝑑𝑡 =−0.12 𝑐 1 +0.02 𝑐 3 +1 outputs 𝑄 31 =1 𝑚 3 𝑚𝑖𝑛

Accumulation = inputs - outputs How to solve that problem? Accumulation = inputs - outputs For other reactors 𝑑 𝑐 1 𝑑𝑡 =−0.12 𝑐 1 +0.02 𝑐 3 +1 Initially the concentration in all reactors will be zero. What will be the evolution of concentrations in time? 𝑑 𝑐 2 𝑑𝑡 =0.15 𝑐 1 −0.15 𝑐 2 𝑑 𝑐 3 𝑑𝑡 =0.025 𝑐 2 −0.225 𝑐 3 +4 𝑑 𝑐 4 𝑑𝑡 =0.1 𝑐 3 −0.1375 𝑐 4 +0.025 𝑐 5 How to solve this problem? 𝑑 𝑐 5 𝑑𝑡 =0.03 𝑐 1 +0.01 𝑐 2 −0.04 𝑐 5

A really simple example Converstion of cyclopropane to propane 𝑘=6.7 10 −4 1 𝑠 , 𝑇= 500 𝑜 𝐶 1st order 𝒅𝒄 𝒅𝒕 =−𝒌𝒄 𝒕 If the initial concentration c(0) of cyclopropane is 0.05 M, what is the concentration after 30 min?

How to calculate c(t)? Differential equation 𝒅𝒄 𝒅𝒕 =−𝒌𝒄 𝒕

How to calculate c(t)? Differential equation 𝒅𝒄 𝒅𝒕 =−𝒌𝒄 𝒕 𝟎 𝒕 𝟏 𝒄 𝒅𝒄 𝒅𝒕 𝒅𝒕 =−𝒌 𝟎 𝒕 𝒅𝒕 𝒄(𝟎) 𝒄 𝒕 𝒅𝒄 𝒄 =−𝒌 𝟎 𝒕 𝒅𝒕

How to calculate c(t)? Differential equation 𝒅𝒄 𝒅𝒕 =−𝒌𝒄 𝒕 𝒄(𝟎) 𝒄 𝒕 𝒅𝒄 𝒄 =−𝒌 𝟎 𝒕 𝒅𝒕 𝐥𝐧 𝒄 𝒕 − 𝐥𝐧 𝒄 𝟎 =−𝒌𝒕

How to calculate c(t)? Differential equation 𝒅𝒄 𝒅𝒕 =−𝒌𝒄 𝒕 𝒄(𝟎) 𝒄 𝒕 𝒅𝒄 𝒄 =−𝒌 𝟎 𝒕 𝒅𝒕 𝐥𝐧 𝒄 𝒕 − 𝐥𝐧 𝒄 𝟎 =−𝒌𝒕 𝒄 𝒕 𝒄 𝟎 = 𝒆 −𝒌𝒕

How to calculate c(t)? Differential equation 𝒅𝒄 𝒅𝒕 =−𝒌𝒄 𝒕 𝒄(𝟎) 𝒄 𝒕 𝒅𝒄 𝒄 =−𝒌 𝟎 𝒕 𝒅𝒕 𝐥𝐧 𝒄 𝒕 − 𝐥𝐧 𝒄 𝟎 =−𝒌𝒕 𝒄 𝒕 𝒄 𝟎 = 𝒆 −𝒌𝒕 𝒄 𝒕 =𝒄 𝟎 ∗ 𝒆 −𝒌𝒕

Different approach Euler’s scheme

Instead of solving function analytically  step by step procedure 𝒇 𝒕+𝚫𝒕 =𝒇 𝒕 + 𝒇 ′ 𝒕 ∗𝚫𝒕 Analytical solution f t

Instead of solving function analytically  step by step procedure 𝒇 𝒕+𝚫𝒕 =𝒇 𝒕 + 𝒇 ′ 𝒕 ∗𝚫𝒕 Analytical solution Point-by-point solution f f t t

How does it works  we start from f(0) 1. Choose step 𝚫𝒕=𝟏 2. Compute next point using „chain rule” 𝒇 𝒕+𝚫𝒕 =𝒇 𝒕 + 𝒇 ′ 𝒕 ∗𝚫𝒕 Example 𝒇 𝒕 =𝟐∗𝒕  𝒇 ′ 𝒕 =𝟐

How does it works  we start from f(0) 𝒇 𝟎+𝚫𝒕=𝟏 =𝟎+𝟐∗𝟏 = 2 f f(1) t 1

How does it works  we start from f(0) 𝒇 𝟏+𝟏 =𝟐+𝟐∗𝟏 = 4 f f(2) f(1) t 2 2

And so on… point by point we reproduce solution f(t) = 2t f f(2) f(1) t 2 2

Problems? - Accuracy Example – derivative varies (change of the function’s shape) Wrong value! f t

Solution? – More points, shorter interval Example – derivative varies (change of the function’s shape) f Problem? Computing efficiency! t

Different approach – finite difference method How to calculate c(t)? Different approach – finite difference method 𝚫𝒄 𝚫𝒕 =−𝒄 𝒕

Different approach – finite difference method How to calculate c(t)? Different approach – finite difference method 𝚫𝒄 𝚫𝒕 =−𝒌𝒄 𝒕 𝒄 𝒕+𝚫𝐭 −𝐜 𝐭 𝚫𝒕 =−𝒌𝒄 𝒕

Different approach – finite difference method How to calculate c(t)? Different approach – finite difference method 𝚫𝒄 𝚫𝒕 =−𝒌𝒄 𝒕 𝒄 𝒕+𝚫𝐭 −𝐜 𝐭 𝚫𝒕 =−𝒌𝒄 𝒕 𝒄 𝒕+𝚫𝐭 −𝐜 𝐭 =−𝚫𝐭𝒌𝒄 𝒕

Different approach – finite difference method, explicit scheme How to calculate c(t)? Different approach – finite difference method, explicit scheme 𝚫𝒄 𝚫𝒕 =−𝒄𝒌 𝒕 𝒄 𝒕+𝚫𝐭 −𝐜 𝐭 𝚫𝒕 =−𝒌𝒄 𝒕 𝒄 𝒕+𝚫𝐭 −𝐜 𝐭 =−𝚫𝐭𝒌𝒄 𝒕 𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 −𝚫𝐭𝐤𝒄 𝒕 =𝒄 𝒕 𝟏−𝐤𝚫𝐭

𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 −𝚫𝐭𝒄 𝒕 =𝒄 𝒕 𝟏−𝐤𝚫𝐭 𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 −𝚫𝐭𝒄 𝒕 =𝒄 𝒕 𝟏−𝐤𝚫𝐭 𝐤=𝟏 𝒄 𝒏 = 𝒄 𝒏−𝟏 𝟏−𝚫𝐭 c t

𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 −𝚫𝐭𝒄 𝒕 =𝒄 𝒕 𝟏−𝚫𝐭 𝐤=𝟏 𝒄 𝒏 = 𝒄 𝒏−𝟏 𝟏−𝚫𝐭 𝚫𝐭=𝟎.𝟏 𝒄 𝟎 = 𝒄 𝟎 =𝟏 𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 −𝚫𝐭𝒄 𝒕 =𝒄 𝒕 𝟏−𝚫𝐭 𝐤=𝟏 𝒄 𝒏 = 𝒄 𝒏−𝟏 𝟏−𝚫𝐭 𝚫𝐭=𝟎.𝟏 𝒄 𝟎 = 𝒄 𝟎 =𝟏 c 1 t

𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 −𝚫𝐭𝒄 𝒕 =𝒄 𝒕 𝟏−𝚫𝐭 𝐤=𝟏 𝒄 𝒏 = 𝒄 𝒏−𝟏 𝟏−𝚫𝐭 𝚫𝐭=𝟎.𝟏 𝒄 𝟎 = 𝒄 𝟎 =𝟏 𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 −𝚫𝐭𝒄 𝒕 =𝒄 𝒕 𝟏−𝚫𝐭 𝐤=𝟏 𝒄 𝒏 = 𝒄 𝒏−𝟏 𝟏−𝚫𝐭 𝚫𝐭=𝟎.𝟏 𝒄 𝟎 = 𝒄 𝟎 =𝟏 𝒄 𝟏 = 𝒄 𝟎 𝟏−𝚫𝐭 =𝟏∗ 𝟏−𝟎.𝟏 =𝟎.𝟗 c 1 t 0.1

𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 −𝚫𝐭𝒄 𝒕 =𝒄 𝒕 𝟏−𝚫𝐭 𝐤=𝟏 𝒄 𝒏 = 𝒄 𝒏−𝟏 𝟏−𝚫𝐭 𝚫𝐭=𝟎.𝟏 𝒄 𝟎 = 𝒄 𝟎 =𝟏 𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 −𝚫𝐭𝒄 𝒕 =𝒄 𝒕 𝟏−𝚫𝐭 𝐤=𝟏 𝒄 𝒏 = 𝒄 𝒏−𝟏 𝟏−𝚫𝐭 𝚫𝐭=𝟎.𝟏 𝒄 𝟎 = 𝒄 𝟎 =𝟏 𝒄 𝟏 = 𝒄 𝟎 𝟏−𝚫𝐭 =𝟏∗ 𝟏−𝟎.𝟏 =𝟎.𝟗 𝒄 𝟐 = 𝒄 𝟏 𝟏−𝚫𝐭 =𝟎.𝟗∗ 𝟏−𝟎.𝟏 =𝟎.𝟖𝟏 c 1 0.1 0.2 t

𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 −𝚫𝐭𝒄 𝒕 =𝒄 𝒕 𝟏−𝚫𝐭 𝐤=𝟏 𝒄 𝒏 = 𝒄 𝒏−𝟏 𝟏−𝚫𝐭 𝚫𝐭=𝟎.𝟏 𝒄 𝟎 = 𝒄 𝟎 =𝟏 𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 −𝚫𝐭𝒄 𝒕 =𝒄 𝒕 𝟏−𝚫𝐭 𝐤=𝟏 𝒄 𝒏 = 𝒄 𝒏−𝟏 𝟏−𝚫𝐭 𝚫𝐭=𝟎.𝟏 𝒄 𝟎 = 𝒄 𝟎 =𝟏 𝒄 𝟏 = 𝒄 𝟎 𝟏−𝚫𝐭 =𝟏∗ 𝟏−𝟎.𝟏 =𝟎.𝟗 𝒄 𝟐 = 𝒄 𝟏 𝟏−𝚫𝐭 =𝟎.𝟗∗ 𝟏−𝟎.𝟏 =𝟎.𝟖𝟏 c 1 𝒄 𝟑 = 𝒄 𝟐 𝟏−𝚫𝐭 =𝟎.𝟖𝟏∗ 𝟏−𝟎.𝟏 =𝟎.𝟕𝟐𝟗 0.1 0.2 0.3 t

𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 −𝚫𝐭𝒄 𝒕 =𝒄 𝒕 𝟏−𝚫𝐭 𝐤=𝟏 𝒄 𝒏 = 𝒄 𝒏−𝟏 𝟏−𝚫𝐭 𝚫𝐭=𝟎.𝟏 𝒄 𝟎 = 𝒄 𝟎 =𝟏 𝒄 𝟏 = 𝒄 𝟎 𝟏−𝚫𝐭 =𝟏∗ 𝟏−𝟎.𝟏 =𝟎.𝟗 𝒄 𝟐 = 𝒄 𝟏 𝟏−𝚫𝐭 =𝟎.𝟗∗ 𝟏−𝟎.𝟏 =𝟎.𝟖𝟏 𝒄 𝟑 = 𝒄 𝟐 𝟏−𝚫𝐭 =𝟎.𝟖𝟏∗ 𝟏−𝟎.𝟏 =𝟎.𝟕𝟐𝟗

Problems? 𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 −𝚫𝐭𝒄 𝒕 =𝒄 𝒕 𝟏−𝐤𝚫𝐭 𝐤=𝟏 Say 𝚫𝐭=𝟏 𝐭𝐡𝐞𝐧 𝒄 𝟏 =𝒄 𝟎 𝟏−𝟏 =𝟎 𝒄 𝟐 =𝒄 𝟏 𝟏−𝟏 =𝟎 Say 𝚫𝐭>𝟏 𝚫𝐭=𝟐 𝐭𝐡𝐞𝐧 𝒄 𝟏 =𝒄 𝟎 𝟏−𝟐 =−𝒄 𝟎 <𝟎 negative concentration. Unphysical!!! 𝒄 𝒕+𝚫𝐭 =𝒄 𝒕 𝟏−𝐤𝚫𝐭 →𝟏−𝐤𝚫𝐭>𝟎→𝚫𝐭<𝟏/𝐤

Solution? Implicit scheme Δ𝑡→0 f 𝑑𝑓 𝑑𝑡 𝑡 ∗ ≈ Δ𝑓 Δ𝑡 𝑡 ∗ 𝑜𝑟 Δ𝑓 Δ𝑡 𝑡 ∗ +Δ𝑡 or anywhere inbetween 𝑓 𝑡 ∗ Δ𝑓 Slope in point 𝑡 ∗ 𝑓 𝑡 ∗ +Δ𝑡 𝑡𝑔𝛽= lim Δ𝑡→0 Δ𝑓 Δ𝑡 = 𝑑𝑓 𝑑𝑡 Δ𝑡 𝛼 𝛽 𝑡 ∗ 𝑡 ∗ +Δ𝑡 t 𝑡𝑔𝛼= Δ𝑓 Δ𝑡 Average slope on Δ𝑡 interval

Solution? Implicit scheme Before… Now… 𝚫𝒄 𝚫𝒕 =−𝒌𝒄 𝒕 𝚫𝒄 𝚫𝒕 =−𝒌𝒄 𝒕+𝚫𝐭 𝒄 𝒕+𝚫𝐭 −𝐜 𝐭 𝚫𝒕 =−𝒌𝒄 𝒕+𝚫𝐭 𝒄 𝒕+𝚫𝐭 −𝐜 𝐭 𝚫𝒕 =−𝒌𝒄 𝒕 𝒄 𝒕+𝚫𝐭 =𝐜 𝐭 −𝚫𝐭𝒌𝒄 𝒕+𝚫𝐭 𝒄 𝒕+𝚫𝐭 =𝐜 𝐭 −𝚫𝐭𝒌𝒄 𝒕

Solution? Implicit scheme 𝒄 𝒕+𝚫𝐭 =𝐜 𝐭 −𝚫𝐭𝐤𝒄 𝒕+𝚫𝐭 𝒄 𝒕+𝚫𝐭 +𝚫𝐭𝐤𝒄 𝒕+𝚫𝐭 =𝐜 𝐭 𝒄 𝒕+𝚫𝐭 𝟏+𝐤𝚫𝐭 =𝐜 𝐭 𝒄 𝒕+𝚫𝐭 = 𝐜 𝐭 𝟏+𝐤𝚫𝐭 Always positive

Solutions, comparison 𝒅𝒄 𝒅𝒕 =−𝒄 𝒕 𝐤=𝟏 𝒄 𝒕+𝚫𝐭 = 𝐜 𝐭 𝟏+𝚫𝐭 𝒄 𝒕+𝚫𝐭 = 𝐜 𝐭 𝟏+𝚫𝐭 𝒄 𝒕+𝚫𝐭 =𝐜 𝐭 −𝚫𝐭𝒄 𝒕 𝒄 𝒕 =𝒄 𝟎 𝒆 −𝒕 𝚫𝐭=𝟎.𝟏 𝚫𝐭=𝟐

Problems? - Accuracy Example – derivative varies (change of the function’s shape) Wrong value! f t

But what about set of ODE? Same approach combined with linear equations 𝑑 𝑐 1 𝑑𝑡 =−0.12 𝑐 1 +0.02 𝑐 3 +1 𝑑 𝑐 1 𝑑𝑡 𝑑 𝑐 2 𝑑𝑡 𝑑 𝑐 3 𝑑𝑡 𝑑 𝑐 4 𝑑𝑡 𝑑 𝑐 5 𝑑𝑡 = 𝑑 𝑐 2 𝑑𝑡 =0.15 𝑐 1 −0.15 𝑐 2 -0.12 0.02 0.15 -0.15 0.025 -0.225 0.1 0.1375 0.03 0.01 -0.05 𝑐 1 𝑐 2 𝑐 3 𝑐 4 𝑐 5 + 1 0 4 0 0 𝑑 𝑐 3 𝑑𝑡 =0.025 𝑐 2 −0.225 𝑐 3 +4 𝑑 𝑐 4 𝑑𝑡 =0.1 𝑐 3 −0.1375 𝑐 4 +0.025 𝑐 5 𝑑 𝑐 5 𝑑𝑡 =0.03 𝑐 1 +0.01 𝑐 2 −0.04 𝑐 5

But what about set of ODE? Same approach combined with linear equations 𝑑 𝑐 1 𝑑𝑡 𝑑 𝑐 2 𝑑𝑡 𝑑 𝑐 3 𝑑𝑡 𝑑 𝑐 4 𝑑𝑡 𝑑 𝑐 5 𝑑𝑡 = -0.12 0.02 0.15 -0.15 0.025 -0.225 0.1 0.1375 0.03 0.01 -0.05 𝑐 1 𝑐 2 𝑐 3 𝑐 4 𝑐 5 + 1 0 4 0 0 -0.12 0.02 0.15 -0.15 0.025 -0.225 0.1 0.1375 0.03 0.01 -0.05 𝑑 𝑑𝑡 𝑐 1 𝑐 2 𝑐 3 𝑐 4 𝑐 5 = 𝑐 1 𝑐 2 𝑐 3 𝑐 4 𝑐 5 + 1 0 4 0 0

𝒅 𝒄 𝒅𝒕 =𝑨 𝒄 + 𝒃 But what about set of ODE? Same approach combined with linear equations -0.12 0.02 0.15 -0.15 0.025 -0.225 0.1 0.1375 0.03 0.01 -0.05 𝑑 𝑑𝑡 𝑐 1 𝑐 2 𝑐 3 𝑐 4 𝑐 5 = 𝑐 1 𝑐 2 𝑐 3 𝑐 4 𝑐 5 + 1 0 4 0 0 𝒄 𝒄 𝒃 A 𝒅 𝒄 𝒅𝒕 =𝑨 𝒄 + 𝒃

What next? Finite difference approach but on vectors! 𝒅 𝒄 𝒅𝒕 =𝑨 𝒄 𝚫 𝒄 𝚫𝒕 =𝑨 𝒄

What next? Finite difference approach but with vectors! 𝚫 𝒄 𝚫𝒕 =𝑨 𝒄 𝒄 𝒕+𝚫𝐭 − 𝐜 (𝐭) 𝚫𝒕 =𝑨 𝒄 𝒄 𝒕+𝚫𝐭 = 𝒄 𝒕 +𝚫𝐭𝑨 𝒄

𝒄 𝒕+𝚫𝐭 = 𝒄 𝒕 +𝚫𝐭𝑨 𝒄 (𝒕) 𝒄 𝒕+𝚫𝐭 = 𝑰+𝚫𝐭𝑨 𝐜 𝒕 𝒄 𝒕+𝚫𝐭 =𝑩 𝐜 𝒕 What next? Finite difference approach but with vectors! Explicit scheme 𝒄 = 𝒄 (𝒕) 𝒄 𝒕+𝚫𝐭 = 𝒄 𝒕 +𝚫𝐭𝑨 𝒄 (𝒕) 𝒄 𝒕+𝚫𝐭 = 𝑰+𝚫𝐭𝑨 𝐜 𝒕 𝒄 𝒕+𝚫𝐭 =𝑩 𝐜 𝒕 𝑩=𝑰+𝚫𝐭𝑨

𝒄 𝒕+𝚫𝐭 =𝑩 𝐜 𝒕 What next? Finite difference approach but with vectors! Explicit scheme 𝒄 = 𝒄 (𝒕) Define c(0) 𝒄 𝒕+𝚫𝐭 =𝑩 𝐜 𝒕 𝑩=𝑰+𝚫𝐭𝑨 Compute 𝑩=𝑰+𝚫𝐭𝐀 Problem? Unstable! Compute c in the next time frame 𝒄 𝒏𝚫𝐭 =𝐁𝐜( 𝐧−𝟏 𝚫𝐭)) 𝒏+𝟏

𝒄 𝒕+𝚫𝐭 = 𝒄 𝒕 +𝚫𝐭𝑨 𝒄 (𝒕+𝚫𝐭) 𝒄 𝒕+𝚫𝐭 −𝚫𝐭𝑨 𝒄 (𝒕+𝚫𝐭)= 𝒄 𝒕 What next? Finite difference approach but on vectors! Implicit scheme 𝒄 = 𝒄 (𝒕+𝚫𝐭) 𝒄 𝒕+𝚫𝐭 = 𝒄 𝒕 +𝚫𝐭𝑨 𝒄 (𝒕+𝚫𝐭) 𝒄 𝒕+𝚫𝐭 −𝚫𝐭𝑨 𝒄 (𝒕+𝚫𝐭)= 𝒄 𝒕 𝑰−𝚫𝐭𝑨 𝒄 𝒕+𝚫𝐭 = 𝒄 𝒕

𝑰−𝚫𝐭𝑨 𝒄 𝒕+𝚫𝐭 = 𝒄 𝒕 𝑩 𝒄 𝒕+𝚫𝐭 = 𝒄 𝒕 𝒄 𝒕+𝚫𝐭 = 𝑩 −𝟏 𝒄 𝒕 𝑩=𝑰−𝚫𝐭𝑨 What next? Finite difference approach but on vectors! Implicit scheme 𝒄 = 𝒄 (𝒕+𝚫𝐭) 𝑰−𝚫𝐭𝑨 𝒄 𝒕+𝚫𝐭 = 𝒄 𝒕 𝑩 𝒄 𝒕+𝚫𝐭 = 𝒄 𝒕 𝒄 𝒕+𝚫𝐭 = 𝑩 −𝟏 𝒄 𝒕 𝑩=𝑰−𝚫𝐭𝑨

Implicit scheme 𝒄 = 𝒄 (𝒕) Compute c in the next time frame Define c(0) 𝒄 𝒕+𝚫𝐭 = 𝑩 −𝟏 𝐜 𝒕 𝑩=𝑰−𝚫𝐭𝑨 Compute 𝑩=𝑰+𝚫𝐭𝐀 Problem? Computing 𝑩 −𝟏 Compute 𝑩 −𝟏 Compute c in the next time frame 𝒄 𝒏𝚫𝐭 = 𝐁 −𝟏 𝐜( 𝐧−𝟏 𝚫𝐭)) 𝒏+𝟏

Working example implicite scheme 𝑨 k 𝟏 =𝟏 𝑩 k 𝟐 =𝟏 𝑪 𝒅𝑨 𝒅𝒕 =−𝑨 Initially A = 1, B = 0, C = 0 𝒅𝑩 𝒅𝒕 =𝑨−𝑩 𝑑 𝑑𝑡 𝐴 𝐵 𝐶 = −1 0 0 1 −1 0 0 1 0 𝐴 𝐵 𝐶 𝒅𝑪 𝒅𝒕 =𝑩 𝑐 0 = 1 0 0

Working example 1. Initiate, calculate B 𝑨 k 𝟏 =𝟏 𝑩 k 𝟐 =𝟏 𝑪 𝑑 𝑑𝑡 𝐴 𝐵 𝐶 = −1 0 0 1 −1 0 0 1 0 𝐴 𝐵 𝐶 𝑐 0 = 1 0 0 𝑩=𝑰−𝚫𝐭𝑨 𝜟𝒕=1 𝑐 0 = 1 0 0 𝐵= 1 0 0 0 1 0 0 0 1 −1 −1 0 0 1 −1 0 0 1 0 = 2 0 0 −1 2 0 0 −1 1

Working example 2. Calculate 𝑩 −𝟏 𝐵= 2 0 0 −1 2 0 0 −1 1 𝐵= 2 0 0 −1 2 0 0 −1 1 𝐵 −1 = 0.5 0 0 0.25 0.5 0 0.25 0.5 1

Working example 3. Iterate n=1 𝑐 𝑛Δ𝑡 = 𝐵 −1 𝑐 𝑛−1 Δ𝑡 𝑐 1 = 𝐵 −1 𝑐 0 = 0.5 0 0 0.25 0.5 0 0.25 0.5 1 1 0 0 = 0.5 0.25 0.25

Working example 3. Iterate n=2 𝑐 𝑛Δ𝑡 = 𝐵 −1 𝑐 𝑛−1 Δ𝑡 𝑐 2 = 𝐵 −1 𝑐 1 = 0.5 0 0 0.25 0.5 0 0.25 0.5 1 0.5 0.25 0.25 = 0.25 0.25 0.5

Working example 3. Iterate n=3 𝑐 𝑛Δ𝑡 = 𝐵 −1 𝑐 𝑛−1 Δ𝑡 𝑐 3 = 𝐵 −1 𝑐 2 = 0.5 0 0 0.25 0.5 0 0.25 0.5 1 0.25 0.25 0.5 = 0.125 0.1875 0.6875

Working example 3. Iterate n=4 𝑐 𝑛Δ𝑡 = 𝐵 −1 𝑐 𝑛−1 Δ𝑡 𝑐 4 = 𝐵 −1 𝑐 3 = 0.5 0 0 0.25 0.5 0 0.25 0.5 1 0.125 0.1875 0.6875 = 0.0625 0.125 0.8125

Partial ODE Diffusion equation 𝜕𝑐 𝜕𝑡 =−𝐷 𝜕 2 𝑐 𝜕 𝑥 2

„Building blocks” for differentials 𝜕𝑐 𝜕𝑥 = 𝑐 𝑖+1 − 𝑐 𝑖−1 Δ𝑥 +𝑂 Δ 𝑥 2 𝜕𝑐 𝜕𝑥 = 𝑐 𝑖 − 𝑐 𝑖−1 Δ𝑥 +𝑂 Δ𝑥 𝜕 2 𝑐 𝜕 𝑥 2 = 𝑐 𝑖+1 −2 𝑐 𝑖 + 𝑐 𝑖−1 Δ 𝑥 2 +𝑂 Δ 𝑥 2

𝜕𝑐 𝜕𝑡 =−𝐷 𝜕 2 𝑐 𝜕 𝑥 2 𝜕𝑐 𝜕𝑡 = 𝑐 𝑚,𝑖+1 − 𝑐 𝑚,𝑖 Δ𝑡 𝜕 2 𝑐 𝜕 𝑥 2 = 𝑐 𝑚+1,𝑖 −2 𝑐 𝑚,𝑖 + 𝑐 𝑚−1,𝑖 Δ 𝑥 2

Example – 1 D Diffusion equation (drug release) Initial concentration profile 𝜙(𝑥) Instantaneous outtake Instantaneous outtake 𝑐 𝑡 =−𝐷 𝑐 𝑥𝑥 𝑐 0,𝑡 =0 𝑐 1,𝑡 =0 𝑐 𝑥,0 =𝜙 𝑥 Drug 1 Question: How the profile changes in time?

Example – 1 D Diffusion equation (drug release) Initial concentration profile 𝜙(𝑥) Instantaneous outtake Instantaneous outtake 𝑐 𝑡 =−𝐷 𝑐 𝑥𝑥 𝑐 0,𝑡 =0 𝑐 1,𝑡 =0 𝑐 𝑥,0 =𝜙 𝑥 Drug 1 Question: How the profile changes in time?

Example – 1 D Diffusion equation (drug release) Initial concentration profile 𝜙(𝑥) Instantaneous outtake Instantaneous outtake 𝑐 𝑡 =−𝐷 𝑐 𝑥𝑥 𝑐 0,𝑡 =0 𝑐 1,𝑡 =0 𝑐 𝑥,0 =𝜙 𝑥 Drug 1 Question: How the profile changes in time?

Example – 1 D Diffusion equation (drug release) Initial concentration profile 𝜙(𝑥) Instantaneous outtake Instantaneous outtake 𝑐 𝑡 =−𝐷 𝑐 𝑥𝑥 𝑐 0,𝑡 =0 𝑐 1,𝑡 =0 𝑐 𝑥,0 =𝜙 𝑥 Drug 1 Question: How the profile changes in time?

Example – 1 D Diffusion equation (drug release) Initial concentration profile 𝜙(𝑥) Instantaneous outtake Instantaneous outtake 𝑐 𝑡 =−𝐷 𝑐 𝑥𝑥 𝑐 0,𝑡 =0 𝑐 1,𝑡 =0 𝑐 𝑥,0 =𝜙 𝑥 Drug 1 Question: How the profile changes in time?

Example – 1 D Diffusion equation (drug release) Initial concentration profile 𝜙(𝑥) 𝑐 𝑡 =−𝐷 𝑐 𝑥𝑥 𝑐 0,𝑡 =0 𝑐 1,𝑡 =0 𝑐 𝑥,0 =𝜙 𝑥 𝑐 𝑛,𝑖 concentration in position 𝑛Δ𝑥 and time 𝑖Δ𝑡 𝑇 Δ𝑡 1 Δ𝑥 𝐿 𝑥 𝑖 =𝑛Δ𝑥, Δ𝑥= 𝐿 𝑀 𝑡 𝑛 =𝑖Δ𝑡, Δ𝑡= 𝑇 𝑁

𝑐 𝑡 =−𝐷 𝑐 𝑥𝑥 𝑐 0,𝑡 =0 → 𝑐 0,𝑗 =0 𝑐 1,𝑡 =0→ 𝑐 𝑀,𝑗 =0 𝑐 𝑥,0 =𝜙 𝑥 → 𝑢 𝑖,0 =𝜙 𝑥

𝑥 𝑖 =𝑛Δ𝑥, Δ𝑥= 𝐿 𝑀 𝑡 𝑛 =𝑖Δ𝑡, Δ𝑡= 𝑇 𝑁

𝑐 𝑚,𝑖+1 − 𝑐 𝑚,𝑖 Δ𝑡 =−𝐷 𝑐 𝑚+1,𝑖 −2 𝑐 𝑚,𝑖 + 𝑐 𝑚−1,𝑖 Δ 𝑥 2 𝑐 𝑚,𝑖+1 = 𝑐 𝑚,𝑖 − 𝐷Δ𝑡 Δ 𝑥 2 𝑐 𝑚+1,𝑖 −2 𝑐 𝑚,𝑖 + 𝑐 𝑚−1,𝑖 𝑐 𝑚,𝑖+1 = 𝑐 𝑚,𝑖 −𝑟 𝑐 𝑚+1,𝑖 −2 𝑐 𝑚,𝑖 + 𝑐 𝑚−1,𝑖

𝑐 𝑚,𝑖+1 = 𝑐 𝑚,𝑖 −𝑟 𝑐 𝑚+1,𝑖 −2 𝑐 𝑚,𝑖 + 𝑐 𝑚−1,𝑖 𝑐 𝑚,𝑖+1 =−𝑟 𝑐 𝑚−1,𝑖 + 1+2𝑟 𝑐 𝑚,𝑖 −𝑟 𝑐 𝑚+1,𝑖

𝑐 𝑡 =−𝐷 𝑐 𝑥𝑥 𝑐 0,𝑡 =0 → 𝑐 0,𝑗 =0 𝑐 1,𝑡 =0→ 𝑐 𝑀,𝑗 =0 𝑐 𝑥,0 =𝜙 𝑥 → 𝑢 𝑖,0 =𝜙 𝑥 𝑐 1,𝑖+1 =−𝑟 𝑐 0,𝑖 + 1+2𝑟 𝑐 1,𝑖 −𝑟 𝑐 2,𝑖 𝑐 1,𝑖+1 = 1+2𝑟 𝑐 1,𝑖 −𝑟 𝑐 2,𝑖 𝑐 𝑀−1,𝑖+1 =−𝑟 𝑐 𝑀−2,𝑖 + 1+2𝑟 𝑐 𝑀−1,𝑖 −𝑟 𝑐 𝑀,𝑖 𝑐 𝑀−1,𝑖+1 =−𝑟 𝑐 𝑀−2,𝑖 + 1+2𝑟 𝑐 𝑀−1,𝑖

𝑐 1,𝑖+1 = 1+2𝑟 𝑐 1,𝑖 −𝑟 𝑐 2,𝑖 𝑐 𝑚,𝑖+1 =−𝑟 𝑐 𝑚−1,𝑖 + 1+2𝑟 𝑐 𝑚,𝑖 −𝑟 𝑐 𝑚+1,𝑖 𝑐 𝑀−1,𝑖+1 =−𝑟 𝑐 𝑀−2,𝑖 + 1+2𝑟 𝑐 𝑀−1,𝑖 𝑐 1,𝑖+1 𝑐 2,𝑖+1 ⋮ 𝑐 𝑀−1,𝑖+1 = 1+2𝑟 −𝑟 0 ⋯ 0 −𝑟 1+2𝑟 −𝑟 ⋯ 0 0 ⋮ 0 ⋱ 0 ⋱ ⋯ ⋱ −𝑟 0 ⋮ 1+2𝑟 𝑐 1,𝑖 𝑐 2,𝑖 ⋮ 𝑐 𝑀−1,𝑖

𝑐 1,𝑖+1 𝑐 2,𝑖+1 ⋮ 𝑐 𝑀−1,𝑖+1 = 1+2𝑟 −𝑟 0 ⋯ 0 −𝑟 1+2𝑟 −𝑟 ⋯ 0 0 ⋮ 0 ⋱ 0 ⋱ ⋯ ⋱ −𝑟 0 ⋮ 1+2𝑟 𝑐 1,𝑖 𝑐 2,𝑖 ⋮ 𝑐 𝑀−1,𝑖 𝑐 𝑖+1 =𝐴 𝑐 𝑖