Answered step by step
Verified Expert Solution
Question
1 Approved Answer
% Clear command window, close all graphs, clear workspace clc , close all, clear % = = = = = = = = = =
Clear command window, close all graphs, clear workspace
clc close all, clear
fprintf
fprintfProject Roundoff vs Truncation Error
fprintfInsert Your Name Here
displaydate
fprintf
format short e
Define the function fx
f @x ; Insert Function fx
df @x ; Insert Exact First Derivative dfx
Select x value to evaluate derivative
x ;
DoublePrecision
loop through the exponents for each delta x value and evaluate the derivative
for i :
calculate the delta x
delii;
Backward Finite Difference
backwardi ;
Forward Finite Difference
forwardi ;
Central Finite Difference
centrali ;
calculate the errors compared to exact analytical derivative
backwarderrori ;
forwarderrori ;
centralerrori ;
end
Plot the error vs del x for each method on the log scale
figure
hold on
Scale of log for axis
setgca 'XScale', 'log', 'YScale', 'log'
the loglog function is the same as plot but on log scale for both axes
loglog
loglog
loglog
xlabelDelta ylabelError
titleError on Fordward, Backward, and Central'
legendForward'Backward','Central'
grid on hold off
assemble the results into a table actually a matrix
Table ;
print to screen
fprintf Double Precision Results
dispTable
Repeat everything, but in single precision
Select x value to evaluate derivative
x singlex;
for i single:
end
Plot the error vs del x for each method on the log scale
figure
hold on
Scale of log for axis
setgca 'XScale', 'log', 'YScale', 'log'
the loglog function is the same as plot but on log scale for both axes
loglog
loglog
loglog
xlabelDelta ylabelError
titleError on Fordward, Backward, and Central'
legendForward'Backward','Central'
grid on
assemble the results into a table actually a matrix
fprintf
Table ;
print to screen
fprintf Single Precision Results
dispTable;
Machine epsilon
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started