Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1 Write a function Lagrange.interp.m that computes the Lagrangian interpolant of a given set of data points (ri. y) i1, 2, The function should

image text in transcribed

Exercise 1 Write a function Lagrange.interp.m that computes the Lagrangian interpolant of a given set of data points (ri. y) i1, 2, The function should be of the form function [y] = Lagrange.nterp(x1.yi.x) Input xi: vector of interpolation nodes yi: vector of data points at interpolation nodes x: vector of points at which we evaluate the polynomial interpolant Output y: polynomial interpolant evaluated at z Hint Compare the output of your function with the output of the Matlab/Octave built-in function y-polyval (polyfit(xi,yi,length(xi)-1),x) (see the Matlab/Octave documentation Exercise 2 Consider the nonlinar function f(z) = 1 + 2 [-1.1]. By using the Matlab function you coded in Exercise 1, determine the Lagrangian interpolant of f, ie, the polynomial lly/(z) that interpolates the set of data { ./(zi),-0-N in the following 1. Evenly-spaced grid with N+1 points N, j=0, .., N 2. Unevenly-spaced grid with N +1 points (Chebyshev-Gauss-Lobatto points) Fj=cos (Nj), j=0.1 , N In particular, write a Matlab function toat Lagrango.interpolation.n function x,,P1,P2,P3,P4]-tost Lagrango.intorpolationO that returns the follwing items: x: vector of 1000 evenly-spaced nodes in [-1,1] (use the connmand x-linspace (-1, 1,1000). t: vector representin(1) evaluated at x. P1: Lagrangian interpolant of (1) blit on the grid (2) with N = 8 nodes and evaluated at x. P2: Lagrangian interpolant of (1) blit on the grid (2) with N = 20 nodes and evaluated at x. P1: Lagrangian interpolant of (1) blilt on the grid (3) with N = 8 nodes and evaluated at x P1: Lagrangian interpolant of (1) blilt on the grid (3) with N = 20 nodes and evaluated at x The function should also plot () (in bl) and the Lagrangian interpolants (in red) obtained by using both the evenly-spaced and the unevenly-spaced grids for the cases N = 8 and N = 20 (4 different figures). Each figure should includehe graph of f(), the data oints (r, f() and the interpolant IINf(r) through those points. Hint: See the code uploaded in CANVAS for examples of similar plots

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Make A Database In Historical Studies

Authors: Tiago Luis Gil

1st Edition

3030782409, 978-3030782405

More Books

Students also viewed these Databases questions