Logo 
Search:

C Programming Articles

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

FUNCTION TABULATED AT UNEQUAL INTERVAL

Posted By: Katie Brown     Category: C Programming     Views: 4103

WRITE A FUNCTION TABULATED AT UNEQVAL INTERVAL.

Code for FUNCTION TABULATED AT UNEQUAL INTERVAL 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,l=0;
  int i,n,j,k=0,f,m;
  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++)
  {
    k=i;
    for(j=0;j<n-i;j++)
    {
     y[i][j]=(y[i-1][j+1]-y[i-1][j])/(x[k]-x[j]);
     k++;
    }
  }
  printf("\n_______________________________________________________\n");
  printf("\n  x(i)\t    y(i)     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<n-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=n-f;
  sum=0;
  for(i=1;i<n;i++)
  {
   k=f;
   temp=1,temp1=0;
   for(j=1;j<=i && l==1;j++)
    {
     temp1 = temp1 + (p - x[k]);
     temp=temp1;
     k++;
   }
    l=1;
    printf("\n%.3f",y[i][f]);
    sum = sum + temp*(y[i][f]);
  }
  printf("\n\n f(%.2f) = %f ",p,sum);
  getch();
}


/*
______________________________________

OUT PUT
______________________________________


how many record you will be enter: 5


enter the value of x0: 10


enter the value of f(x0): 12


enter the value of x1: 12


enter the value of f(x1): 15


enter the value of x2: 16


enter the value of f(x2): 20


enter the value of x3: 17


enter the value of f(x3): 22


enter the value of x4: 22


enter the value of f(x4): 32


Enter X for finding f(x): 14

_______________________________________________________

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

10.000 12.000 1.500 -0.042 0.027 -0.004

12.000 15.000 1.250 0.150 -0.015

16.000 20.000 2.000 0.000

17.000 22.000 2.000

22.000 32.000

f(14.00) = 1.295000

*/
  
Share: 


Didn't find what you were looking for? Find more on FUNCTION TABULATED AT UNEQUAL INTERVAL Or get search suggestion and latest updates.

Katie Brown
Katie Brown author of FUNCTION TABULATED AT UNEQUAL INTERVAL is from London, United Kingdom.
 
View All Articles

 
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!