Answered step by step
Verified Expert Solution
Link Copied!

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("============================================================
")
fprintf("Project 1- Round-off vs Truncation Error
")
fprintf("Insert Your Name Here
")
display(date())
fprintf("============================================================
")
%========================================================================
format short e
% Define the function f(x)
f = @(x) ; % Insert Function f(x)
df = @(x) ; % Insert Exact First Derivative df(x)
% Select x value to evaluate derivative
x = ;
%% Double-Precision
% loop through the exponents for each delta x value and evaluate the derivative
for i =1:20
% calculate the delta x
del(i,1)=10^(-i);
% Backward Finite Difference
backward(i,1)= ;
% Forward Finite Difference
forward(i,1)= ;
% Central Finite Difference
central(i,1)= ;
% calculate the errors compared to exact (analytical) derivative
backward_error(i,1)= ;
forward_error(i,1)= ;
central_error(i,1)= ;
end
% Plot the error vs del x for each method on the log scale
figure
hold on
% Scale of log for axis
set(gca, 'XScale', 'log', 'YScale', 'log')
% the loglog() function is the same as plot() but on log scale for both axes
loglog()
loglog()
loglog()
xlabel('\Delta'), ylabel('Error')
title('Error on Fordward, Backward, and Central')
legend('Forward','Backward','Central')
grid on, hold off
% assemble the results into a table (actually a matrix)
Table =[];
% print to screen
fprintf("=========== Double Precision Results ===========
")
disp(Table)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Repeat everything, but in single precision
% Select x value to evaluate derivative
x = single(x);
for i = single(1:20)
end
% Plot the error vs del x for each method on the log scale
figure
hold on
% Scale of log for axis
set(gca, 'XScale', 'log', 'YScale', 'log')
% the loglog() function is the same as plot() but on log scale for both axes
loglog()
loglog()
loglog()
xlabel('\Delta'), ylabel('Error')
title('Error on Fordward, Backward, and Central')
legend('Forward','Backward','Central')
grid on
% assemble the results into a table (actually a matrix)
fprintf("
")
Table =[];
% print to screen
fprintf("=========== Single Precision Results ===========
")
disp(Table);
%% Machine epsilon

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

2. Why do we need legislation to protect women in the workplace?

Answered: 1 week ago