Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MAE 376 - Lab 5: Truncation and Floating Point Error Using a Taylor series appro

ID: 3168337 • Letter: M

Question

MAE 376 - Lab 5: Truncation and Floating Point Error Using a Taylor series approximation, various finite difference methods can be derived. These methods are used to approximate the derivatives of functions at any point, x,. The three main types of finite difference methods are The Forward Difference Method: f(ri) -f(r) The Backward Difference Method: f'(m) = The Central Difference Method: f(ri) f(x,-1) 2h f'(n) = The error due to these approximations can be given as the difference between the actual value of the derivative and our approximated value. Assignment: This problem explores the trade-off between the truncation error in the finite difference approximation of the derivative and floating point truncation error incurred when using finite precision arithmetic. (a) Write a MATLAB script that computes the forward finite difference ap- proximation of the derivative of e for x1. Use step sizes ranging from 10-1 to 10-16. The logspace command may be useful here. Plot the error, using a log-log scale, between your approximation and the exact derivative for each of your step sizes. (b) Based on your plot, what is the best step size to use for the finite difference step size? (c) Explain the behavior you see in the graplh Submission Instructions: ·You should submit your final code as a single MATLAB script, Labo-person#.m" . Your plot should be labeled properly and submitted as a single figure, "LabS-person#.png” Your answers for part b) and c)should be submitted in a pdf file. Lab5.person#.pdf . A zipped folder containing all the submission files should be uploaded to UBLearns

Explanation / Answer

clear all
clc
f = @(x) exp(3*x);
%actual derivative of function
fprime = @(x) 3*exp(3*x);
h=0.25;
%forward difference
a=1/10;
b=1/(10^6);
h=logspace(b,a);
n=length(h);
for i=1:n
    df(i) = (f(1+h(i))-f(1))/h(i);
    Error(i) = fprime(1)-df(i);
end
f=figure(1);
loglog(Error) % Ploting the error


Let me know if this solved your problem or not.