Question: = In the main script file, given a set of data point x = [x_1,x_2...X_n] and y = [f(x_1),f(x_2),...,f(x_n)] and dy = [df(x_1),df(x_2),...,df(x_n)], we would

![point x = [x_1,x_2...X_n] and y = [f(x_1),f(x_2),...,f(x_n)] and dy = [df(x_1),df(x_2),...,df(x_n)],](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f5178eb2279_38266f5178e27b67.jpg)


= In the main script file, given a set of data point x = [x_1,x_2...X_n] and y = [f(x_1),f(x_2),...,f(x_n)] and dy = [df(x_1),df(x_2),...,df(x_n)], we would like to evaluate Hermite polynomial which fit the data. We then plot the interpolating polynomial and plot average 12 error at the points of evaluation with an increasing number of data points. Template of the script file clear close all syms f_sym(x); % initialize a symbolic function m = 100; % number of evaluation points f_sym(x) = sin(pi*x)+exp(x.^2+2); % define the symbolic function df_sym(x) = diff(f_sym); % compute the derivative of the symbolic function f = @(x) double(f_sym(x)); % change the function f_sym to a double value function df = @(x) double(df_sym(x)); % change the function df_sym to a double value function z = 0:2/(m-1):2; % x location of evaluation points Hz = zeros(size(z)); % initialize Hz (which is the vector of H(z)) = figure(1); hold on i = 1; % initialize the counter of the for-loop for n = [2,4,8,16] % using increasing number of data points x = 0:2/(n-1):2; % x location of data points y = f(x); % f(x) values dy = df(x); % f(x) values = %% compute the coefficient of Hermite polynomial by divided difference b = ... %% evaluate H(z), the polynomial at z ... Hz(j) = .. = ... %% compute the abs error of the interpolation at z figure(1);plot(z, Hz,.-') error(i)= norm(Hz-f(z))/sqrt(m); i = i+1; end figure(1);plot(z,f(z);.,Markersize, 10) legend('n=2',n=4';n=8,n=16,'exact function, Location, 'northwest'); figure(2); plot([2,4,8,16].*log([2,4,8,16]),log(error)) The first Matlab function is used to evaluate the coefficient of the Hermite polynomial by divided_difference Input: x, y, dy, % ((x,y) are the vectors of data points (x_i,f(x_i))) Output: b %b_i is the i-th coefficient of the Hermite polynomial in Newton form Pseudocode: Step 1: Set n = length(x), = initalize - - F(1:2:end, 1) = y; F(2:2:end, 1) = y; F(2:2:end, 2) = dy; X = zeros(2*n,1); X(1:2:end) = x; X(2:2:end) = x; = = = Step 2: Use a for-loop to calclate the second colmun of F Step 3: Use a for-loop (with a sub-loop) to calclate the F - Step 4: b = diag(F) The second Matlab function is used to evaluate the Newton polynomial with given coefficients b_i where H(2) = b1 + b2 (z x1) + b3 (2 21)2 + b3 (2 x1)(2 22) +... xix z x2. + b2n (z Xn) IT=1 z X1 ) Z =1 Input: b, x, z (b is the coefficients of Newton polynomial, x is the location of the data points and z is the location to evaluate P) Output: Hz % Hz equal to H(z) where H is the Hermite polynomial in Newton form Pseudocode: Step 1: Set n = length(x), initize S = 1; Hz=b(1)*S; = = Step 2: Use a for loop to evaluate the formula of Hermite polynomial in Newton form
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
