Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write 1. a MATLAB function to calculate the coefficients of Hermite interpolating polynomial, H (using divided difference) 2. a MATLAB function to evaluate the Hermite

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Write 1. a MATLAB function to calculate the coefficients of Hermite interpolating polynomial, H (using divided difference) 2. a MATLAB function to evaluate the Hermite interpolating polynomial. 3. a MATLAB script to compare the error of using Hermite polynomial which fits the data at x = 0, 0.5, 1to approximate the function et at x = 0.3, 0.7, 0.9 and plot a graph of the exact function et and the Hermite polynomial H First function: Input: x, y, dy where x is a vector consisting of Ci, y is a vector consisting of f(xi), dy is a vector consisting of f'(x;), Output: c where cis a vector consisting of the coefficients of the Hermite Polynomial, that is, H(x) = C1 + c2(x 21)+c2(x 21)2 + ... + C2n+2 -1(x zi). where 2211 = Z2i = b;, for i = 1,...,n. function (c] = Divided_difference_Hermite_NetID(x,y,dy) %% Step 1: F= zeros(2n,2n); F(1:2:end, 1) = y; F(2:2:end, 1) = y; F(2:2:end 2) = dy; z = zeros(2*n, 1); z(1:2:end) = x; z(2:2:end) = x; %% Step 2: for j= 1,..., n-1 F(2*j+1,2) = (F(2*j+1,1)-F(2*),1))/(2(2*j+1)-z(2*)); %% Step 3: for i= 3,..., 2n for j = 1, ..., 1-1 (Using the Divided_differences to calculate the coefficient) %% Step 4: set c= diag(F); end Second function: Input: c, x, X, where cis a vector consisting of the coefficients of the Hermite Polynomial and x is a vector consisting of tj. Output: HX which is the function value of H at point X function (HX] = Hermite_polynomial_NetID(0.x,x) %% Step 1: PX = c(1); S = 1; z = zeros(2*n,1); z(1:2:end) = x; z(2:2:end) = x; %% Step 2: for i = 2,3..., 2*n S = S*(X-z(i-1)) PX = PX+c(i)*s; end Main script: %% Step 1: define the function f and f' f = @(x) exp(x); df = @(x) exp(x); %% Step 2: define the vector x %%% type your code here %% Step 3: define the test points X %%% type your code here %% Step 4: calculate the vectory and dy y=f(x); dy = df(x); %% Step 5: calculate the coefficients of the Hermite Polynomial %%% type your code here %% Step 6: evaluate the polynomial and the function at X %%% type your code here %% Step 7: compute the error %%% type your code here %% Step 8: plot the graph N = 100; HX = zeros(N+1,1); Xplot = (0:1/N:1)'; for i = 1:N+1 HX(i)= Hermite_polynomial_NetID(c.x,X_plot(i)); end plot(X_plot,HX-) hold on plot(X_plot,f(X_plot)'r-") Assuming the main script is saved as "main_NetID.m". We can use the following Matlab comment to check your code: Command Output x = (-1,0.1); y = (-1,0,1)'; dy = [3,0,3); c = Divided_difference_Hermite_NetID(x,y,dy) X = 1/2; HX = HX = Hermite_polynomial_NetID(cx,x) 0.1250 error = 1.0e-05* main_NetID 0.3962 0.4195 0.3174 Write 1. a MATLAB function to calculate the coefficients of Hermite interpolating polynomial, H (using divided difference) 2. a MATLAB function to evaluate the Hermite interpolating polynomial. 3. a MATLAB script to compare the error of using Hermite polynomial which fits the data at x = 0, 0.5, 1to approximate the function et at x = 0.3, 0.7, 0.9 and plot a graph of the exact function et and the Hermite polynomial H First function: Input: x, y, dy where x is a vector consisting of Ci, y is a vector consisting of f(xi), dy is a vector consisting of f'(x;), Output: c where cis a vector consisting of the coefficients of the Hermite Polynomial, that is, H(x) = C1 + c2(x 21)+c2(x 21)2 + ... + C2n+2 -1(x zi). where 2211 = Z2i = b;, for i = 1,...,n. function (c] = Divided_difference_Hermite_NetID(x,y,dy) %% Step 1: F= zeros(2n,2n); F(1:2:end, 1) = y; F(2:2:end, 1) = y; F(2:2:end 2) = dy; z = zeros(2*n, 1); z(1:2:end) = x; z(2:2:end) = x; %% Step 2: for j= 1,..., n-1 F(2*j+1,2) = (F(2*j+1,1)-F(2*),1))/(2(2*j+1)-z(2*)); %% Step 3: for i= 3,..., 2n for j = 1, ..., 1-1 (Using the Divided_differences to calculate the coefficient) %% Step 4: set c= diag(F); end Second function: Input: c, x, X, where cis a vector consisting of the coefficients of the Hermite Polynomial and x is a vector consisting of tj. Output: HX which is the function value of H at point X function (HX] = Hermite_polynomial_NetID(0.x,x) %% Step 1: PX = c(1); S = 1; z = zeros(2*n,1); z(1:2:end) = x; z(2:2:end) = x; %% Step 2: for i = 2,3..., 2*n S = S*(X-z(i-1)) PX = PX+c(i)*s; end Main script: %% Step 1: define the function f and f' f = @(x) exp(x); df = @(x) exp(x); %% Step 2: define the vector x %%% type your code here %% Step 3: define the test points X %%% type your code here %% Step 4: calculate the vectory and dy y=f(x); dy = df(x); %% Step 5: calculate the coefficients of the Hermite Polynomial %%% type your code here %% Step 6: evaluate the polynomial and the function at X %%% type your code here %% Step 7: compute the error %%% type your code here %% Step 8: plot the graph N = 100; HX = zeros(N+1,1); Xplot = (0:1/N:1)'; for i = 1:N+1 HX(i)= Hermite_polynomial_NetID(c.x,X_plot(i)); end plot(X_plot,HX-) hold on plot(X_plot,f(X_plot)'r-") Assuming the main script is saved as "main_NetID.m". We can use the following Matlab comment to check your code: Command Output x = (-1,0.1); y = (-1,0,1)'; dy = [3,0,3); c = Divided_difference_Hermite_NetID(x,y,dy) X = 1/2; HX = HX = Hermite_polynomial_NetID(cx,x) 0.1250 error = 1.0e-05* main_NetID 0.3962 0.4195 0.3174

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

Logistics Lifeline Supply Chain Strategies

Authors: Ehsan Sheroy

1st Edition

7419377502, 978-7419377503

More Books

Students also viewed these Databases questions

Question

Evaluating Group Performance?

Answered: 1 week ago