Question

Please write code in MATLAB. This is an ungraded HW assignment

(5pts). The percentage of light (L) passing through the sea surface that penetrates to specific depths (D) in clean ocean wat

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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:

Piecewise Linear interpolation rte pelted poirts LatD 30m . 60 100 20 40 TU 90 Dim) Spline interpolation data LatD- 30m 100 1

Add a comment
Know the answer?
Add Answer to:
Please write code in MATLAB. This is an ungraded HW assignment (5pts). The percentage of light (L) passing through the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT