You are on page 1of 1

FUNCTION #1a

1. In this assignment, you are to create a matlab function that has the following form:
function [K y] = FindMaxJump(x)
where the lone input argument x is a vector of real numbers. The outputs describe where in
vector x the maximum jumps occur for consecutive vector elements. That is, the output K is
the size of the maximum jump and the vector y are the left-hand-side indexes where the
maximum jump(s) occur. It is possible that the vector may have more than one jump at the
maximum so the vector y may have more than one index value.
For example, if
x = [1 2 5 0 2 3];
Then the maximum jump occurs between the 3rd and 4th elements where the jump is -5
when stepping from left to right. It doesnt matter if the jump is positive or negative when
looking at the vector from left to right. The function should output
K = 5;
as well as the vector
y = [3];
where the 3 indicates the left index of where the jump occured
As a second example, the input vector
x = [1 3 4 2 3];
should give rise to the outputs
K = 2; y = [1 3];

Remember that matlab requires that the function name and the file name be the same. That is,
the function must be put in the file with name:
FindMaxJump.m
Solve the problem using the more direct approach using constructs such as
for ... end, if ... else ... end, etc.

2. Variable checking: If the x vector is empty or has only one element, return the empty vector
for both K and y.

3. Grading: When your code is completed and tested, upload it to the LIBRARY & GRADE
website and grade it. This only grades the program results.
Once your function is writen, go back to the grade rubrics and make sure your code conforms
to the grade components described.

You might also like