Pages

Tuesday, September 20, 2016

Ordinary Differential Equations part 3

Instead of solving ordinary differential equations directly using 'Euler'(euode) or 'Runge-Kutta'(rkode) , there exists a graphical method that can show charactistics of the solution for some particular ode problems. One example is the problem of 'predator-prey' problem that we introduced on the part 1 of the 'ode' post :
First, the problem is re-stated as follows :
Solve the equation for t from 0 to 8 :

dx/dt =   x -  x y
dy/dt = - y +  x y

Initial condition xt=0 = 0 , yt=0 = 2
We can cancel out the denominator 'dt' from both equations by dividing the second equation by the first equation and reduce the two equations into one equation. The result is shown below :
Solve the equation for t from 0 to 8 :

dy/dx = (-y + x y)/(x - x y)

Initial condition xt=0 = 0 , yt=0 = 2
As the right handed side of the above equation do not contain the variable 't', the slope dy/dx is not varied with time t at any point (x,y).
In part 1 of the 'ode' post, we had been shown a plot of x vs y resulted in a closed solution curve that pass through the initial point (0,2) of the plane x-y. That closed solution curve's slope is actually given by the above formula of dy/dx. Using that dy/dx formula, we can actually generate a whole set of solution curves when satisfy different initial conditions.
To get what a set of solution curves look like, Mathcalc8 has a function called 'plotz' that can visualize the value of the slope dy/dx when it's formula is given.
The one line input is shown below :

  • Input 1 : plotz('slope','(-y+x*y)/(x-x*y)',0,3,0.2,0,3,0.2)
     

  • Below is the resulting graph :


    The graph is called slope field. Small bars are drawn at different (x,y) position and their slope of the bar is the value of slope calculated from the dy/dx formula at that point. Started from any initial point, you can develop a solution curve from following and joining those bars.
    It can be seen from the graph that when the initial condition of x and y are within 0 to 3, except the point (1,1), the solution curve would be a closed loop circulating around point (1,1). That point is the stable point where dy/dx = 0.
    By using the slope field, it shows us the charactistic of the solutions for an ode problem.
    Below is another example showing the use of slope field :
    Find solution y for x :
    
    dy/dx = y - x
    
    To plot the slope field :

  • Input 2 : plotz('slope','y-x',-3,3,0.5,-3,3,0.5)
     

  • The resulting graph is :


    From the slope field, it can be found that the line y - x = 1 divides the graph into two different regions. The region at the top left side shows solution curves that when x increases to infinity, y would increases to positive infinity. The region at the bottom right shows solution curves that when x increases to infinity, y would at some point begin to decrease to negative infinity. This means that the solution y increases to positive or negative infinity depends on which region the initial point (x0,y0) fall in.