A) Write a MATLAB function that computes precision for a given reference value.
ID: 3784304 • Letter: A
Question
A) Write a MATLAB function that computes precision for a given reference value.
A prototype of the function is given here:
function [precision] = PrecisionVersusBase( base ) % returns precision
The algorithm for computing the precision is given in the pseudo code below
precision = base
WHILE( base + precision > base )
precision = precision / 2
precision = precision * 2
B)
Using the function from part A, compute precision for a reference value equal to 1.0 to
1e-30, reducing it by a factor of 10 each step. ( base = base/10.0; ) Write out the results of each case to a Comma Separated Values (CSV) file*. Write out the precision, and the base, along with the ratio of precision and base, in other words writeout base, precision and precision/base. Document these results in your report.
First, plot the base versus precision and then plot base versus the ratio. Due to the geometricnature in the progression of base, base/10 at each step, a log scale might be helpful.The MATLAB function loglog is the same as plot, except each axis (x and y) will use a log scale.
Explanation / Answer
Answer
For A, below is the matlab function:
function [precision] = PrecisionVersusBase( base )
precision = base
while base + precision > base
precision = precision / 2;
end
precision = precision * 2;
For B, below is the matlab code:
function [precision] = PrecisionVersusBase( base )
while base != 1
precision = base
while base + precision > base
precision = precision / 2;
end
precision = precision * 2;
% store the precision in the required file here
base = base/10;
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.