Writing a script to plot cubic spline approximations

4 views (last 30 days)
Write a script called inteffect that will plot cubic spline approximations to each set of data. Use the given file quad3 to integrate the data. Your script should produce a figure (use subplot).
Data:
time = [0,10,20,30,40,50,60]
glucose = [102, 114, 122, 132, 115, 107, 100]
insulin = [11,26,36,47,39,27,15]
quad3.m:
function I = quad3(x, f)
%
% I = quad3(x, f);
%
% This function integrates tabular data using cubic splines.
%
% Input: x, f - vectors containing the tabular data
% Output: I - approximation of the integral
%
S = spline(x, f);
N = length(x);
I = 0;
for i = 1:N-1
h = x(i+1) - x(i);
I = I + (h/6)*(f(i) + 4 * ppval(S, (x(i) + x(i+1))/2) + f(i+1));
end
Modify quad3 and write a new function m-file quadp which uses pchip instead of spline. This is an easy modification.
I am not sure how to plot a graph of the data which connects the points using the spline.

Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!