The task was to take data points, compute a spline of the points, then calculate the first and second derivate of the spline curve. I have found and plotted the curves correctly, but am having trouble with displaying specific values on the derivate curves. How can I input specific x-values in to the first and second derivate curves to give me y-values, then display them?
code:
close all x = linspace(-3, 3, 9); y = [2, 3, 4.1, 4.5, 2, 2, 3, 3, 3];
%x = linspace(0, 4, 6); %y = [2, 1, .4, 0.08, 0, .2];
xx = linspace(-3,4); pp = spline(x,y); yy = ppval(pp, xx); plot(x, y, '.', 'markersize', 10); hold on; plot(xx, yy, 'b');
dpp = fnder(pp); plot(xx,fnval(dpp,xx),'k'); hold on; ddpp=fnder(dpp); plot(xx,fnval(ddpp,xx),'r'); hold on; y_val=fnval(dpp,xx); y2_val=fnval(ddpp,xx); fprintf('At x = %d, f(x) = %.4f, f''(x) = %.4f\n\n',xx,y_val,y2_val)