Please write code in MATLAB. This is an ungraded HW assignment
Code:
clear
clc
D = [0 1 2 10 50 100];
L = [100 45 39 22 5 0.5];
Dq = 0:100; % Query points
p1 = interp1(D, L, Dq, 'linear');
p2 = interp1(D, L, Dq, 'spline');
p3 = interp1(D, L, Dq, 'pchip');
L1 = p1(Dq == 30);
L2 = p2(Dq == 30);
L3 = p3(Dq == 30);
figure('Renderer', 'painters', 'Position', [10 10 900
700])
subplot(3, 1, 1)
plot(D, L, 'ro');
hold on
plot(Dq, p1, '-.');
plot(Dq(Dq == 30), L1, 'dk');
xlabel('D(m)');
ylabel('L(%)');
title("Piecewise Linear interpolation");
legend('data', 'interpolated points', 'L at D = 30m');
subplot(3, 1, 2)
plot(D, L, 'ro');
hold on
plot(Dq, p2, '-.');
plot(Dq(Dq == 30), L2, 'dk');
xlabel('D(m)');
ylabel('L(%)');
title("Spline interpolation");
legend('data', 'interpolated points', 'L at D = 30m');
subplot(3, 1, 3)
plot(D, L, 'ro');
hold on
plot(Dq, p3, '-.');
plot(Dq(Dq == 30), L3, 'dk');
xlabel('D(m)');
ylabel('L(%)');
title("Cubic Hermite interpolation");
legend('data', 'interpolated points', 'L at D = 30m');
Output:
Please write code in MATLAB. This is an ungraded HW assignment (5pts). The percentage of light (L) passing through the...