ENGN2219/COMP6719 Computer Architecture & Simulation Ramesh - - PowerPoint PPT Presentation

β–Ά
engn2219 comp6719
SMART_READER_LITE
LIVE PREVIEW

ENGN2219/COMP6719 Computer Architecture & Simulation Ramesh - - PowerPoint PPT Presentation

ENGN2219/COMP6719 Computer Architecture & Simulation Ramesh Sankaranarayana Semester 1, 2020 1 Week 8: Simulation - Dynamical Systems 2 An informal denition A dynamical system is one whose state changes over time The state space may


slide-1
SLIDE 1

ENGN2219/COMP6719

Computer Architecture & Simulation Ramesh Sankaranarayana Semester 1, 2020

1

slide-2
SLIDE 2

Week 8: Simulation - Dynamical Systems

2

slide-3
SLIDE 3

An informal denition

A dynamical system is one whose state changes over time The state space may be discrete or continuous, nite or innite Time may be continuous or discrete Represented using diferential equations or diference equations Use analytical or numerical simulation approaches to study the system

3

slide-4
SLIDE 4

Simple Pendulum

4

slide-5
SLIDE 5

Lorenz Attractor

5

slide-6
SLIDE 6

Bouncing Ball

6

slide-7
SLIDE 7

Magnetohydrodynamic Flow Simulation

7

slide-8
SLIDE 8

Random Walk

A random walk describes a walk in which each step is chosen by a random mechanism, independent of any previous step. Used to model a number of diferent phenomena, such as: Random movement of molecules in liquids and gases Share prices Exchange rates Search path of bacteria The size of the Web Gambling

8

slide-9
SLIDE 9

One dimensional random walk

Walk along one axis Steps of equal size, forwards or backwards

9

slide-10
SLIDE 10

Two dimensional random walk

Walk along two axes Steps of equal size, in one of four directions

10

slide-11
SLIDE 11

Interpolation

Given a set of discrete data points, (which might represent some unknown function), determine the value at some point between already existing data points. linear interpolation spline interpolation

11

slide-12
SLIDE 12

Linear interpolation

12

slide-13
SLIDE 13

Cubic spline interpolation

13

slide-14
SLIDE 14

Extrapolation

In extrapolation, we would like to estimate the value at a point outside of the existing data points. This comes with a certain amount of uncertainty and the results are less meaningful. Keep in mind that the resulting value may not be accurate.

14

slide-15
SLIDE 15

Linear extrapolation

15

slide-16
SLIDE 16

Cubic spline extrapolation

16

slide-17
SLIDE 17

Regression

Assume that we are given a set of data points and we want to determine the value

  • f the unknown function that these points represent, at a point within the range

dened by these points. However, the measurement of the data has introduced some noise and therefore the date is imprecise. In such cases, we try and t a polynomial function to the data. The choice of the polynomial must be made by the

  • user. This approach is called regression.

17

slide-18
SLIDE 18

Linear Regression

In linear regression, we try and t a linear equation to a set of data points. Given a bunch of data points, let’s estimate a best t linear estimate.

18

slide-19
SLIDE 19

Let’s now use the polyfit function to do a best t for us.

19

slide-20
SLIDE 20

So how do we decide which one is a better t? Use some error measure A commonly used one is to minimize the error dened by the sum of the squared diferences between the actual data points and the estimates. If we do this in the above two cases, we get: Manual t: 573 Polyt: 356.82

𝑇𝑇𝐹 = ( βˆ’ Ξ£π‘œ

𝑗=1 𝑦𝑗

𝑦 Β―)2

20

slide-21
SLIDE 21

Polynomial Regression

Linear regression is a special case of polynomial regression, where you try and t a polynomial of degree to the data, minimizing the error as computed by an appropriate method.

π‘œ

21

slide-22
SLIDE 22

talk

So which order polynomial would you use? Why?

22

slide-23
SLIDE 23

Questions?

23

slide-24
SLIDE 24

Numerical Integration

Numerical integration generally involves evaluating the value of the integrand at a nite set of points and using a weighted sum of these values to approximate the

  • integral. The intent is to calculate the area under the curve. Two common

techniques estimate the function with a set of piecewise linear or parabolic functions.

24

slide-25
SLIDE 25

Using the trapz function

Find the area of between and .

𝑧 = π‘‘π‘—π‘œ(𝑦) 2𝜌

25

slide-26
SLIDE 26

Using the quad function

quad is a general purpose integration function. You can use dblquad and tplquad for double and triple integration, respectively.

26

slide-27
SLIDE 27

Numerical Diferentiation

Numerical diferentiation techniques estimate the derivative of a function at a point by approximating the slope of the tangent at , using values of the function at points near . The approximation of the slope can be done in several ways. Plot the derivate of between and .

𝑦𝑙 𝑦𝑙 𝑦𝑙 𝑧 = π‘‘π‘—π‘œ(𝑦) 2𝜌

27

slide-28
SLIDE 28

Forward diference approximation

The derivate at is estimated by computing the slope of the line between and .

𝑦𝑙 𝑦𝑙 𝑦𝑙+1

28

slide-29
SLIDE 29

Backward diference approximation

The derivate at is estimated by computing the slope of the line between and .

𝑦𝑙 π‘¦π‘™βˆ’1 𝑦𝑙

29

slide-30
SLIDE 30

Central diference approximation

The derivate at is estimated by computing the slope of the line between and . In practice, you use the mid-points of each interval, to maximize usage of the given data.

𝑦𝑙 π‘¦π‘™βˆ’1 𝑦𝑙+1

30

slide-31
SLIDE 31

Solving ordinary diferential equations

You can use ode or odeint. odeint has a simpler interface and uses the lsoda

  • algorithm. Note the the rst two arguments for these are in opposite order. Use ode

to select one of the many available integrators, not just lsoda. We will use odeint. scipy.integrate.odeint(func,y0,t,args) where func computes the derivative of at a specic time y0 is the initial condition on t is an array. A sequence of time points to solve for args: tuple, optional. Extra arguments to pass to the function.

𝑧 𝑒0 𝑧 𝑧

31

slide-32
SLIDE 32

Example 1

Consider the system represented by the following ODE:

  • r

Solve for this in the interval . The initial boundary condition is .

= 2𝑒 𝑒𝑧 𝑒𝑒 = 2𝑒 𝑧′ [βˆ’1, 1] 𝑧(βˆ’1) = 1

32

slide-33
SLIDE 33

33

slide-34
SLIDE 34

Example 2

Consider the system represented by the following ODEs: If and , this simplies to: The interval is and the boundary condition is and .

= 𝑦 𝑒𝑧 𝑒𝑒 = βˆ’π‘§ 𝑒𝑦 𝑒𝑒 ≑ 𝑧 𝑧1 ≑ 𝑦 𝑧2 = 𝑧′

1

𝑧2 = βˆ’ 𝑧′

2

𝑧1 [βˆ’1, 1] (βˆ’1) = 1 𝑧1 (βˆ’1) = 1 𝑧2

34

slide-35
SLIDE 35

35

slide-36
SLIDE 36

Example 3 - Damped simple harmonic motion

Consider the second-order ODE representing a damped simple harmonic motion: with We can turn this into two rst-order equations by dening a variable . We now have: with .

𝑧″ +2𝑧′ + 2𝑧 = 𝑑𝑝𝑑(2𝑦) 𝑧(0) = 0, 𝑧′(0) = 0 𝑨 ≑ 𝑧′ + 2𝑨 + 2𝑧 = 𝑑𝑝𝑑(2𝑦) 𝑨′ 𝑧(0) = 0, 𝑨(0) = 0

36

slide-37
SLIDE 37

37

slide-38
SLIDE 38

Example 4 - Predator Prey System

The following Lotka-Volterra equations describe the evolution of a predator-prey system: where represents the prey population (say rabbits) and represents the predator population (say foxes). The derivatives are the growth rates. , , and are positive constants describing the interaction of the predators and prey (assume these are all ). Let’s assume that there are 1.5 rabbits and 1 fox initially.

= 𝑦(𝑏 βˆ’ 𝑐𝑧) 𝑒𝑦 𝑒𝑒 = βˆ’π‘§(𝑑 βˆ’ 𝑒𝑦) 𝑒𝑧 𝑒𝑒 𝑦 𝑧 𝑏 𝑐 𝑑 𝑒 1

38

slide-39
SLIDE 39

39

slide-40
SLIDE 40

40

slide-41
SLIDE 41

Questions?

41