Question
MATLAB You've recently looked at 'while' loops in Matlab. Break statements can be contained within 'while' loops to exit the loop early. Look at the
MATLAB
You've recently looked at 'while' loops in Matlab. Break statements can be contained within 'while' loops to exit the loop early. Look at the following example code:
x=-10;
while x<0
x=x+2;
if x == -2
break;
end
end
Without the break statement, the while loop would usually add 2 to x=-10 until x=0, and then produce a final answer of x=0 at the end of the loop. Now, the loop ends prematurely when the value of -2 is given to x.
Following this example. come up with a code while loop that calculates multiple powers of 2, i.e. (2^1, 2^2, 2^3...). Your while loop should calculate up to 2^30
Provide a break statement that stops the code at the value 1048576, which is equal to 2^20
To complete this quest, answer the following questions in the submission box below.
- Upload a word document of your code that contains a while statement calculating 2^30, with a break statement that exits the while loop at 2^20.
- Keep in mind that the screenshot must also include a timestamp showing when you completed the quest.
(For more information see the "Engineering Tools - MATLAB" chapter from Pathfinder)
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