Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started