/*CSEMATTER.BLOGSPOT.IN
PROGRAM TO IMPLEMENT NUMERICAL DIFFERENTIATION*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,i,e,j,k;
float ax[16],ay[16],x,val,diff[16][16],h,xs,res,sum=0.0;
printf("enter the value of n(1 to 6)\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nenter the value of x:\n");
scanf("%f",&ax[i]);
printf("\nenter the value of y:\n");
scanf("%f",&ay[i]);
}
for(j=0;j<n;j++)
{
for(i=0;i<n;i++)
{
if(j==0)
diff[i][j]=ay[i];
else if(diff[i+1][j-1]!=NULL)
diff[i][j]=diff[i+1][j-1]-diff[i][j-1];
}
}
printf("\n enter the value of x to find corresponding y:\n");
scanf("%f",&val);
for(i=0;i<n;i++)
{
if(ax[i]>val)
{
break;
}
k=i;
}
h=ax[1]-ax[0];
for(e=0;e<n-1;e++)
{sum=sum + ((pow(-1,e))*(diff[k][e+1]))/(e+1);
res=sum/h;}
printf("the result is %f",res);
}
/*
OUTPUT:
enter the value of n(1 to 6)
5
enter the value of x: 0
enter the value of y: 0
enter the value of x: 5
enter the value of y: 3
enter the value of x: 10
enter the value of y: 14
enter the value of x: 15
enter the value of y: 69
enter the value of x: 20
enter the value of y: 228
enter the value of x to find corresponding y: 0
the result is 1.000000
PROGRAM TO IMPLEMENT NUMERICAL DIFFERENTIATION*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,i,e,j,k;
float ax[16],ay[16],x,val,diff[16][16],h,xs,res,sum=0.0;
printf("enter the value of n(1 to 6)\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nenter the value of x:\n");
scanf("%f",&ax[i]);
printf("\nenter the value of y:\n");
scanf("%f",&ay[i]);
}
for(j=0;j<n;j++)
{
for(i=0;i<n;i++)
{
if(j==0)
diff[i][j]=ay[i];
else if(diff[i+1][j-1]!=NULL)
diff[i][j]=diff[i+1][j-1]-diff[i][j-1];
}
}
printf("\n enter the value of x to find corresponding y:\n");
scanf("%f",&val);
for(i=0;i<n;i++)
{
if(ax[i]>val)
{
break;
}
k=i;
}
h=ax[1]-ax[0];
for(e=0;e<n-1;e++)
{sum=sum + ((pow(-1,e))*(diff[k][e+1]))/(e+1);
res=sum/h;}
printf("the result is %f",res);
}
/*
OUTPUT:
enter the value of n(1 to 6)
5
enter the value of x: 0
enter the value of y: 0
enter the value of x: 5
enter the value of y: 3
enter the value of x: 10
enter the value of y: 14
enter the value of x: 15
enter the value of y: 69
enter the value of x: 20
enter the value of y: 228
enter the value of x to find corresponding y: 0
the result is 1.000000
No comments:
Post a Comment