/*CSEMATTER.BLOGSPOT.IN
PROGRAM TO IMPLEMENT GAUSS BACKWARD METHOD*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,k;
float ax[6],ay[6],x,val,diff[6][6],h,xs,p,res,y1,y2,y3,y4,y5;
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("\nenter the value of x to find corresponding y:\n");
scanf("%f",&val);
for(i=0;i<n;i++)
{if(ax[i]>val)
{break;}
xs=ax[i];
k=i; }
h=ax[1]-ax[0];
p=(val-xs)/h;
y1=p*diff[i][1];
y2=(p*(p+1)*diff[i-1][2]);
y3=((p-1)*p*(p+1)*diff[i-2][3]);
y4=((p-1)*p*(p+1)*(p+2)*diff[i-3][4]);
y5=((p-2)*(p-1)*p*(p+1)*(p+2));
res=ay[k]+y1+y2+y3+y4+y5;
printf("the result is %f",res);
}
/*OUTPUT
enter the value of n(1 to 6)
6
enter the value of x: 1939
enter the value of y: 12
enter the value of x: 1949
enter the value of y: 15
enter the value of x: 1959
enter the value of y: 20
enter the value of x: 1969
enter the value of y: 27
enter the value of x: 1979
enter the value of y: 39
enter the value of x: 1989
enter the value of y: 53
enter the value of x to find corresponding y: 30
the result is 32.532318
PROGRAM TO IMPLEMENT GAUSS BACKWARD METHOD*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,k;
float ax[6],ay[6],x,val,diff[6][6],h,xs,p,res,y1,y2,y3,y4,y5;
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("\nenter the value of x to find corresponding y:\n");
scanf("%f",&val);
for(i=0;i<n;i++)
{if(ax[i]>val)
{break;}
xs=ax[i];
k=i; }
h=ax[1]-ax[0];
p=(val-xs)/h;
y1=p*diff[i][1];
y2=(p*(p+1)*diff[i-1][2]);
y3=((p-1)*p*(p+1)*diff[i-2][3]);
y4=((p-1)*p*(p+1)*(p+2)*diff[i-3][4]);
y5=((p-2)*(p-1)*p*(p+1)*(p+2));
res=ay[k]+y1+y2+y3+y4+y5;
printf("the result is %f",res);
}
/*OUTPUT
enter the value of n(1 to 6)
6
enter the value of x: 1939
enter the value of y: 12
enter the value of x: 1949
enter the value of y: 15
enter the value of x: 1959
enter the value of y: 20
enter the value of x: 1969
enter the value of y: 27
enter the value of x: 1979
enter the value of y: 39
enter the value of x: 1989
enter the value of y: 53
enter the value of x to find corresponding y: 30
the result is 32.532318
No comments:
Post a Comment