Question: Using MATLAB , Write a function posnum that prompts the user to enter a positive number and loops to error-check. It returns the square root

Using MATLAB,

Write a function posnum that prompts the user to enter a positive number and loops to error-check. It returns the square root of the positive number entered by the user. It calls a subfunction in the loop to print an error message. The subfunction has a persistent variable to count the number of times an error has occurred. Here is an example of calling the function:

>> squarerootvalue = posnum

Enter a positive number: -5

Error #1: Follow instructions!

Does -5.00 look like a positive number to you?

Enter a positive number: -33

Error #2: Follow instructions!

Does -33.00 look like a positive number to you?

Enter a positive number: 4

squarerootvalue = 2

Step by Step Solution

3.28 Rating (145 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

function to find the squaroot of a number function squarootvalue posnum n inputEnte... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!