Question

In: Computer Science

Make a program for LAGRANGE INTERPOLATION METHOD using C++ program and can be evaluated both polynomial...

Make a program for LAGRANGE INTERPOLATION METHOD using C++ program and can be evaluated both polynomial and Transcendental Functions.

Solutions

Expert Solution

In this C++ program, x and y are two array for storing x data and y data respectively. xp is interpolation point given by user and output of Lagrange interpolation method is obtained in yp.

#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
         float x[100], y[100], xp, yp=0, p;
         int i,j,n;

         /* Input Section */
         cout<<"Enter number of data: ";
         cin>>n;
         cout<<"Enter data:"<< endl;
         for(i=1;i<=n;i++)
         {
                  cout<<"x["<< i<<"] = ";
                  cin>>x[i];
                  cout<<"y["<< i<<"] = ";
                  cin>>y[i];
         }
         cout<<"Enter interpolation point: ";
         cin>>xp;

         /* Implementing Lagrange Interpolation */
         for(i=1;i<=n;i++)
         {
                  p=1;
                  for(j=1;j<=n;j++)
                  {
                           if(i!=j)
                           {
                                p = p* (xp - x[j])/(x[i] - x[j]);
                           }
                  }
                  yp = yp + p * y[i];
         }
         cout<< endl<<"Interpolated value at "<< xp<< " is "<< yp;

         return 0;
}

Related Solutions

Write a computer program using C++ that computes the value of a Lagrange Polynomial and accepts,...
Write a computer program using C++ that computes the value of a Lagrange Polynomial and accepts, as input: (n+1) data points (x0, f(x0)), (x1, f(x1)),...(xn, f(xn)).. at value x, which the polynomial is to evaluated. As output, the program should produce a statement that reads, "f(x) = (the value of f(x))". As a test, use the data values (1,2);(-1,1);(0,0);(2,4);(-2,3)
Find the lagrange polynomials that approximate f(x) = x3 a ) Find the linear interpolation polynomial...
Find the lagrange polynomials that approximate f(x) = x3 a ) Find the linear interpolation polynomial P1(x) using the nodes x0= -1 and x1 = 0 b) Find the quadratic interpolation polynomial P2(x) using the nodes x0= -1 and x1 = 0 and x2 = 1 c) Find the cubic interpolation polynomial P3(x) using the nodes x0= -1 and x1 = 0 and x2 = 1 and x3=2 d) Find the linear interpolation polynomial P1(x) using the nodes x0= 1...
Use Lagrange interpolation to find the polynomial p3(x) of degree 3 or less, that agree with...
Use Lagrange interpolation to find the polynomial p3(x) of degree 3 or less, that agree with the following data: p3(−1) = 3, p3(0) = −4, p3(1) = 5, and p3(2) = −6. Using python to solve
Language: Java Design and implement a program that implements an Interpolation Search method. Interpolation search is...
Language: Java Design and implement a program that implements an Interpolation Search method. Interpolation search is similar to binary search, except it tries to begin the search nearer to the location of the item. Instead of the using the middle value of the sorted array, interpolation search estimates the location of the target with respect to the first & last values in the array. The implementation is the same as binary search except that you should calculate the mid value...
Using the bisection method:     Make a program to use this method using the following three...
Using the bisection method:     Make a program to use this method using the following three functions and use it to find the root of this function f (x) = x * x * x-8. a) A function so that the user between xlower and xupper that meets the value of the function has a different sign and if he does not ask for new values. b) A function to find the root and call it bisection and perform a...
Program in C Make both a SOURCE AND HEADER FILE WITH FUNCTIONS to run the program....
Program in C Make both a SOURCE AND HEADER FILE WITH FUNCTIONS to run the program. Input data from csv file. Two files. grades.c and grades.h Thank you data.csv file Mark Prest,37468,36,113,In Person Andy Joe,6785923,19,98,Online Caden Miller,237741,20,70.1,In Person Luke Jr,2347878,18,45.9,In Online Ally Rogers,8467483,30,89.99,Online Maya Jank,5674930,30,90,In Person Expected output Name: Mark Prest ID: 37468 Age: 36 Grade: 113.00 Attending: In Person Name: Andy Joe ID: 6785923 Age: 19 Grade: 98.00 Attending: Online Name: Caden Miller ID: 237741 Age: 20 Grade: 70.10...
Write the c++ program of Secant Method and Fixed point Method in a one program using...
Write the c++ program of Secant Method and Fixed point Method in a one program using switch condition .Like : cout<<"1.Secant Method \n 2. Fixed point Method\n"<<endl; if press 1 then work Secant Method if press 2 then work Fixed point Method .so please writhe the code in c++ using switch case.and the equation given down consider the equation in the given.Note: Must showt the all the step of output all the iteration step shown in the program .in program...
find Lagrange polynomials that approximate f(x)=x^3, a) find the linear interpolation p1(x) using the nodes X0=-1...
find Lagrange polynomials that approximate f(x)=x^3, a) find the linear interpolation p1(x) using the nodes X0=-1 and X1=0 b) find the quadratic interpolation polynomial p2(x) using the nodes x0=-1,x1=0, x2=1 c) find the cubic interpolation polynomials p3(x) using the nodes x0=-1, x1=0 , x2=1 and x3=2. d) find the linear interpolation polynomial p1(x) using the nodes x0=1 and x1=2 e) find the quadratic interpolation polynomial p2(x) using the nodes x0=0 ,x1=1 and x2=2
The following two investment alternatives are being evaluated using the​ B/C ratio method. The alternatives have...
The following two investment alternatives are being evaluated using the​ B/C ratio method. The alternatives have a​ 5-year service life and the MARR is 18​% per year. Alternative A Alternative B Capital investment ​$10,900    ​$16,000    Annual revenues 4,000   7,500   Annual costs 250   900   Market value at EOY 5 5,000   9,200   Click the icon to view the interest and annuity table for discrete compounding when i equals=18​%per year. Calculate the modified​ B/C ratio of Alternative A A. 1.32 B.1.35 C.1.26 D.0.90...
Using Object Oriented Programming method, make a simple game program with C++. Please include fully explanation/diagram(if...
Using Object Oriented Programming method, make a simple game program with C++. Please include fully explanation/diagram(if any) about which parts implement the object oriented programming.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT