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
-
Bob Nale is the owner of Nale's Texaco GasTown. Bob would like to estimate the mean number of litres (L) of gasoline sold to his customers. Assume the number of litres sold follows the normal...
-
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...
-
In Problem, find f'(x) and find the equation of the line tangent to the graph of f at the indicated value of x. f(x) %3D 41 (3x - 8)
-
Discuss the two sales response models described in the text. Explain the differences between the two models. Provide examples of type of products that might follow each of these response curves.
-
for determining whether operations have been discontinued and the problems that might arise in applying them. 5 Annual accounts have been put into such a straitjacket overemphasis on uniform...
-
George Zegoyan and Amir Gupta face a difficult decision. Their private auto parts manufacturing company has been a great success - too quickly. They cannot keep up with the demand for their product....
-
2. Let f(x,y) = y+4xy. Find the volumes of the solids under the surface z = f(x, y) and above the following regions: (a) D={(x,y)|0 < <2,2-
-
a. To simplify the analysis, assume for now that there is virtually no turnaround time between flights so the next flight can begin as soon as the current flight ends. (If an immediate next flight is...
-
The Campbell Company is considering adding a robotic paint sprayer to its production line. The sprayer's base price is $1,040,000, and it would cost another $20,500 to install it. The machine falls...
-
Consider the following convertible bond: Maturity = 10 years Coupon rate = 7% Conversion ratio = 50 Maturity value = 1,000 Moreover, the following information has been gathered about the bond and the...
-
Explain, giving reasons, whether the following statements are true or false. a. A high degree of trade among a group of countries implies that there would be benefits from them adopting a common...
-
An agricultural scientist wants to determine the effect of fertilizer type on the yield of tomatoes. There are four types of fertilizer under consideration. She plants tomatoes on four plots of land....
-
Suppose that a bond issued by XXX Corporation is convertible into 30 shares of common stock. The delta of this bond is 0.77. Explain how to create a long position in the XXX convertible bond that is...
-
Suppose that Techoland and Cornsylvania decide to engage in fiscal federalism and adopt a common fiscal budget. a. Show, again using the AD/AS model, how fiscal policy can be used to alleviate the...
-
Recording Fixed Asset DisposalOn April 1, one of two large production machines used by EvertCompany stripped a gear, causing major internal damage. On April 5,the company decided to purchase a new 2...
-
Refer to the situation described inBE 18-13, but assume a 2-for-1 stock split instead of the 5% stock dividend. Prepare the journal entry to record the stock split if it is to be effected in the form...
-
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
-
Jon Alden is puzzled. His company had a profit margin of 10% in 2002. He feels that this is an indication that the company is doing well. Anna Weis, his accountant, says that more information is...
-
(a) If Nick Flach Company had net income of \($540,000\) in 2001 and it experienced a 24.5% in- crease in net income for 2002, what is its net in- come for 2002? (b) If six cents of every dollar of...
-
Brian Tanaka Company, a retail store, has a receivables turnover ratio of 4.5 times. The industry aver- age is 12.5 times. Does Tanaka have a collection problem with its receivables?
Study smarter with the SolutionInn App