Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please show the code and the result. You can use java or the Matlab language. Th

ID: 3785497 • Letter: P

Question

Please show the code and the result. You can use java or the Matlab language. Thank you

Problem 1 (Continuous vs. discrete). Functions f a) are usually defined over an entire domain E I (a, b) C R and if interesting take values in image f(I) C R. The domain and, typically also the image, are sets with an infinitely many elements. On the other hand, computers can only represent numbers using a finite number of bits, most often as 32-bit (float, or REAL*4) or 64-bit (double, or REAL 8) IEEE floating point numbers, which store numbers in the form tm2e, where 0 mn 1 is the mantissa. ma b12-1 b22 2 b32 3 bM2 (1) and e is the exponent and has the form e (u020 u121 u222 u323 wE2F) (2) The coefficients bi ui are single-bit numbers, i.e., either 0 or 1. In the bi nary system, floating point numbers can therefore be written as 10203 x 2 1 E-2 u0 The total number of bits needed for the representation are M bits for the mantissa, E 1 bits for the exponent, and 2 bits for the two signs. Obviously, not all elements of I and f(I) can be represented. Write a short program to find

Explanation / Answer

class Test
{
public static void main(String[] args)
{
float num = 1;
float small = 1;
float prevSmall = small;
  
while(num != (num+small))
{
prevSmall = small;
small = small / 10;
}
System.out.println("Smallest float: " + prevSmall);


double numD = 1;
double smallD = 1;
double prevSmallD = smallD;
while(numD != (numD+smallD))
{
prevSmallD = smallD;
smallD = smallD / 10;
}
System.out.println("Smallest double: " + prevSmallD);
}
}

/*

Sample run

$ javac Test.java
$ java Test
Smallest float: 9.999999E-8
Smallest double: 1.0E-15

*/