Cody

# Problem 1017. Lagrange Interpolation

Solution 344108

Submitted on 1 Nov 2013 by Adam
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   Pass
%% 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)

y = 0.7365 y = 0.7365

2   Pass
%% 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)

y = 7.3650 y = 7.3650 L = 0.3333 0.6667

3   Pass
%% 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)

y = 0.5676 y = 0.5676 L = 0.3750 0.7500 -0.1250

4   Pass
%% 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)

y = 0.5658 y = 0.5658 L = 0.5333 0.6667 -0.2000
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}