Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Numerical MethodsRSS Feeds

FUNCTION TABULATED AT EQUAL INTERVAL USING BACKWARD DIFFERENCE BETWEEN TWO VALUE

Posted By: Audris Schmidt     Category: C Programming     Views: 2653

WRITE A FUNCTION TABULATED AT EQUAL INTERVAL USING BACKWARD DIFFERENCE BETWEEN TWO VALUE.

Code for FUNCTION TABULATED AT EQUAL INTERVAL USING BACKWARD DIFFERENCE BETWEEN TWO VALUE in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
  float x[10],y[10][10],sum,p,u,temp,temp1;
  int i,n,j,k=0,f,m,l=0;
  float fact(int);
  clrscr();
  printf("\nhow many record you will be enter: ");
  scanf("%d",&n);
  for(i=0; i<n; i++)
  {
   printf("\n\nenter the value of x%d: ",i);
   scanf("%f",&x[i]);
   printf("\n\nenter the value of f(x%d): ",i);
   scanf("%f",&y[k][i]);
  }
  printf("\n\nEnter X for finding f(x): ");
  scanf("%f",&p);

  for(i=1;i<n;i++)
  {
    for(j=i;j<n;j++)
    {
     y[i][j]=y[i-1][j]-y[i-1][j-1];
    }
  }
  printf("\n_____________________________________________________\n");
  printf("\n  x(i)\t   y(i)\t    y1(i)    y2(i)    y3(i)    y4(i)");
  printf("\n_____________________________________________________\n");
  for(i=0;i<n;i++)
  {
    printf("\n %.3f",x[i]);
    for(j=0;j<=i;j++)
    {
     printf("   ");
     printf(" %.3f",y[j][i]);
    }
   printf("\n");
  }

  i=0;
  do
  {
   if(x[i]<p && p<x[i+1])
    k=1;
   else
    i++;
  }while(k != 1);
  f=i;
  n=f+1;
  sum=0;
  for(i=1;i<n;i++)
  {
    temp=1,temp1=0;
    for(j=1;j<i;j++)
     {
      if(l==0)
    {
     temp = temp * (u+(u + j));
     l=1;
    }
      else
    {
     temp1 = temp1 + u*(u+j);
     temp = temp * (u+j);
    }
     }
    m=fact(i);
    temp=temp+temp1;
    sum = sum + temp*(y[i][f]/m);
  }
  sum = sum/(x[1]-x[0]);
  printf("\n\n f(%.2f) = %f ",p,sum);
  getch();
}


float fact(int a)
{
  float fac = 1;

  if (a == 0)
   return (1);
  else
   fac = a * fact(a-1);

  return(fac);
}

/*
______________________________________

OUT PUT
______________________________________


how many record you will be enter: 5



enter the value of x0: 2.5


enter the value of f(x0): 9.75


enter the value of x1: 3.0


enter the value of f(x1): 12.45


enter the value of x2: 3.5


enter the value of f(x2): 15.70


enter the value of x3: 4.0


enter the value of f(x3): 19.52


enter the value of x4: 4.5


enter the value of f(x4): 23.75


Enter X for finding f(x): 4.25

_____________________________________________________

x(i) y(i) y1(i) y2(i) y3(i) y4(i)
_____________________________________________________

2.500 9.750

3.000 12.450 2.700

3.500 15.700 3.250 0.550

4.000 19.520 3.820 0.570 0.020

4.500 23.750 4.230 0.410 -0.160 -0.180


f(4.25) = 8.223335

*/
  
Share: 



Audris Schmidt
Audris Schmidt author of FUNCTION TABULATED AT EQUAL INTERVAL USING BACKWARD DIFFERENCE BETWEEN TWO VALUE is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!