Question

Write a script that determines how many times a number can be divided by 2 before...

Write a script that determines how many times a number can be divided by 2 before its resulting value is less than 1. Do not use any built in MATLAB functions
0 0
Add a comment Improve this question Transcribed image text
Answer #1
n = input("Enter a number: ");
count = 0;
while(n>=1)
    n = n / 2;
    count = count + 1;
end
fprintf("Number of times a number can be divided by 2 before its resulting value is less than 1 = %d\n",count);

Output:

Enter a number: > 100 Number of times a number can be divided by 2 before its resulting value is less than 1 = 7

Add a comment
Know the answer?
Add Answer to:
Write a script that determines how many times a number can be divided by 2 before...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a MATLAB script, using either a single or nested for-loop, that will print the factorials...

    Write a MATLAB script, using either a single or nested for-loop, that will print the factorials for the numbers between 1 and 100 (inclusive). The factorial of n (n!) is the product of the positive integers less than or equal to n. For example: 3! = 3 * 2 * 1. For this question you cannot use the built-in MATLAB factorial function, but you can use other MATLAB functions if you wish. MATLAB code!MATLAB code!MATLAB code!MATLAB code!

  • Matlab Homework Please write a script that does the following: generates a 3 x 5 matrix...

    Matlab Homework Please write a script that does the following: generates a 3 x 5 matrix of random integersand call it A. generates a 3 x 3matrix of random integers and call it B. "Fix" A so it can be compared to B How do we "Fix" A? Make sure to reassign the value to A Tell me how many elements of A are greater than or equal to B This can be done in a single line. You will...

  • Self-check exercise: While-loops The value of (π^2)/8 can be approximated by the series Write a script...

    Self-check exercise: While-loops The value of (π^2)/8 can be approximated by the series Write a script that evaluates this expression, ignoring all terms that are strictly smaller than .000001. Your script should display the number of terms summed and the sum. Use a while-loop. Think about the initialization of your variables and the order of computation carefully! In the loop body you need to calculate the value of a term only once. We use the above series for approximating (π^2)/8...

  • How do your write this in Matlab. Create a program that takes as input: An integer...

    How do your write this in Matlab. Create a program that takes as input: An integer nFunction that is either 1 or 2 indicating which of the two functions below to nsc * An integer n in [1.oc) indicating how many data points (ro."). ·The left endpoint a of an overall interval. (n泓) tote. The right endpoint b of an overall interval Your program should find the interpolating polynomial of degree less than or equal to of the requested function...

  • 2. Write a question for Newton-divided difference interpolation. Then, solve it theoretically. After solving it, write...

    2. Write a question for Newton-divided difference interpolation. Then, solve it theoretically. After solving it, write a MATLAB code for this question which returns either an estimation for a value or the polynomial coefficients of ',x1, x²,..., respectively, Instructions: . You do not need to create built-in function. You may study on a script, • You have already known your table, which is written as a question. Using this table, write a code which returns either an estimation for a...

  • Use Python Write a script to perform various basic math and string operations. Use some functions...

    Use Python Write a script to perform various basic math and string operations. Use some functions from Python's math module. Generate formatted output. Basic math and string operations Calculate and print the final value of each variable. a equals 3 to the power of 2.5 b equals 2 b equals b + 3 (use +=) c equals 12 c = c divided by 4 (use /=) d equals the remainder of 5 divided by 3 Built-in functions abs, round, and...

  • 2. [5pts] Write a MATLAB script that can calculate the equivalent resistance in a circuit that all electrical resis...

    2. [5pts] Write a MATLAB script that can calculate the equivalent resistance in a circuit that all electrical resistors are connected in parallel: . Print the title 'Equivalent Resistance for Resistors Connected in Parallel' on your output. . Check the size of vector resistor to see how many resistors in the circuit. .Check each individual resistance to see any 0 or negative resistance. If there is any, print message 'ERROR', then finish the program. . Otherwise, calculate the equivalent resistance...

  • DO THIS IN MATLAB PLEASE DO THIS IN MATLAB Create a script file that performs the...

    DO THIS IN MATLAB PLEASE DO THIS IN MATLAB Create a script file that performs the following calculations. Your script will use the functions you create. Label all graphs appropriately. For this project, do not have your homemade functions fprintf anything, instead have all your fprintf commands within your script. Attach your published script file along with .m files for your functions. Exercise 1. A fundamental iterative method for finding the roots of equations of one-variable is known as Newton's...

  • Write a MATLAB script named Converter.m and MATLAB two functions, each in its own script, named...

    Write a MATLAB script named Converter.m and MATLAB two functions, each in its own script, named D2BConverter.m and B2DConverter.m The Selection Output should be the following: Binary to Decimal & Decimal to Binary Converter Please Select: 1. Convert from Decimal To Binary 2. Convert from Binary To Decimal 3. Exit If user select option [1] then you ask the user to enter a decimal number (whole number) and display the equivalent binary, else if the user select option [2] then...

  • X) -1-2! +41-614 (2k)! k=0 he actual Write a script that will determine how many terms are needed...

    x) -1-2! +41-614 (2k)! k=0 he actual Write a script that will determine how many terms are needed in the series to get the error between t value and the estimate to be less than 0.0001. The user should input the value of x and a formatted print statement should be used to display the result. Use a while loop to complete this problem. Note: error I(cos 2x)actual - (cos 2x)estimatel. See below for an example. Enter a value of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT