In: Computer Science
Clamped Splines Let
t = [1:60]; x = [68 126 86 71 100 177 233 271 206 269 340 269 315 384 431 467 382 440 511 558 565 529 511 551 682 665 642 671 796 774 749 758 796 834 878 896 847 836 872 925 978 981 989 1041 1070 1067 1138 1167 1167 1167 1167 1194 1245 1196 1167 1165 1167 1196 1167 1134]; y =-[238 226 189 238 295 231 184 240 289 235 195 231 295 249 184 189 244 291 246 233 193 193 246 289 115 35 273 298 111 33 44 286 280 242 238 193 191 242 291 271 184 293 233 182 211 289 242 209 80 160 278 298 246 298 275 206 155 153 157 162]; 1. Use cubic splines with clamped conditions to fit the data t and y. 2. Let tt=linspace(t(1),t(end),200); and evaluate the cubic spline at tt and assign the result to a varibale called y1. 3. Find spline (from 1) at 45. Show your MATLAB code and result
ANSWER:
CODE TEXT
% defining variables as provided in question
t = 1:60;
x = [68 126 86 71 100 177 233 271 206 269 340 269 315 384 431 467 382 440 ...
511 558 565 529 511 551 682 665 642 671 796 774 749 758 796 834 878 896 ...
847 836 872 925 978 981 989 1041 1070 1067 1138 1167 1167 1167 1167 ...
1194 1245 1196 1167 1165 1167 1196 1167 1134];
y =-[238 226 189 238 295 231 184 240 289 235 195 231 295 249 184 189 244 ...
291 246 233 193 193 246 289 115 35 273 298 111 33 44 286 280 242 238 ...
193 191 242 291 271 184 293 233 182 211 289 242 209 80 160 278 298 ...
246 298 275 206 155 153 157 162];
% 1. cubic spline with clamped condition, using function csape of matlab
% with end points condition
% fitting on t and y with endpoints condition [1 0]
splineFit = csape(t,y,[1 0]);
% 2. evaluate the cubic spline at tt
tt = linspace(t(1),t(end),200);
% y values for tt
y1 = ppval(splineFit,tt);
% 3. spline at 45
spline45 = y(45);
% displaying result by ploting
plot(t,y,'o',"DisplayName","Data Points");
hold on;
plot(tt,y1,"DisplayName","Cubic Spline");
% ploting point 45
plot(45,spline45,'kx',"MarkerSize",12,"DisplayName","Spline at 45");
legend();
% labelling plot
ylabel("y");
xlabel("t");
title("t vs y");
CODE IMAGE
OUTPUT IMAGE