E7_Lab08_solutions_Fall_2010

E7_Lab08_solutions_Fall_2010 - Contents Solution for Lab 08...

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

View Full Document Right Arrow Icon
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 uses IEEE % double-precision standard to store real numbers in binary forms. 11.11 is % right in between two numbers that Matlab can store and therefore is % 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'. char(49)= % '1', and char(48) = '0' x = 11.109999999999999 x = 11.1100
Background image of page 1

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

View Full DocumentRight Arrow Icon
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) % 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 error can be positive or negative y = y+1;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

E7_Lab08_solutions_Fall_2010 - Contents Solution for Lab 08...

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

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