GREETINGS I NEED HELP WITH THIS PROBLEM USING MATLAB THANKS
GREETINGS,
I NEED HELP WITH THIS PROBLEM. USING MATLAB. THANKS
. FOR COMPUTATIONAL METHOD CLASS
Create a MATLAB script to find the first and second derivative of given function using Forward, Backward, central and Taylor numerical schemes. Test your code using the following functions: a. f(x) = xe^x +3x^2 +2x - 1 and find f\'(3) and f\'(3) for with h = 0.1, 0.01 and 0.001 b. Approximate y\'(1) and y\"(1) using the following table Input: (copy and paste the MATLAB or Scilab script in the following box)Solution
a) Matlab Code
f= @(x) x*exp(x)+3*x^2+x-1;
h = [0.1 0.01 0.001];
% for h=0.1
firstorder_forward1 = (f(3+h(1))-f(3))/h(1)
firstorder_backward1 = (f(3)-f(3-h(1)))/h(1)
firstorder_central1 = (f(3+h(1))-f(3-h(1)))/(2*h(1))
secondorder_central1 = (f(3+h(1))-2*f(3)+f(3-h(1)))/h(1)^2
% for h=0.01
firstorder_forward2 = (f(3+h(2))-f(3))/h(2)
firstorder_backward2 = (f(3)-f(3-h(2)))/h(2)
firstorder_central2 = (f(3+h(2))-f(3-h(2)))/(2*h(2))
secondorder_central2 = (f(3+h(2))-2*f(3)+f(3-h(2)))/h(2)^2
% for h=0.001
firstorder_forward3 = (f(3+h(3))-f(3))/h(3)
firstorder_backward3 = (f(3)-f(3-h(3)))/h(3)
firstorder_central3 = (f(3+h(3))-f(3-h(3)))/(2*h(3))
secondorder_central3 = (f(3+h(3))-2*f(3)+f(3-h(3)))/h(3)^2
b) Matlab Code
x = [0.8 0.9 1.0 1.1 1.2];
f = [0.992 0.999 1.0 1.001 1.008];
firstorder_forward = (f(4)-f(3))/0.1
firstorder_backward = (f(3)-f(2))/0.1
firstorder_central = (f(4)-f(2))/0.2
secondorder_central = (f(4)-2*f(3)+f(2))/0.1^2
secondorder_higher = (-f(1)+16*f(2)-30*f(3)+16*f(4)-f(5))/(12*0.1^2)
........Thank you
