Phy ODE

1.0  The predator pray equation is
       

where, x = population of the pray
           y= population of the predator
 the initial values are
 x=1.0,  y=0.5,  t=0.0,  a=0.5,  alpha=0.05,  c=1.0,  gamma=0.9  
Obtain a graph that show the visual impression of the number of predator and pray.

Hare we can use the Euler method.

Euler method is a first-order numerical procedure for solving ordinary differential equations (ODEs) with a given initial value. It is the most basic explicit method for numerical integration of ordinary differential equation 

The Euler Method is


Where h is the step size.


The code is---


#include<iostream>
#include<stdio.h>
#include<cmath>

using namespace std;

FILE*cplab;

int main(){
 
    cplab=fopen("new11","w");
 
    int i;
    double x=1.0, y=0.5, t=0.0, a=0.5, alpha=0.05, c=1.0, gamma=0.9;
    double h=0.001;
 
    for( i=0;  i<=50000;  i++)  {
             x = x+h*( a*x - alpha*x*y);
             y = y+h*(-c*y + gamma*x*y );
             fprintf( cplab,"%lf  %lf  %lf  \n",  i*h , x , y );      
             }
             fclose(cplab);
       
             return 0;
             }






2.0 A falling body is described by-


                                                                                                                                  
      where v = v(t) is the velocity of the body, t is the time and g = 9.8 m/s  , a = 0.2 s-1   

  (a)  Solve the above differential equation using any suitable numerical algorithm.  Take
           the initial condition as v(0) = 0.

    (b)  Write the values of the velocity v(t) for time t = 0 s to t = 40 s, in a file and plot
           v vs.  t.  From the plot, approximately determine the terminal velocity.


#include<iostream>
#include<stdio.h>

using namespace std;

FILE * cplab;

int main(){

cplab = fopen("gnu41", "w");    
  
  int i;
  double v=0.0, a=0.2, g=9.8, h=.001;

  for(i=0; i<=40000; i++)             //40/0.001=40000
    {
      v=v+h*(g-a*v);
    
      fprintf( cplab,"%lf %lf \n", i*h, v );
     
    }
  fclose(cplab);  
  
  return 0;
}

Terminal velocity Vs Time for free fall

1 comment:

  1. http://phet.colorado.edu/sims/pendulum-lab/pendulum-lab_en.html

    ReplyDelete