2 Consider the function fa 2 4 on the interval 221 with h 02
2. Consider the function: f(a) 2- 4 on the interval (-2,21 with h 0.25. Use the forward, backward, and centered finite difference approx- imations for the first and second derivatives so as to graphically illustrate which approximation is most accurate. Graph all three first-derivative finite difference approximations along with the theoretical, and do the same for the second derivative as well.
Solution
f(x)= x3 _2.x +4
Calculus:
>> syms x;
>> diff(x^2)
ans =2*x
2.
>> syms x
>> diff(x^4)
ans = 4*x^3
diff(x3 _2.x +4)
>> syms x;
diff(x^3-2*x+4)
ans =
3*x^2 - 2
diff(3*x^2 - 2)
>> diff(3*x^2 - 2)
ans =
6*x
