Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB HELP Using the X and Y values below, write a MATLAB function SECOND_DERIV

ID: 3607152 • Letter: M

Question

MATLAB HELP

Using the X and Y values below, write a MATLAB function SECOND_DERIV in MATLAB. The output of the function should be the approximate value for the second derivative of the data at x, the input variable of the function.
Use the forward difference method and interpolate to get your final answer.
X=[1,1.2,1.44,1.73,2.07,2.49,2.99,3.58,4.3,5.16,6.19,7.43,8.92,10.7,12.84,15.41,18.49];
Y=[18.89,19.25,19.83,20.71,21.96,23.6,25.56,27.52,28.67,27.2,19.38,-2.05,-50.9,-152.82,-354.73,-741.48,-1465.11];

Thank you.

Explanation / Answer

clc clear all close all %% x=linspace(a); F=Fun(x); h=x(2)-x(1); xCentral=x(2:end-1); dFCenteral=(F(3:end)-F(1:end-2))/(2*h); xForward=x(1:end-1); dFForward=(F(2:end)-F(1:end-1))/h; xBackward=x(2:end); dFBackward=(F(2:end)-F(1:end-1))/h; %% ForwardError1 = (f1 - dy(x1))/dy(x1); ForwardError2 = (f2 - ddy(x1))/ddy(x1); plot(x,dFun(x)); hold on plot(xCentral,dFCenteral,'r') plot(xForward,dFForward,'k'); plot(xBackward,dFBackward,'g'); legend('Analytic','Central','Forward','Backward')