/*Euler method */
# include <stdio.h>
# include <conio.h>
void main()
{
 int c=0;
 float x,y,xp,h,dy,i,n;
 float f(float,float);
 clrscr();
 printf("Solution by Euler Method\n");
 printf("Enter initial Boundry condition x,y : ");
 scanf("%f%f",&x,&y);
 printf("Enter Value of X at which Y is required : ");
 scanf("%f",&xp);
 printf("Enter Interval ,h : ");
 scanf("%f",&h);
 printf(" No. \t  X\t      f(x,y) \t      Y\n");
 printf("----------------------------------------------------------\n");
 for(i=x;i<=xp;i=i+h)
 {
  c++;
  n=y+h*f(i,y);
  printf("%2d\t %2.3f\t      %5.5f\t   %5.6f\n",c,i,f(i,y),n);
  y=n;
 }
 printf("----------------------------------------------------------\n");
 printf("Value of y @ %f is %f",xp,n);
getch();
}
float f(float x,float y)
{
 return (y-x)/(y+x);
}
OUTPUT
Solution by Euler Method
Enter initial Boundry condition x,y : 1 2
Enter Value of X at which Y is required : 2
Enter Interval ,h : .25
 No.      X           f(x,y)          Y
----------------------------------------------------------
 1       1.000        0.33333      2.083333
 2       1.250        0.25000      2.145833
 3       1.500        0.17714      2.190119
 4       1.750        0.11170      2.218045
 5       2.000        0.05169      2.230968
----------------------------------------------------------
Value of y @ 2.000000 is 2.230968
 
No comments:
Post a Comment