Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write 1. a MATLAB function to evaluate the Lagrange interpolating polynomial by Neville's method 2. a MATLAB function to calculate the coefficients of Lagrange interpolating

image text in transcribedimage text in transcribedimage text in transcribed

Write 1. a MATLAB function to evaluate the Lagrange interpolating polynomial by Neville's method 2. a MATLAB function to calculate the coefficients of Lagrange interpolating polynomial, Pin Newton's form (using divided difference) 3. a MATLAB function to evaluate the interpolating polynomial in Newton's form. 4. a MATLAB script to compare the computational time of using Neville's method and using Newton's polynomial. First function: Input: x,y,X, where x is a vector consisting of dyis a vector consisting of f(04) Output: PX which is the function value of P at point X function (PX.Q = Neville_method_NetDoxy.X 9696 Step 1: 1:1) = y; n = numel(x): 9696 Step 2: for i= 2.....n forj= 1. .., 1-1 (Using the Neville_method to calculate Q) 9696 Step 4: set PX = Qin.n): end Second function: Input: x, y, where x is a vector consisting of Xiy is a vector consisting of f(x) Output: b where bis a vector consisting of the coefficients of the Newton's Polynomial that is, P(t) = 6, +63(3-1)+...+On+1 -1 (it - i). function [b] = Divided_difference_NetID(x,y) 9696 Step 1: FC:1) =y: 9696 Step 2: for i = 2...n forj = 1.-1 (Using the Divided differences to calculate the coefficient) 9696 Step 4: set b = diag(F): end Third function: Input:b, x, X, where bis a vector consisting of the coefficients of the Newton's Polynomial and x is a vector consisting of Output: PX which is the function value of P at point X function [PX] = Newton_polynomial_NetID[bxX 9696 Step 1:PX = 5(1):S = 1: 9696 Step 2: for i = 2.3....n S=S*(X-x[i-1)) PX = PX + b(i) : Main script (n = 20; m = 1000: x = (0:1:1): f=@ x) exp(x)+x; y = f(x): X = [0:1/m:1)': PX = zeros(m+1.1): PX_N = zeros(m+1.1): tic for i = 1:m+1 PXC) = Neville_method_NetID[xy XO): end t1 = toc error_1 = norm(PX-F(X) [b] = Divided_difference_NetID[xy): for i = 1:m+1 [PX_NO) = Newton_polynomial_NetID(bxX0): end t2 = toc error_2= norm(PX_N-F(X))} Assuming the main script is saved as "main_NetID.m'. We can use the following Matlab comment to check your code: Command Output b= 0.5000 x= [-1.0.1.2]': y = [0,0,1.3]: b = Divided_difference_NetID(x,y) [PXO] = Newton_polynomial_NetID(b.x,1/2) [PX1] = Neville_method_NetID(xy.1/3) PXO = 0.3750 PX1 = 0.2222 0000 0000 1.0000 0.3333 0.22220 3.0000-0.3333 0.2222 0.2222 tia 0.0363 error_1 = 4.3409e-12 main_NetID SIT - 4.0145e-12 (Your Output may not be exactly equal to my Output. You should get a small error and t1 > t2) Write 1. a MATLAB function to evaluate the Lagrange interpolating polynomial by Neville's method 2. a MATLAB function to calculate the coefficients of Lagrange interpolating polynomial, Pin Newton's form (using divided difference) 3. a MATLAB function to evaluate the interpolating polynomial in Newton's form. 4. a MATLAB script to compare the computational time of using Neville's method and using Newton's polynomial. First function: Input: x,y,X, where x is a vector consisting of dyis a vector consisting of f(04) Output: PX which is the function value of P at point X function (PX.Q = Neville_method_NetDoxy.X 9696 Step 1: 1:1) = y; n = numel(x): 9696 Step 2: for i= 2.....n forj= 1. .., 1-1 (Using the Neville_method to calculate Q) 9696 Step 4: set PX = Qin.n): end Second function: Input: x, y, where x is a vector consisting of Xiy is a vector consisting of f(x) Output: b where bis a vector consisting of the coefficients of the Newton's Polynomial that is, P(t) = 6, +63(3-1)+...+On+1 -1 (it - i). function [b] = Divided_difference_NetID(x,y) 9696 Step 1: FC:1) =y: 9696 Step 2: for i = 2...n forj = 1.-1 (Using the Divided differences to calculate the coefficient) 9696 Step 4: set b = diag(F): end Third function: Input:b, x, X, where bis a vector consisting of the coefficients of the Newton's Polynomial and x is a vector consisting of Output: PX which is the function value of P at point X function [PX] = Newton_polynomial_NetID[bxX 9696 Step 1:PX = 5(1):S = 1: 9696 Step 2: for i = 2.3....n S=S*(X-x[i-1)) PX = PX + b(i) : Main script (n = 20; m = 1000: x = (0:1:1): f=@ x) exp(x)+x; y = f(x): X = [0:1/m:1)': PX = zeros(m+1.1): PX_N = zeros(m+1.1): tic for i = 1:m+1 PXC) = Neville_method_NetID[xy XO): end t1 = toc error_1 = norm(PX-F(X) [b] = Divided_difference_NetID[xy): for i = 1:m+1 [PX_NO) = Newton_polynomial_NetID(bxX0): end t2 = toc error_2= norm(PX_N-F(X))} Assuming the main script is saved as "main_NetID.m'. We can use the following Matlab comment to check your code: Command Output b= 0.5000 x= [-1.0.1.2]': y = [0,0,1.3]: b = Divided_difference_NetID(x,y) [PXO] = Newton_polynomial_NetID(b.x,1/2) [PX1] = Neville_method_NetID(xy.1/3) PXO = 0.3750 PX1 = 0.2222 0000 0000 1.0000 0.3333 0.22220 3.0000-0.3333 0.2222 0.2222 tia 0.0363 error_1 = 4.3409e-12 main_NetID SIT - 4.0145e-12 (Your Output may not be exactly equal to my Output. You should get a small error and t1 > t2)

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

Step: 3

blur-text-image

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

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

Students also viewed these Databases questions

Question

List out some inventory management techniques.

Answered: 1 week ago