Skip to main content
Home
Live to Learn!

Main navigation

  • Home
  • Learn
    • FoxPro
    • MS-DOS
    • C PRG
    • Java
    • ASP
    • Ruby on Rails
    • ASP.NET
    • E-Books
    • Exam Preparation
    • Tools
  • Blog
  • Forums
  • Contact
User account menu
  • Log in

Breadcrumb

  1. Home
  2. C Programming

Lagrange's Interpolation

Book navigation

  • C Programming Introduction
  • C – Program Code – Basics Part I
  • C – Program Code – Basics Part II
  • Operators in C Programming
  • C – Program Code – Basics Part III
  • C Program Code Basics - Part IV
  • Addition , Subtraction and Multiplication of Matrices
  • Solving Quadratic Equation
  • Sum of sin series
  • Sum of cos series
  • Sum of e series
  • Ascending and Descending order
  • Sorting in Alphabetical Order
  • Factorial of a number
  • Fibonacci Series
  • String Counting
  • String Manipulation
  • Bisection Method
  • Newton Raphson Method
  • Lagrange's Interpolation
By Karthikeyan , 8 September, 2009

Sample C Program that uses Lagrange's interpolation formulae in mathematics


#include 
#include 
line()
{
	int i;
	printf("\n");
	for(i=0; i<60; i++)
	printf("*");
}
main()
{
	float x[100], f[100], xin, sum, prod;
	int i, n, j;
	printf("\n\t Lagrange's Interpolation ");
	printf("\n\t *************************");
	printf("\n\t Enter the values of xin[f(x)], n [No. of pairs]:\n");
	scanf("%f%d", &xin, &n);
	printf("\t\t xin=%f\t\t n=%d\t\t", xin, n);
	printf("\nEnter the x, y values [pairs]\n");
	for(i=1; i<=n; i++)
	{
	   scanf("%f%f", &x[i], &f[i]);
    }
    line();
    printf("\n\t\t x[i]\t\t\tf[i]\n");
    line();
	for(i=1; i<=n; i++)
	{
		printf("\n\t\t%f\t\t\t%f\n", x[i], f[i]);
	}
	sum = 0.0;
	for(i=1; i<=n; i++)
	{
		prod = 1.0;
		for(j=1; j<=n; j++)
		{
			if(j != i)
			{
			prod = prod*(xin - x[j]) / (x[i] - x[j]);
			}
		}
		sum = sum + prod*f[i];
	}
	line();
	printf("\n\n\t\t\t sum = %10.4f\n", sum);
	line();
}

Comments

Featured Blog Posts

Convert Currency in Number to Words (Indian Rupees) - MS Excel
Foxpro Tutorial and Programs
Convert Currency in Number to Words in MS Word
Convert Currency in Number to Words (Indian Rupees) - Version 2
Best way to Use Rupee Symbol in Windows – Easy steps
Convert Currency in Number to Words - MS Access
Creating All in One Windows XP DVD with all Important Applications
RSS feed

© 2009-2025 Live to Learn.In

Terms of Use | Privacy Policy