Question

Solve using MATLAB and provide code please

4. The first derivative of a function f(x) at a point x = xo can be approximated with the four-point central difference formu

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

%%% Matlab function

function dfdx = FoPtdr(Fun,x0)
h=x0/100;
dfdx=(Fun(x0-2*h)-8*Fun(x0-h)+8*Fun(x0+h)-Fun(x0+2*h))/(12*h);
end

%%%% Test

clc;
close all;
clear all;
format long;
Fun=@(x) x^3*exp(2*x);
x0=0.6;

(a)

>> FoPtdr(Fun,x0)

ans =

5.020016698059604

>>

(b)

>> Fun=@(x) x^3;
>> x0=2;
>> FoPtdr(Fun,x0)

ans =

12.000000000000027

(c)

%%%

syms x;
f=x^3*exp(2*x);
df=subs(diff(f),x0);
fprintf('Actual value = %f Error =%1.10f \n',df,abs(x1-df));

OUTPUT:

Actual value = 5.020017 Error =0.0000000891   
>>

(d) and (e)

clc;
close all;
clear all;
format long;
Fun=@(x) 3^x/x^2;
x0=2.5;
x1=FoPtdr(Fun,x0);
fprintf('Using function FoPtdr dydx=%f \n',x1);
syms x;
f=3^x/x^2;
df=subs(diff(f),x0);
fprintf('Actual value = %f Error =%1.10f \n',df,abs(x1-df));

OUTPUT:

Using function FoPtdr dydx=0.744785
Actual value = 0.744785 Error =0.0000000174   
>>

Add a comment
Know the answer?
Add Answer to:
4. The first derivative of a function f(x) at a point x = xo can be approximated with the four-po...
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
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