Code for Modified Euler’s method in C

C code to implement  modified Euler’s  method  .  Compiled in DEV C++

website_caption1

#include<stdio.h>
#include <math.h>
#include<conio.h>
#define F(x,y)  (x)*(x)+(y)
int main()
{
  double y0,x0,y1,x1,y1_0,a,n,h,f,f1;
  int j,count,flag;

  printf("\nEnter the value of x0: ");
  scanf("%lf",&x0);
  printf("\nEnter the value of y0: ");
  scanf("%lf",&y0);
  printf("\nEnter the value of h: ");
  scanf("%lf",&h);
  printf("\nEnter the value of last point: ");
  scanf("%lf",&n);
  for(x1=x0+h,j=1; x1<=n+h; x1=x1+h,j++)
  {
    count=0;
    flag=0;
    f=F(x0,y0);
    y1_0 = y0 + (h * f);
    printf("\n\n * * y%d_0 = %.3lf * *",j,y1_0);
     do
      {
    count++;
    f=F(x0,y0);
    f1=F(x1,y1_0);
    y1 = y0 + h/2 * ( f + f1);
    printf("\n\n * * x = %.3lf => y%d_%d = %.3lf * *",x1,j,count,y1);
    if(fabs(y1-y1_0)<0.00001)
     {
      printf("\n\n\n\n * * * * y%d = %.3lf * * * *\n\n",j,y1);
      flag=1;
     }
    else
      y1_0 = y1;
      }while(flag!=1);
    y0 = y1;
  }
getch();
}

website_caption1

You might be also interested in :

Advertisements

Code for Newton’s forward interpolation in C

C code to implement Newton’s forward interpolation .  Compiled in DEV C++

website_caption1

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
main()
{
  float x[20],y[20],f,s,h,d,p;
  int j,i,n;
  printf("enter the value of n :");
  scanf("%d",&n);
  printf("enter the elements of x:");
  for(i=1;i<=n;i++)
   {
        scanf("%f",&x[i]);
         }
                   printf("enter the elements of y:");
               for(i=1;i<=n;i++)
               {
              scanf("%f",&y[i]);                  
                                }
  h=x[2]-x[1];
  printf("Enter the value of f:");
  scanf("%f",&f);
s=(f-x[1])/h;
p=1;
d=y[1];                                  
for(i=1;i<=(n-1);i++)
 {
                   for(j=1;j<=(n-i);j++)
                    {
                          y[j]=y[j+1]-y[j];
                            
                    }
                    p=p*(s-i+1)/i;
                    d=d+p*y[1];
 }                         
printf("For the value of x=%6.5f THe value is %6.5f",f,d);
 getch();
}

 website_caption1

You might be also interested in :