Question

MATLAB 1) Calculate the following for the function f(x) = e-4x- 2x3

#use MATLAB script


1)  Calculate the following for the function f(x) = e-4x- 2x3 

a. Calculate the derivative of the function by hand. Write a MATLAB function that calculates the derivative 05. of this function and calculate the derivative at x = 0.5. 


b. Develop an M- to evaluate the cetered finite-difference approximation (use equation below), at x = 0.5. Assume that h = 0.1. 


c. Repeat part (b) for the second-order forward and backward differences. Again Assume that h = 0.1. 


d. Using the results obtained in parts b and c, calculate the percentage error between the actual value and the results of (b) and (c). 


image.png

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

clc
clear all
close all
f=@(x) exp(-4*x)-2*x^3;
g=matlabFunction(diff(sym(f)));
disp('Exact value of derivative at x=0.5 is');
ex=g(0.5);
disp(ex);
disp('Value for part b');
h=0.1;
x=0.5;
Df1=(-f(x+2*h)+8*f(x+h)-8*f(x-h)+f(x-2*h))/(12*h)
disp('Value for part c, forward difference');
Df2=(-f(x+2*h)+4*f(x+h)-3*f(x))/(2*h)
disp('Value for part c, backward difference');
Df3=(3*f(x)-4*f(x-h)+f(x-2*h))/(2*h)
disp('Percent error in central difference is');
abs(ex-Df1)/abs(ex)*100
disp('Percent error in forward difference is');
abs(ex-Df3)/abs(ex)*100
disp('Percent error in backard difference is');
abs(ex-Df2)/abs(ex)*100

Add a comment
Know the answer?
Add Answer to:
MATLAB 1) Calculate the following for the function f(x) = e-4x- 2x3
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
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