Rewrite the MATLAB user-defined function mybab(x), which was developed earlier i
ID: 3804771 • Letter: R
Question
Rewrite the MATLAB user-defined function mybab(x), which was developed earlier in class and returns the squareroot of a number using the Babylonian method, in such a way that it will now include a check for the error in user input, or so called "error-trap". This function will return two values, the squareroot and an integer error code. Identify all possible cases of user input error. You can use the following MATLAB built-in functions is char (x) which will return 1 if x is a character string, and zero otherwise sire X (n) which will return 1 if n is a real number, and zero otherwise y = is char ('My Name'); % This will make y = 1 a = 3.5; z = is real(a); % This will make z = 1Explanation / Answer
We sould find if the given input x is real number or not. The default isreal function will return 1 even for char strings like 'hello'.
if(ischar(x)==1 || isreal(x)==0)
disp("Error occured")
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.