 # 1. To approximate the derivative of a function at a point...

## Question

Show transcribed text

## Transcribed Text

1. To approximate the derivative of a function at a point x we can use the first order forward difference method (FD1): 22 - h To implement this, we create a function file called FD1.m: function d = FD1 (f, , X , h) d = (f (x+h)-f(x))/h; A sample script that uses this simple function is f = 0(x) x.^2; x = 3; exactderiv = 2*x; h1 = .1; h2 = .01; d1 = FD1(f,x,h1) ; d2 = FD1 (f, x, h2) fprintf ('The approximate derivative at %f using h=%f is %e\n', x, h1,d1) fprintf ('The approximate derivative at %f using h=%f is %) x, h2, d2) fprintf ('The error with h=%f is %e\n' h1, abs (exactderiv-d1)) fprintf ('The error with h=%f is %e\n' h2, abs (exactderiv-d2)) Always print errors in scientific notation SO you can see the order of magnitude. Your assignment is to approximate the derivative of f = xet2 at x = 2 using h = .01 and h = .001 using the second order central difference (CD2) and second order forward difference (FD2) schemes, shown below. Build function files CD2.m and FD2.m, and a script file to define the inputs, call the functions, and output the results including the errors. = - 2h f' (x) = - 3f(x)+4f(x+h-f(x+2h) - 2h

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

f=@(x) x.^2;
x=3;
exactderiv = 2*x;
h1 = .1; h2 = .001;
d1 = FD1(f,x,h1); d2 = FD1(f,x,h2);
fprintf('The approximative derivative at %f using h=%f is %e\n',x,h1,d1);
fprintf('The approximative derivative at %f using h=%f is %e\n',x,h2,d2);
fprintf('The error with h=%f is %e\n',h1,abs(exactderiv-d1));
fprintf('The error with h=%f is %e\n',h2,abs(exactderiv-d2));...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

# 50% discount

Hours
Minutes
Seconds
\$13.00 \$6.50
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Numerical Analysis Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.