In this exercise, you will be creating a function trough_error that will assign
ID: 3585544 • Letter: I
Question
In this exercise, you will be creating a function trough_error that will assign a message based on the input vector y.
Note that we can assign a message by typing: message = 'type message here'
Function Process:
The initial value for y and the final value for y should be equal within a tolerance of 10-3. If they are not, the message should say 'Warning: Trough Area is invalid since shape does not close properly'. If the final y value is within tolerance, you should then check whether any of the other values in y (excluding the initial and final values) are greater than the initial value for y. If this condition is met, the message should be 'Warning: Trough Area will be incorrect since y exceeds y0 at a certain point'. If neither of these conditions are met, the message should be 'Trough Area is valid'.
Potentially Useful Functions: if, elseif, else, abs, max, end
Function Template
function message = trough_error(y) %insert code end
Explanation / Answer
function message = trough_error(y)
if(abs(y0-yf)<10-3)
message='Warning: Trough Area is invalid since shape does not close properly';
elseif (y > y0)
message='Warning: Trough Area will be incorrect since y exceeds y0 at a certain point';
else
message='Trough Area is valid';
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.