Population of two species: Predator and Prey model, e.g Rabbits and FoxParadisal Condition: y'(t) = a y(t).
It may be valid for a short period, the solution approaches infinity as t approaches infinity.
Add death rate: y'(t) = a y(t) - b y(t) = (a-b) y(t).
It will valishes if b>a, and approaches to infinity if a>b; and remains as a constant if a=b.Better model: y'(t) = a y(t) - b y(t) 2.
Transfer high order IVP to first order system.y'(t) = a y(t) - b y(t) z(t)
z'(t) = - c z(t) + d y(t) z(t).
y'''(t) - 2 y''(t) + t y'(t) + 2 y = 0, y(0) = 0, y'(0)=1, y''(0)=0.Define:
y1 = y,Then:
y2 = y'
y3 = y''.
y1 ' = y2,
y2' = y'' = y3,
y3' = y''' = 2 y'' - t y' - 2 y = 2 y3 - t y2 - 2 y1
y1 (0) = y(0) = 0; y2(0) = y'(0) = 1; y3(0) = y''(0) = 0.
Format for defining an ODE system:
yp(1) =
yp(2) =
What should be the name of this matlab function?
How do you solve the original problem using Matlab?
t y1 y2 y3 .............................................
t(1)=t0 y1(t0) y2(t0) y3(t0) .............................................
t(2) =t0+h y1(t(2)) y2(t(2)) y3(t(2)) .............................................
.................................................................................................................................................................
t(n+1) = tfinal
y1(t(n+1)) y2(t(n+1))
y3(t(n+1)) ...........................................
Summary of Runge-Kutta methodKey idea: y' = f(x,y); y(x0) = y0; It is equivalent to:Very popular and useful More accurate, h2, h3 h4 .,.... Adaptive time steps, different h. More stable (later)
y(x) = y0+ int f(t, y(t)) from x0 to x .
From one step to the next, find better approximation to the integral.
Try different strategies of integration we get different RK methods.
Examples: Left rectangle, Mid-rectangle, Right rectangle, Trapezoidal ..... (class exercise)
Steps: (three groups of coefficients)Remarks:How to determine the coefficients:
- Choose a few points,
- Choose predictions
- Choose final combinations
- Points between xi and xi+1 are given
- Other coefficients are determined from the Taylor expansion.
Format calling ODE45 (RK(4) + RK(5), and adaptive time step):Generally, RK(k) method is k-th order accurate, which means that the error is propotional to hk.
High order methods require more function evaluations (f(x,t)). Therefore if the function is easy to compute, high order methods are more efficient. If the function is too complicated and take too much time to evaluate, then the lower order method such as Euler's method may be more efficient. [x, y] = ode45('yfun',[x0, xfinal] ,y0)
Comparison of different method for the following problem:
y1' = -y2,The exact solution is y1= cos (x), y2 = sin (x), y1 + y2 ' = 1, so phase plot plot(y1,y2) is a circle.
y2 ' = y1
y1(0) = 1; y2(0) = 0.