Question: Write a while-loop in MATLAB that creates an array x using the following algorithm: It creates a single random number It checks if the random
Write a while-loop in MATLAB that creates an array x using the following algorithm: It creates a single random number It checks if the random number is bigger or equal than zero and less than 0.5, or if it is bigger than 0.5 and less or equal to 1. o If it bigger or equal than zero and less than 0.5, make the value of x at the location defined by the iteration number of the while loop equal to the last previous value of x plus 1 o If it is bigger than 0.5 and less or equal to 1, make the value of x at the location defined by the iteration number of the while loop equal to the previous value of x minus 0.5 o If it is the first iteration run, which means the first value of x will be defined, make the first value of x equal to zero. To stop the while loop, check for one of these two conditions: o If the while loop has run for 50 or more, break the while loop and let the code finish o If the last six values of x are positive, then leave the while loop
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
