0
$\begingroup$

I have to solve this numeric problem on octave:

(A) Check the correctness of the Lagrange (or Newton) interpolation method on some functions, of which the analytical formula is known, considering tabulations with 5, 6, 11, 12, 20 , 25 equidistant points. Analyze the error graph. Build the table containing the error rule. Comment on the results.

(B) Check the goodness of the Lagrange interpolation method on them functions analyzed in part (A) considering tabulations with 5, 6, 11, 12, 20, 25 points

calculated with the following formula:

x (i) = cos (((2 * (n-i) +1) * pg) / (2 * (n + 1))), for i = 0,1, ..., n.

(Remember that in the case of intervals [a, b] other than [-1,1] the abscissa of the printout must be obtained with the following formula once the x (i) have been calculated with the previous formula:

t (i) = (b-a) / 2 * x (i) + (b + a) / 2, for i = 0.1, ..., n.)

Note that the overwrite of the vector x can be used.

I have solved the first part(A) in this way and it's correct:

a = -1; 
b =  1;  

function y = rung( x )
    y = 1 ./ ( 1 + 25 * x .^ 2 );
endfunction

%% equispaced points
n = input( 'polynomial degree = ' );

for i = 1 : n - 1
    h  = ( b - a ) / i;
    xi = a : h : b;   % or   xi = linspace( -1, 1, i );
    yi = rung( xi );

    % polynomial interpolator on equispaced nodes
    x     = linspace( a, b, 321 );
    pequi = polyfit( xi, yi, i );
    g     = rung( x );
    yeq   = polyval( pequi, x );

    %plot( xi, yi, 'o', x, yeq, 'b-', x, g, 'r-' );
    %plot(              x ,yeq, 'b-', x, g, 'r-' );

    err3 = ( g - yeq );
    err4 = norm( err3, 2 ); 

    plot( x, yeq, 'b-', x, g, 'm-', x, err3, 'r-' );
endfor

the objective of part b of the exercise is to demonstrate that the error, using the chebychev formula, tends to zero as the degree of the polynomial increases. However, in the first part I used linspace to represent equispaced points; I do not understand how to represent the printouts with the formula:

x (i) = cos (((2 * (n-i) +1) * pg) / (2 * (n + 1))), for i = 0,1, ..., n.

Can you help me? thanks a lot.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.