Pages

Sunday, 23 October 2011

Euler's Method For Numerical Differentiation

 #include<stdio.h>  
 #include<math.h>  
 float funct(float,float);  
 void main()  
 {  
      float y0,yprime;  
      float h,x,iter,x0;  
      printf("\n\t\t\tEuler's Method To Solve Differential Equation");  
      printf("\n=================================================================================================================\n");  
      printf("\t\t\tEnter the value of h(the interval) ");  
      scanf("%f",&h);  
      printf("\n=================================================================================================================\n");  
      printf("\t\t\tEnter the value of X(for which you need value of y) ");  
      scanf("%f",&x);  
      printf("\n=================================================================================================================\n");  
      printf("\t\t\tEnter the intital value y0 ");  
      scanf("%f",&y0);  
      printf("\n=================================================================================================================\n");  
      printf("\t\t\tEnter the intital value x0 ");  
      scanf("%f",&x0);  
      for(iter=x0;iter<=x;iter=iter + h)  
      {  
           yprime=y0+(h*funct(iter,y0));  
           printf("\nWhen X=%f then Y=%f",iter,y0);  
           y0=yprime;  
      }  
      getchar();  
 }  
 float funct(float x,float y)  
 {  
      return ((x-y)/(x+y));  
 }  


2 comments: