In this code, you will be evaluating the minimum value of an input vector, provi
ID: 3144629 • Letter: I
Question
In this code, you will be evaluating the minimum value of an input vector, provided there are three values in it.
Inputs:
Vector - A vector that contains three elements within it.
Outputs:
Minimum - The minimum value in Vector.
Process:
In this exercise, you will be using two if statements to find the minimum value of a three element vector. The steps are given below.
Step 1: Make Minimum equal the first element of the input vector.
Step 2: If the second element of the input vector is less than Minimum, make Minimum equal the second element of the input vector.
Step 3: If the third element of the input vector is less than Minimum, make Minimum equal the third element of the input vector.
Note: The following functions are banned in this exercise: min, max, sort, elseif, else.
Function Template:
function Minimum = min3(Vector)
%INSERT CODE
end
Explanation / Answer
Following MATLAB code will give the intended result
function Minimum = min3(vector)
vetor = input('Enter a vector of three elements')
min=vetor(1)
if (vector(2)<vector(1))
min=vector(1)
if (vector(3)<vector(2))
min=vector(2)
end
end
return
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.