Question: Write a short piece of MATLAB code that will: Ask a user for a value, R. Generate the message: The square root of X.XXX is
Write a short piece of MATLAB code that will:
Ask a user for a value, R.
Generate the message: The square root of X.XXX is Y.YYY, if R is non-negative.
If R is negative, the code should generate the message: R is negative. The square root of X.XXX is Y.YYYi [imaginary number]
The value of R should be substituted for X.XXX, and the value of the square root of the magnitude of R should be substituted for Y.YYY. Both numbers should be displayed with three decimal places. For this question, use values where -10 < R < 10.
HINT: Need to use input statement and if / else statement to make sure values are within range. If not in range, print out error message using error (error message) statement. Use fprintf for output.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
