NEWTON'S BACKWORD INTERPOLATION

If you have any queries please leave a message here
Your Message
×



USING ARRAY

#include<stdio.h>
void main()
{
float x[20],fx[20][20],xvalue,h,q,temp,ans;
int n,i,j,fact;
printf("\n Enter the value of x to find f(x)...");
scanf("%f",&xvalue);
printf("\n Enter the number of values you want to insert...");
scanf("%d",&n);

//Input observation table
for(i=0;i<n;i++)
{
printf("\n Enter the value of x...");
scanf("%f",&x[i]);
printf("\n Enter the value of f(x)...");
scanf("%f",&fx[i][0]);
}

//Calculate the value of q
h=x[1]-x[0];
q=(xvalue-x[n-1])/h;

//Calculate the value of ∆xi , ∆2xi , ∆3xi , . . . (where i = 1, 2, 3, . . . )
for(i=1;i<n;i++)
{
for(j=0;j<n-i;j++)
{
fx[j][i]=fx[j+1][i-1]-fx[j][i-1];
}
}

//Print the value of ∆xi , ∆2xi , ∆3xi , . . . table
for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<n-i;j++)
{
printf("%f ",fx[i][j]);
}
}

//Find f(x) using Newton's Backword Interpolation Method
ans=fx[n-1][0];
for(i=1;i<n;i++)
{

//Calculate q , q(q + 1) , q(q + 1)(q + 2) , . . .
temp=q;
for(j=1;j<i;j++)
{
temp=temp*(q+j);
}

//Factorial calculation
fact=1;
for(j=1;j<=i;j++)
{
fact=fact*j;
}
ans=ans+((temp/fact)*fx[n-i-1][i]);
}
printf("\n f(x) = %f",ans);
}


USING POINTER

#include<stdio.h>
void main()
{
float *x,*fx,xvalue,h,q,temp,ans;
int n,i,j,fact;
printf("\n Enter the value of x to find f(x)...");
scanf("%f",&xvalue);
printf("\n Enter the number of observation you want to insert...");
scanf("%d",&n);

//Dynamic memory allocation
x=(float *)malloc(n * sizeof(float));
fx=(float *)malloc(n * n * sizeof(float));

//Input observation table
for(i=0;i<n;i++)
{
printf("\n Enter the value of x...");
scanf("%f",(x + i));
printf("\n Enter the value of f(x)...");
scanf("%f",(fx + i*n));
}

//Calculate the value of q
h = *(x + 1) - *(x + 0);
q = (xvalue - *(x + (n-1))) / h;

//Calculate the value of ∆xi , ∆2xi , ∆3xi , . . . (where i = 1, 2, 3, . . . )
for(i=1;i<n;i++)
{
for(j=0;j<n-i;j++)
{
*(fx + j*n + i)=*(fx + (j+1)*n + (i-1)) - *(fx + j*n + (i-1));
}
}

//Print the value of ∆xi , ∆2xi , ∆3xi , . . . table
for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<n-i;j++)
{
printf("%f ",*(fx + i*n + j));
}
}

//Find f(x) using Newton's Backword Interpolation Method
ans = *(fx + (n-1)*n);
for(i=1;i<n;i++)
{

//Calculate q , q(q + 1) , q(q + 1)(q + 2) , . . .
temp = q;
for(j=1;j<i;j++)
{
temp = temp * (q+j);
}

//Factorial calculation
fact = 1;
for(j=1;j<=i;j++)
{
fact = fact * j;
}
ans = ans + ((temp / fact) * *(fx + (n-i-1)*n + i));
}
printf("\n f(x) = %f",ans);
}



ABOUT US

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.


MORE TOPIC


Windows Command

UNIX Command

IGNOU Assignment Solution

IGNOU Question Paper Solution

Solutions of Different Questions


WHAT WE DO


Website Devlopment

Training

Home Learning

Provide BCA, MCA Projects

Provide Assignment & Question Paper Solution


CONTACT US


Follow Us