Taylor’s Series

Taylor’s Series

#include<stdio.h>
#include<conio.h>
#define Y1 x*x+y*y
#define Y2 2*x+2*y*(x*x+y*y)
#define Y3 2+2*(x*x+y*y)*(x*x+y*y)+2*y*(2*x+2*y*(x*x+y*y))
#define Y4 6*(x*x+y*y)*(2*x+2*y*(x*x+y*y))+2*y*(2+2*(x*x+y*y)*(x*x+y*y)+2*y*(2*x+2*y*(x*x+y*y)))
int main (void)
{
	float h,a,b,c=0,n,i,ya,yb,yc,yd,x,y;
   clrscr();
   printf("Enter the valu of a & b as Y(a)=b: ");
   scanf("%f%f",&a,&b);
   printf("Enter the value of h: ");
   scanf("%f",&h);
   printf("Enter the value of x: ");
   scanf("%f",&n);
   x=a;
   y=b;
   for(i=a;i<n;i=i+h)
   {
   	ya=Y1;      printf("\n\t%f",ya);
      yb=Y2;      printf("\n\t%f\t%f\t%f\t%f",Y1,y,x,yb);
      yc=Y3;      printf("\n\t%f\t%f\t%f\t%f",Y2,y,x,yc);
      yd=Y4;      printf("\n\t%f",yd);
      y=y+ya*h+(yb*h*h)/2+(yc*h*h*h)/6+(yd*h*h*h*h)/24;
      x=x+h;
      c++;
      printf("\n\t\t%f",y);
   }
   printf("\nItaration no. %f\nRequired ans: %f",c,y);
   getch();
   return 0;
}

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *