E7_Lab08_Solution_Fall_2010

# E7_Lab08_Solution_Fall_2010 - Contents Solution for Lab 08...

This preview shows pages 1–3. Sign up to view the full content.

Contents Solution for Lab 08 Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Problem 6 Problem 7 Solution for Lab 08 clear clc format compact Problem 1 x = 11.11; format long x format short x % Because the numbers stored in Matlab is not continuous. Matlab % double-precision standard to store real numbers in binary form % right in between two numbers that Matlab can store and therefo % rounded to one of them. y = dec2bin(2); z = dec2bin(3); t = y+z % The output of function dec2bin is strings. so t is '10' + '11' % '1', and char(48) = '0' x = 11.109999999999999 x = 11.1100 t = 98 97 Problem 2 result_2_a = digits_bug(-10.75) result_2_b = digits_bug(11.11) result_2_c = digits_bug(1.11)

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

View Full Document
% after debugged result_2_d = digits_debugged(1.11) result_2_e = digits_debugged (-100) result_2_f = digits_debugged (-3.1415926) type digits_debugged result_2_a = 2 result_2_b = 2 result_2_c = 16 result_2_d = 2 result_2_e = 0 result_2_f = 7 function y = digits_debugged(x) x = abs(x); machine_error = eps(x); y = 0; while (abs(round(x)- x)> machine_error) % Use round because the y = y+1; x = x-floor(x); x = x*10; machine_error = machine_error*10; % Remember the error need
This is the end of the preview. Sign up to access the rest of the document.

### Page1 / 7

E7_Lab08_Solution_Fall_2010 - Contents Solution for Lab 08...

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

View Full Document
Ask a homework question - tutors are online