Question

1. Approximate the derivative of each of the following functions using the forward, backward, and centered differ- ence formu

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOLUTION

1)

MATLAB CODE :

clc
clear all
x=linspace(-5,5,100);
h=1e-4;
fd1=[];
bd1=[];
cd1=[];
fd2=[];
bd2=[];
cd2=[];
fd3=[];
bd3=[];
cd3=[];
fd4=[];
bd4=[];
cd4=[];
f1=@(x) x;
f2=@(x) x.^2;
f3=@(x) x.^3;
f4=@(x) sin(x);
for i=1:length(x)-1
fd1(i)=(f1(x(i)+h)-f1(x(i)))/h;
fd2(i)=(f2(x(i)+h)-f2(x(i)))/h;
fd3(i)=(f3(x(i)+h)-f3(x(i)))/h;
fd4(i)=(f4(x(i)+h)-f4(x(i)))/h;

end
for i=2:length(x)
bd1(i-1)=(f1(x(i))-f1(x(i)-h))/h;
bd2(i-1)=(f2(x(i))-f2(x(i)-h))/h;
bd3(i-1)=(f3(x(i))-f3(x(i)-h))/h;
bd4(i-1)=(f4(x(i))-f4(x(i)-h))/h;

end
for i=2:length(x)-1
cd1(i-1)=(f1(x(i)+h)-f1(x(i)-h))/(2h);
cd2(i-1)=(f2(x(i)+h)-f2(x(i)-h))/(2h);
cd3(i-1)=(f3(x(i)+h)-f3(x(i)-h))/(2h);
cd4(i-1)=(f4(x(i)+h)-f4(x(i)-h))/(2h);

end
plot(x(1:end-1),fd1,x(2:end),bd1,x(2:end-1),cd1);
title('Plot of finite difference for part a');
legend('Forward difference','Backward difference','Central difference')
figure;
plot(x(1:end-1),fd2,x(2:end),bd2,x(2:end-1),cd2);
title('Plot of finite difference for part b');
legend('Forward difference','Backward difference','Central difference')
figure;
plot(x(1:end-1),fd3,x(2:end),bd3,x(2:end-1),cd3);
title('Plot of finite difference for part c');
legend('Forward difference','Backward difference','Central difference')

figure;
plot(x(1:end-1),fd4,x(2:end),bd4,x(2:end-1),cd4);
title('Plot of finite difference for partd');
legend('Forward difference','Backward difference','Central difference')

OUTPUT :

PLOTS ;

part A :

plot 1

1.15 - 1.05 1.1彫 0.95 0.9 1 0.85 43 -4

plot 2

Plot of finite difference for part a 1.15 - 1.05 - 0.95 0.9 43 -4 -2

plot 3

Plot of finite difference for part a 1.15 - Forward difference backward difference 1.1 1.05 - 0.95 0.9 43 -4 -2part B:

plot 1

10 5i 5i 10 -8 -4 -2

plot 2

Plot of finite difference for part b 10 5i 5 Ei 10 -8 -4 -2

plot 3

Plot of finite difference for part b 10 Forward difference Backward difference 5i -5 10 -6 -4 -2

part C

plot 1

80 70 50 40 30 - 20 10_ 41 .4 -2

plot 2

Plot of finite difference for part c 80 70 10) 50 40 30 20 10 41 .4 -2plot 3

Plot of finite difference for part c 80 Forward difference 70 backward difference 10) 50 40 30 20 10 41 .4 -2

part D :

plot 1

0.5 0.5 -6 -4 -2

plot 2

Plot of finite difference for partd 0.5 05 -1 -6 -4plot 3

Plot of finite difference for partd Forward difference Backward difference andle 0.5 0.5 -1 -6 -4

Add a comment
Know the answer?
Add Answer to:
1. Approximate the derivative of each of the following functions using the forward, backward, and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Use the centered difference formula to approximate f(z) for f sin and z1, using h 1, 1/10, 1/1...

    2. Use the centered difference formula to approximate f(z) for f sin and z1, using h 1, 1/10, 1/100, ...., 1 /1015. Plot the absolute error. Explain the behavior as h decreases. (Hint: Read the last subsection of §11 concerning roundoff error.) Why does this instability not arise with -0? 2. Use the centered difference formula to approximate f(z) for f sin and z1, using h 1, 1/10, 1/100, ...., 1 /1015. Plot the absolute error. Explain the behavior as...

  • Approximating derivatives f(z +h) - f(z) f(x)-f( -h) f(x + h) - f(x - h) Forward difference Backw...

    Added the formulas, thank you! Approximating derivatives f(z +h) - f(z) f(x)-f( -h) f(x + h) - f(x - h) Forward difference Backward difference Centered difference for 1st derivative s(a) (3) 2h t)-2e-bCentered diference for 2nd derivative (4) 2 2. Write a short program that uses formulas (1), (3) and (4) to approximate f(1) and f"(1) for f(x)e with h 1, 2-1, 2-2,.., 2-60. Format your output in columns as follows: h (6+f)() error (öf(1 error f error Indicate the...

  • 1. Approximate the following integral, exp(r) using the composite midpoint rule, composite trapez...

    can i get some help with this ? 1. Approximate the following integral, exp(r) using the composite midpoint rule, composite trapezoid rule, and composite Simpeon's method. Each method should invol + l integrand evaluations, k 1: 20. On the same plot, graph the absolute error as a function of n. ve exactly n = 2k 2. Approximate the integral from Question 1 using integral, Matlab's built-in numerical integrator. What is the absolute error? 1. Approximate the following integral, exp(r) using...

  • 1. Use the forward-difference formulas and backward-difference formulas to determine each missing entry in the following...

    1. Use the forward-difference formulas and backward-difference formulas to determine each missing entry in the following tables. 0.0 0.00000 0.2 0.74140 0.4 1.3718 xf(x) s(x) 0.3 1.9507 0.2 2.0421 -0.1 2.0601 MATH-321: INTRODUCTION TO NUMERICAL ANALYSIS 2·The data in Exercise 1 comes from functions f with second derivatives given as follows: (a) "(x)-e 4 Find error bounds using the error formulas. (b) (x)8 cos 2x

  • (a) (4 points) Fill in the blanks in the following MATLAB function M file trap so...

    (a) (4 points) Fill in the blanks in the following MATLAB function M file trap so that it implements the composilu trapezidul rulo, using a soquence of w -1,2, 4, 8, 16,... trapezoids, to approximatel d . This M file uses the MATLAB built-in function trapz. If 401) and y=() f(!)..... fr. 1)). 3= ($1, then the execution of z = trapz(x, y) approximates using the composite trapezoidal rule (with trapezoids). (Note that the entries of are labeled starting at...

  • Estimate the second derivative of the following function using stencils for the FORWARD and CENTRAL derivatives for an order of accuracy of O(h2) for each. Use a step size of h -1. fo)x-2x2...

    Estimate the second derivative of the following function using stencils for the FORWARD and CENTRAL derivatives for an order of accuracy of O(h2) for each. Use a step size of h -1. fo)x-2x2 +6 Second derivative, Forward Difference Approximation, o(h2)- Second derivative, Central Difference Approximation, O(h2) Which of the two methods is closer to the true value? (Forward/Central 12.5 points Differential Equation Estimate the second derivative of the following function using stencils for the FORWARD an derivatives for an order...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT