A Write a MATLAB function that computes precision for a give

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.

Solution

(a)

function numdigits(x: integer): integer;

var t,n: integer;

begin

n := 1; t := x;

while t >= 10 do begin

n := n + 1;

t := t div 10;

end;

numdigits := n;

end;

(c)

numdigits x = if x < 10 then 1 else numdigits(x / 10) + 1

(e)

function numdigits(x: Integer) return Integer is

t: Integer := x;

n: Integer := 1;

begin

while t >= 10 loop

n := n + 1;

t := t / 10;

end loop;

return n;

end numdigits;

(g)

class NumDigits

{ public static int numdigits(int x)

{ int t = x, n = 1;

while (t >= 10)

{ n++;

t = t / 10;

}

return n;

}

}

A) Write a MATLAB function that computes precision for a given reference value. A prototype of the function is given here: function [precision] = PrecisionVersu
A) Write a MATLAB function that computes precision for a given reference value. A prototype of the function is given here: function [precision] = PrecisionVersu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site