Question
Please answer this problem using MATLAB.
Problem 4 : Finite difference formula and interpolation For this problem, you will approximate the derivative of the function
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

clc
clear all
x=linspace(-2,2,5);
y=[];
g=@(x) 5*x^5+6*x^4-2*x^3+8*x^2+3*x-15;
h=0.01;
for i=1:length(x)
y(i)=(g(x(i)+h)-g(x(i)-h))/(2*h);
end
C=polyfit(x,y,4);
gd=@(x) 25*x^4+24*x^3-6*x^2+16*x+3;
fplot(gd,[-2,2]);
xx=-2:0.01:2;
hold on;
plot(xx,polyval(C,xx));
fprintf('Coefficients of polynomial are: %f*x^4+%f*x^3%f*x^2+%f*x+%f',C);
legend('Analytical','Finite difference');
disp('Both are approximately same since this is a polynomial fit for centered difference with low h');

MATLAB R2018a Figure Search Documentation Log In EDITOR naertfEile Edit View Insert Iools Desktop Wndow Help Find Files Compa

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Problem 4 : Finite difference formula and interpolation For this problem, you will approximate th...
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