Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matlab question In this exercise, you will be creating a function trough_error t

ID: 3586164 • Letter: M

Question

Matlab 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

only one file can be sumbitted

Explanation / Answer

Solution==============================

function [ ] = trough_error( y )
%Display error message if y is not as per conditions
%Else gives OK message

if (abs(y(1)-y(end))>0.001) %outside of tolerance
    message='Warning: Trough Area is invalid since shape does not close properly';
    msgbox(message);            %display this message if trough area is invalid
    return;
end

if (sum(y(2:end-1)>y(1))>0) %if there is some value greater than initial value
    message='Warning: Trough Area will be incorrect since y exceed y0 at certain point';
    msgbox(message);        %display this message if trough area is invalid
    return
end

message='Trough Area is valid'; %if area is valid
msgbox(message);                %display this message
end