Using matlab to create the programs Calculate the sum not th

Using matlab to create the programs;

Calculate the sum (not the partial sum) of the first 10 million terms in the harmonic series 1/2 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 + ... + 1/N + ... using both double-precision and single-precision numbers. Compare the results. Explain why they are different. (You may include your explanation as a comment at the end of the code for this problem. Sometimes it is confusing to realize that numbers can be represented bas both numeric data and character data. Use MATLAB to express the number 85 as a character array. a. How many elements are in this array? b. What is the numeric equivalent of the character 8? c. What is the numeric equivalent of the character 5? (again, you may include your answers as comments at the end of the code for this problem.

Solution

n=1:10^6;
L = length(n);
sumdouble = 0;
for i=1:L
sumdouble=sumdouble+double(1/i);%summing in double format
end
sumsingle=0;
for i=1:L
sumsingle = sumsingle+single(1/i);%summing in single formats
end
disp(sumsingle);
disp(sumdouble);
%double stores the value in 64 bits where as single stores it in 32 bits,
%which causes truncation in single precesion and more over double is more
%precise than single

2one:

>> clear all;
>> var1 = \'85\';
>> L = length(var1);
>> uint16(var1(1))

ans =

56%ASCII value

>> uint16(var1(2))

ans =

53%ASCII value

>>

Using matlab to create the programs; Calculate the sum (not the partial sum) of the first 10 million terms in the harmonic series 1/2 + 1/2 + 1/3 + 1/4 + 1/5 +

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site