Question: % 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
