engn2219 comp6719
play

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


  1. ENGN2219/COMP6719 Computer Architecture & Simulation Ramesh Sankaranarayana Semester 1, 2020 1

  2. Week 8: Simulation - Dynamical Systems 2

  3. An informal de�nition A dynamical system is one whose state changes over time The state space may be discrete or continuous, �nite or in�nite Time may be continuous or discrete Represented using di�ferential equations or di�ference equations Use analytical or numerical simulation approaches to study the system 3

  4. Simple Pendulum 4

  5. Lorenz Attractor 5

  6. Bouncing Ball 6

  7. Magnetohydrodynamic Flow Simulation 7

  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 di�ferent 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

  9. One dimensional random walk Walk along one axis Steps of equal size, forwards or backwards 9

  10. Two dimensional random walk Walk along two axes Steps of equal size, in one of four directions 10

  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

  12. Linear interpolation 12

  13. Cubic spline interpolation 13

  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

  15. Linear extrapolation 15

  16. Cubic spline extrapolation 16

  17. Regression Assume that we are given a set of data points and we want to determine the value of the unknown function that these points represent, at a point within the range de�ned 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

  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

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

  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 de�ned by the sum of the squared di�ferences between the actual data points and the estimates. ¯) 2 Σ 𝑜 𝑇𝑇𝐹 = 𝑗 =1 𝑦 𝑗 ( − 𝑦 If we do this in the above two cases, we get: Manual �t: 573 Poly�t: 356.82 20

  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

  22. talk So which order polynomial would you use? Why? 22

  23. Questions? 23

  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

  25. Using the trapz function Find the area of between and . 𝑧 = 𝑡𝑗𝑜 ( 𝑦 ) 0 2 𝜌 25

  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

  27. Numerical Di�ferentiation Numerical di�ferentiation 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 . 𝑧 = 𝑡𝑗𝑜 ( 𝑦 ) 0 2 𝜌 27

  28. Forward di�ference approximation The derivate at is estimated by computing the slope of the line between and 𝑦 𝑙 𝑦 𝑙 . 𝑦 𝑙 +1 28

  29. Backward di�ference approximation The derivate at is estimated by computing the slope of the line between 𝑦 𝑙 𝑦 𝑙 − 1 and . 𝑦 𝑙 29

  30. Central di�ference approximation The derivate at is estimated by computing the slope of the line between 𝑦 𝑙 𝑦 𝑙 − 1 and . In practice, you use the mid-points of each interval, to maximize usage of 𝑦 𝑙 +1 the given data. 30

  31. Solving ordinary di�ferential 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 speci�c time 𝑧 𝑢 0 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. 31

  32. Example 1 Consider the system represented by the following ODE: 𝑒𝑧 = 2 𝑢 𝑒𝑢 or 𝑧 ′ = 2 𝑢 Solve for this in the interval . The initial boundary condition is . [ − 1, 1] 𝑧 ( − 1) = 1 32

  33. 33

  34. Example 2 Consider the system represented by the following ODEs: 𝑒𝑧 = 𝑦 𝑒𝑢 𝑒𝑦 = − 𝑧 𝑒𝑢 If and , this simpli�es to: 𝑧 1 ≡ 𝑧 𝑧 2 ≡ 𝑦 𝑧 ′ = 𝑧 2 1 𝑧 ′ = − 𝑧 1 2 The interval is and the boundary condition is and . [ − 1, 1] 𝑧 1 ( − 1) = 1 𝑧 2 ( − 1) = 1 34

  35. 35

  36. Example 3 - Damped simple harmonic motion Consider the second-order ODE representing a damped simple harmonic motion: 𝑧 ″ +2 𝑧 ′ + 2 𝑧 = 𝑑𝑝𝑡 (2 𝑦 ) with 𝑧 (0) = 0, 𝑧 ′ (0) = 0 We can turn this into two �rst-order equations by de�ning a variable . We 𝑨 ≡ 𝑧 ′ now have: 𝑨 ′ + 2 𝑨 + 2 𝑧 = 𝑑𝑝𝑡 (2 𝑦 ) with . 𝑧 (0) = 0, 𝑨 (0) = 0 36

  37. 37

  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

  39. 39

  40. 40

  41. Questions? 41

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend