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

Do it with MATLAB *A) For each of the h-values specified in the chart, use the t

ID: 3184544 • Letter: D

Question

Do it with MATLAB

*A) For each of the h-values specified in the chart, use the three-point centered-difference formula for the second derivative to approximate f"(0), where f(x) cos x, find a bound on the approximation error and compare with the actual error. 4. B) What is the order of the convergence of the approximation formula (linear, square, cubic, etc., i.e., if the h is decreased by ½, does the approximation get better by a factor of ½, ¼,1/8, etc.)? h exact approximationerr-exact-approximationbound on error 0.1 0.01 0.001

Explanation / Answer

clc;
clear all;
f=@(x)cos(x);

ddf=@(x)-cos(x);
x=0;

%error bound is f^4(x)*h^2/12

h=[0.1 0.01 0.001]
for i=1:3
f_central(i)=(f(x+h(i))-2*f(x)+f(x-h(i)))/(h(i)^2);
end
error=abs(f_central-ddf(x));
disp('________________________________________________________________________')
disp('x central(x=0) exact error error bound')
disp('______________________________________________________________________________')
for i=1:3
fprintf('%f %15f %15f %15f %15f ',h(i),f_central(i), ddf(x), error(i), h(i)^2/12 )
end

h =

0.1000 0.0100 0.0010

________________________________________________________________________

x central(x=0) exact error error bound

______________________________________________________________________________

0.100000 -0.999167 -1.000000 0.000833 0.000833

0.010000 -0.999992 -1.000000 0.000008 0.000008

0.001000 -1.000000 -1.000000 0.000000 0.000000

>>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote