Runge-Kutta and Cellular Automata Simulations

  • Upload
    akozy

  • View
    224

  • Download
    0

Embed Size (px)

Citation preview

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    1/22

    More Accurate Rate Estimation

    CS 170:Computing for the Sciences and

    Mathematics

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    2/22

    Administrivia

    Last time (in P265) Eulers method for computation

    Today Better Methods

    Simulation / Automata

    HW #7 Due!

    HW #8 assigned

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    3/22

    Eulers method

    Simplest simulation technique for solvingdifferential equation

    Intuitive Some other methods faster and more accurate

    Error on order of t Cut t in half cut error by half

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    4/22

    Eulers Method

    tn = t0 + n t

    Pn = Pn-1 + f(tn-1, Pn-1) t

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    5/22

    Runge-Kutta 2 method

    Euler's Predictor-Corrector (EPC) Method

    Better accuracy than Eulers Method

    Predict what the next point will be (with Euler)

    then correct based on estimated slope.

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    6/22

    Concept of method

    Instead of slope of tangent line at (tn-1, Pn-1), wantslope of chord

    For t = 8, want slope of chord between

    (0, P(0)) and (8, P(8))

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    7/22

    Concept of method

    Then, estimate for 2nd point is ?

    (t, P(0) + slope_of_chord * t)

    (8, P(0) + slope_of_chord * 8)

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    8/22

    Concept of method

    Slope of chord average of slopes of tangents atP(0) and P(8)

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    9/22

    EPC

    How to find the slope of tangent at P(8) when we donot know P(8)?

    Y = Eulers estimate for P(8)

    In this case Y = 100+ 100*(.1*8) = 180 Use (8, 180) in derivative formula to obtain estimate

    of slope at t = 8

    In this case, f(8, 180) = 0.1(180) = 18

    Average of slope at 0 and estimate of slope at 8 is 0.5(10 + 18) = 14

    Corrected estimate of P1 is 100 + 8(14) = 212

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    10/22

    Predicted and corrected estimation of(8, P(8))

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    11/22

    Runge-Kutta 2 Algorithm

    initialize simulationLength,population, growthRate, t

    numIterationssimulationLength / t

    fori going from 1 to numIterations do the following:growth growthRate * population

    Ypopulation + growth * t

    t i*t

    population population+ 0.5*( growth + growthRate*Y)

    estimating next point (Euler)

    averaging two slopes

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    12/22

    Error

    With P(8) = 15.3193 and Euler estimate = 180,relative error = ?

    |(180 - P(8))/P(8)| 19.1%

    With EPC estimate = 212, relative error = ? |(212 - P(8))/P(8)| 4.7%

    Relative error of Euler's method is O(t)

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    13/22

    EPC at time 100

    t Estimated P Relative error

    1.0 2,168,841 0.015348

    0.5 2,193,824 0.004005

    0.25 2,200,396 0.001022

    Relative error of EPC method is on order of O((t)2)

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    14/22

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    15/22

    S I M U L A T I O N

    CS 170:Computing for the Sciences and

    Mathematics

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    16/22

    Computer simulation

    Having computer program imitate reality, in order tostudy situations and make decisions

    Applications?

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    17/22

    Use simulations if

    Not feasible to do actual experiments

    Not controllable (Galaxies)

    System does not exist

    Engineering Cost of actual experiments prohibitive Money

    Time

    Danger

    Want to test alternatives

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    18/22

    Example: Cellular Automata

    Structure

    Grid of positions

    Initial values

    Rules to update at each timestep

    often very simple

    New = Old + Change

    This Change could entail a diff. EQ, a constantvalue, or some set of logical rules

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    19/22

    Mr. von Neumanns Neighborhood

    Often in automata simulations, acells change is dictated by the state

    of its neighborhood Examples: Presence of something in the neighborhood

    temperature values, etc. of neighboring cells

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    20/22

  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    21/22

    Conways Game of Life

    The Rules

    For a space that is 'populated': Each cell with one or zero neighbors dies (loneliness)

    Each cell with four or more neighbors dies (overpopulation) Each cell with two or three neighbors survives

    For a space that is 'empty' or 'unpopulated

    Each cell with three neighbors becomes populated

    http://www.bitstorm.org/gameoflife/

    http://www.bitstorm.org/gameoflife/http://www.bitstorm.org/gameoflife/
  • 7/29/2019 Runge-Kutta and Cellular Automata Simulations

    22/22

    HOMEWORK!

    Homework 8 READ Seeing Around Corners

    http://www.theatlantic.com/magazine/archive/2002/04/seeing-around-corners/2471/

    Answer reflection questions to be posted on class site

    Due THURSDAY 11/4/2010

    Thursdays Class in HERE (P265)

    http://www.theatlantic.com/magazine/archive/2002/04/seeing-around-corners/2471/http://www.theatlantic.com/magazine/archive/2002/04/seeing-around-corners/2471/http://www.theatlantic.com/magazine/archive/2002/04/seeing-around-corners/2471/http://www.theatlantic.com/magazine/archive/2002/04/seeing-around-corners/2471/http://www.theatlantic.com/magazine/archive/2002/04/seeing-around-corners/2471/http://www.theatlantic.com/magazine/archive/2002/04/seeing-around-corners/2471/http://www.theatlantic.com/magazine/archive/2002/04/seeing-around-corners/2471/