Cody

Problem 1017. Lagrange Interpolation

Solution 821397

Submitted on 6 Feb 2016
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Fail
%% Check linear interpolation X = [4800; 5100]; Y = [7.5247; 7.2851]*1e-1; x = 5000; y = Lagrange_Interp(X,Y,x) y_correct = 0.73650; assert(abs(y-y_correct)<1e-4)

[Warning: Polynomial is not unique; degree >= number of data points.] L = 1.0e-03 * -0.0000 0.3795 0 y = 0.7374 y = 0.7374

Assertion failed.

2   Fail
%% Check Lagrange polynomial coefficients X = [4800; 5100]; Y = [7.5247; 7.2851]; x = 5000; y_correct = 7.3650; L_correct = [1, 2]/3; [y,L] = Lagrange_Interp(X,Y,x) assert(abs(y-y_correct)<1e-4) assert(norm(L-L_correct)<1e-3)

[Warning: Polynomial is not unique; degree >= number of data points.] L = -0.0000 0.0038 0 y = 7.3742 y = 7.3742 L = -0.0000 0.0038 0

Assertion failed.

3   Fail
%% Check quadratic interpolation X = [300, 400, 500]; Y = [0.616, 0.525, 0.457]; x = 350; [y,L] = Lagrange_Interp(X,Y,x) y_correct = 0.567625; L_correct = [3, 6, -1]/8; assert(abs(y-y_correct)<1e-4) assert(norm(L-L_correct)<1e-3)

[Warning: Polynomial is not unique; degree >= number of data points.] L = 0.0000 -0.0000 0.0063 0 y = 0.5740 y = 0.5740 L = 0.0000 -0.0000 0.0063 0

Assertion failed.

4   Fail
%% Check quadratic interpolation for log X = [1, 4 6]; Y = log(X); x = 2; [y,L] = Lagrange_Interp(X,Y,x) y_correct = 0.5658; L_correct = [8/15, 2/3, -1/5]; assert(abs(y-y_correct)<1e-4) assert(norm(L-L_correct)<1e-3)

[Warning: Polynomial is not unique; degree >= number of data points.] L = -0.0212 0.1815 0 -0.1603 y = 0.3961 y = 0.3961 L = -0.0212 0.1815 0 -0.1603

Assertion failed.