next up previous
Next: About this document ...

ESC 251 HW 9 Due: Sep. 24

Remember to indent the bodies of your IF-THEN blocks.

1)
(3 pts) An important application of IF-THEN statements is error checking. Error checking means that you take steps to ensure that a calculation won't fail before attempting to perform it. Examples of this include dividing by zero, taking the square root of a negative number, taking the log of a negative number, etc.

Write a MATLAB script program that will ask the user to input 2 values a and b. If it is feasible to do so, the program should compute the quotient $\displaystyle {\frac{a}{b}}$ and display the result. Otherwise, the program should print out an appropriate error message. Devise 2 test cases that will test each branch of your IF-THEN statement.

2)
(3 pts) Write a MATLAB script that will read in a value from the keyboard and print out a message telling the user whether the value is either even or odd. Th mod function will be useful here.
3)
(3 pts) NOTE: You should assume that you are working with real (not complex) numbers for this problem. Write a program that will ask the user to input a value x and test if the function

\begin{displaymath}y = \ln \left( \frac{1}{x^2 + x - 6} \right) \end{displaymath}

can be computed for that value of x. If y can be computed, the program should print the corresponding value of y. If y cannot be evaluted, the program should print out an appropriate error message. Test your program for two values of x that work and one that does not.



next up previous
Next: About this document ...
2018-09-21