For medical purposes the level of sugar was measured in blood (in mg/dl). The sa
ID: 3572255 • Letter: F
Question
For medical purposes the level of sugar was measured in blood (in mg/dl). The samples were taken with 1/2 hr increments, as the following table shows: initial sample 96 mg/dl after 30 min.133 mg/dl after 60 min. 142 mg/dl after 90 min. 81 mg/dl after 120 min. 87 mg/dl Graph in MATLAB sugar curves corresponding to these data; By using piecewise linear function. By using the Lagrange interpolating polynomial (clearly state the degree of this polynomial). By using any interpolating polynomial. How would a typical polynomial of this type look like? Before producing any graph, show the procedures for obtaining such required functions. Be as specific as possible. Download the handout Lagrange interpolating polynomials distributed in class from the Blackboard.Explanation / Answer
%piecewise linear function
time = [0 30 60 90 120];
sample = [96 133 142 81 87];
%plot(time,sample);
%lagrange
f = [];
x = time(1):1:time(end);
m = length(time);
L = ones(m, length(x));
for k=1:m %the rows, i.e L1,L2, L3, L4....
for i=1:m %the columns L11, L12, L13....L17
if (k~=i) % if k not equal to i
L(k,:)=L(k,:).*((x-time(i))/(time(k)-time(i)));
end
end
end
y=0; % Using L polynomials to calculate the interpolating function.
for k=1:m
f=sample(k).*L(k,:);
y=y+f
end
plot(x, y);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.