Write a script to find Nmin, the smallest possible value for N in Eq. (1) so...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a script to find Nmin, the smallest possible value for N in Eq. (1) so that ln(5) evaluated using my Log with Matlab's default double precision arithmetics is exact when written as a half-precision binary floating point number in engineering notation. Use decimal2binary developed in Module 1 to answer this question and do not use Matlab's half (). Just setting Nmin without an algorithm to find its value will not give any credit. Notes for the MatlabGrader script submission: Comment out clear or clear all in your script when submitting to MatlabGrader. Store the answer in the variable Nmin. Do not include the source code for my Log or decimal2binary in your submission. Correct versions are used automati- cally on Matlab Grader. 1% Initialize Nmin 2 Nmin = 1; 3 4% Calculate the true value of In(5) s true_val = log (5); 6 7% Calculate the precision of a half-precision floating point number 8 half_precision = 2^-11; 9 10 % Initialize the error 11 error = Inf; 12 13 327998722222222 14 15 16 17 18 19 20 21 24 25 26 % While the error is greater than the half-precision while error > half_precision % calculate the value of ln (5) using myLog my Log_val = myLog(5, Nmin); 28 end % Convert 1n (5) to half-precision binary floating-point in engineering notation Ins_half_precision_binary = decimal2binary(myLog_val, 16); % Adjust the second argument base % calculate the error error = abs (myLog_val - true_val); % If the error is greater than the half-precision, increment Nmin for the next iteration if error > half_precision Nmin = Nmin + 1; end 30 % Display the result 31 disp(['The smallest value for N (Nmin) is: num2str (Nmin)]); 32 I Write a script to find Nmin, the smallest possible value for N in Eq. (1) so that ln(5) evaluated using my Log with Matlab's default double precision arithmetics is exact when written as a half-precision binary floating point number in engineering notation. Use decimal2binary developed in Module 1 to answer this question and do not use Matlab's half (). Just setting Nmin without an algorithm to find its value will not give any credit. Notes for the MatlabGrader script submission: Comment out clear or clear all in your script when submitting to MatlabGrader. Store the answer in the variable Nmin. Do not include the source code for my Log or decimal2binary in your submission. Correct versions are used automati- cally on Matlab Grader. 1% Initialize Nmin 2 Nmin = 1; 3 4% Calculate the true value of In(5) s true_val = log (5); 6 7% Calculate the precision of a half-precision floating point number 8 half_precision = 2^-11; 9 10 % Initialize the error 11 error = Inf; 12 13 327998722222222 14 15 16 17 18 19 20 21 24 25 26 % While the error is greater than the half-precision while error > half_precision % calculate the value of ln (5) using myLog my Log_val = myLog(5, Nmin); 28 end % Convert 1n (5) to half-precision binary floating-point in engineering notation Ins_half_precision_binary = decimal2binary(myLog_val, 16); % Adjust the second argument base % calculate the error error = abs (myLog_val - true_val); % If the error is greater than the half-precision, increment Nmin for the next iteration if error > half_precision Nmin = Nmin + 1; end 30 % Display the result 31 disp(['The smallest value for N (Nmin) is: num2str (Nmin)]); 32 I
Expert Answer:
Related Book For
Posted Date:
Students also viewed these algorithms questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Discuss three quotes from the YouTube video (put time stamps after you type the quote) and explain why chose this quote. https://youtu.be/h86MGjGAtYk?si=_1hMyOefl0L3E4ox Example: Radio is "still...
-
To what extent do you think that models of the service encounter and service design developed for face-to-face encounters, e.g. Servicescape, are applicable in an online service context? Illustrate...
-
You are asked to construct a capacitor having a capacitance near 1nF and a breakdown potential in excess of 10 000 V. You think of using the sides of a tall Pyrex drinking glass as a dielectric,...
-
Shikha Entertainment Ltd. purchased some fixed assets for a consolidated price. The details are as under. Details of the market values of these assets as appraised by a valuer are also given....
-
1. What advice do you have for Morris and Ellen? 2. What recommendations do you have for preparing children to lead changes in a company?
-
. How a flash memory can be Read, Erased, or Programmed? Explain the steps involved.
-
What is the theory? An experiment measuring density and viscosity.
-
Use synthetic division to find the quotient and the remainder. 3r3+24r2+32r-33 r+6
-
3. If the policy proposed in question 2 is adopted, analyze the potential effects of this policy on the demand for workers under the age of 65. That is, if employers who want their employees to be...
-
Question 2 Consider a monopsonist with the following relationship between wage and labor: and the following production function w= a+bL f(K, L) = ln(L) + In(K) (3) (4) 1. Write the short run profit...
-
3. a) Derive D = 4x using solid state diffusion theory b) Calculate the binary O2/N2 gas diffusivity at T = 300K and compare it to the pure 02 self- diffusivity. The molecular diameter of N2 is...
-
3.4 The following sequence of code has been observed in various programs: dup2 (fd, 0); dup2 (fd, 1); dup2 (fd, 2); if (fd > 2) close(fd); To see why the if test is needed, assume that fd is 1 and...
-
Isadores Implements, Inc., manufactures pens and mechanical pencils often used for gifts. Overhead costs are currently allocated using direct labor-hours, but the controller has recommended an...
-
Hotel Majestic is interested in estimating fixed and variable costs so that the company can make more accurate projections of costs and profit. The hotel is in a resort area that is particularly busy...
-
Suppose the solution set of a certain system of linear equations can be described as x1 = 5 + 4x3, x2 = -2 - 7x3, with x3 free. Use vectors to describe this set as a line in. R3
-
In Exercises 1-2, determine if the vectors are linearly independent. Justify each answer. 1. 2. 10
-
Suppose A is a 4 ( 3 matrix and b is a vector in with the property that Ax = b has a unique solution. What can you say about the reduced echelon form of A? Justify your answer. R4
-
Explain why a taxpayer with higher income does not have as large of a behavioral response to an increase in the tax rate as a lower-income taxpayer.
-
Differentiate between an open transaction and a closed transaction.
-
Differentiate between tax compliance and tax planning.
Study smarter with the SolutionInn App