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
  • Homework 5 (35 Points max) Please Submit all Matlab and Data files that you create for this homew...

    Homework 5 (35 Points max) Please Submit all Matlab and Data files that you create for this homework Problem 1 (max 20 Points): For the second-order drag model (see Eq.(1)), compute the velocity of a free-falling parachutist using Euler's method for the case where m80 kg and cd 0.25 kg/m. Perform the calculation from t 0 to 20 s with a step size of 1ms. Use an initial condition that the parachutist has an upward velocity of 20 m/s at...

  • The first two parts should be solved by Matlab. This is from an intro to Numerical...

    The first two parts should be solved by Matlab. This is from an intro to Numerical Analysis Class and I have provided the Alog 3.2 in below. Please write the whole codes for me. Alog3.2 % NEWTONS INTERPOLATORY DIVIDED-DIFFERENCE FORMULA ALGORITHM 3.2 % To obtain the divided-difference coefficients of the % interpolatory polynomial P on the (n+1) distinct numbers x(0), % x(1), ..., x(n) for the function f: % INPUT: numbers x(0), x(1), ..., x(n); values f(x(0)), f(x(1)), % ...,...

  • (b) . Write the k-th step of the trapezoidal method as a root-finding problem Ğ = is Y+1 where the unknown (e)Find the Jacobian matrix of the vector function from the previous part. (dWrite a funct...

    (b) . Write the k-th step of the trapezoidal method as a root-finding problem Ğ = is Y+1 where the unknown (e)Find the Jacobian matrix of the vector function from the previous part. (dWrite a function in its own file with definition [Y] dampedPendulum(L, T) function alpha, beta, d, h, that approximates the solution to the equivalent system you derived in part (a) with L: the length of the pendulum string alpha: the initial displacement beta: the initial velocity d:...

  • 2. Consider a mass m moving in R3 without friction. It is fasten tightly at one...

    2. Consider a mass m moving in R3 without friction. It is fasten tightly at one end of a string with length 1 and can swing in any direction. In fact, it moves on a sphere, a subspace of R3 1 0 φ g 2.1 Use the spherical coordinates (1,0,) to derive the Lagrangian L(0,0,0,0) = T-U, namely the difference of kinetic energy T and potential energy U. (Note r = 1 is fixed.) 2.2 Calculate the Euler-Lagrange equations, namely...

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