Tuesday 20 September 2011

Euler Method


/* This program finds solution of differential equation by Euler method*/

#include<stdio.h>
#include<math.h>

float fun(float x, float y)
{
  float f;
  f = x*x +y;
  return(f);
 }

void main()
{
  int i,n;
  float x0,y0,x,h;
  printf(“Type n\n”);
  scanf(“%d”,&n);
  printf(“Type x0 and y0\n”);
  scanf(“%f%f”,&x0,&y0);
  printf(“Type x\n”);
  scanf(“%d”,&x);
  h= (x-x0)/n;
  for(i=0; i<=n; i++)
  {
   y0+=fun(x0,y0)*h;
   x0+=h;
   }
   printf(“The required value= %8.4f\n”,y0);
   getch();
   }

No comments:

Post a Comment