MAT 581 HW 1

MAT 581 HW 1 - disp(sprintf('%2.0f %15.0f %8.0f %15.0f

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
% P 1.4.8 MaxVal=2^5-1; disp(sprintf('THe nearest floating point number to 64 with 5-bit mantisa is .11111*2^5 or %d', MaxVal)) % P 1.4.4 t = 24; MaxInt = 2^t - 1; n = 0; nfact = 1; s = MaxInt-1; disp(' n n! x n!/x MaxInt-(n!/x)') disp('------------------------------------------------------------------') while(s>=0) n = n+1; nfact = nfact*n; % Computing x = largest power of 2 that divides n!. TwoPower = 1; while floor((nfact/TwoPower))*TwoPower == nfact TwoPower = 2*TwoPower; end x = TwoPower/2; % n! is exactly representable if n!/x <= MaxInt s = MaxInt-(nfact/x);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: disp(sprintf('%2.0f %15.0f %8.0f %15.0f %15.0f',n,nfact,x,nfact/x,s)) end disp(' ') disp(sprintf('The largest n so n! is exactly representable is n = %1d.',n-1)) % P 1.4.3 x = linspace(0,2*pi); sum = zeros(1,length(x)); z = input('Please Enter number of terms:') %creating a vector of length of x of 0s; for i = 1:length(sum) %initialize first loop for n = 1:z term = (((-1)^(n-1))*x(i)^(2*(n-1)+1))/factorial(2*(n-1)+1); sum(i) = sum(i)+term; end end plot (x, sum, '-', x, sin (x), '--')...
View Full Document

Page1 / 2

MAT 581 HW 1 - disp(sprintf('%2.0f %15.0f %8.0f %15.0f

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online