Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 436081

Submitted on 29 Apr 2014 by Celestino

Correct

104Size
This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%% Check linear interpolation
X = [4800; 5100];
Y = [7.5247; 7.2851]*1e-1;
x = 5000;
y = Newton_Interp(X,Y,x)
y_correct = 0.73650;
assert(abs(y-y_correct)<1e-4)
y =
    0.7365
2
Pass
 
%% Check Newton polynomial coefficients
X = [4800; 5100];
Y = [7.5247; 7.2851];
x = 5000;
y_correct = 7.3650;
b_correct = [7.5247, -0.00079867];
[y,b] = Newton_Interp(X,Y,x)
assert(abs(y-y_correct)<1e-4)
assert(norm(b-b_correct)<1e-3)
y =
    7.3650
b =
    7.5247   -0.0008
3
Pass
 
%% Check quadratic interpolation
X = [300, 400, 500];
Y = [0.616, 0.525, 0.457];
x = 350;
[y,b] = Newton_Interp(X,Y,x)
y_correct = 0.567625;
b_correct = [0.616, -0.00091, 0.00000115];
assert(abs(y-y_correct)<1e-4)
assert(norm(b-b_correct)<1e-3)
y =
    0.5676
b =
    0.6160   -0.0009    0.0000
4
Pass
 
%% Check quadratic interpolation for log
X = [1, 4 6];
Y = log(X);
x = 2;
[y,b] = Newton_Interp(X,Y,x)
y_correct = 0.5658;
b_correct = [0, 0.4620981, -0.0518731];
assert(abs(y-y_correct)<1e-4)
assert(norm(b-b_correct)<1e-3)
y =
    0.5658
b =
         0    0.4621   -0.0519