In this assignment you are to create a matlab function that

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 doesn’t 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]; If the x vector is empty or has only one element, return the empty vector for both K and y. 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.

Solution

Code:

function [K y]=FindMaxJump1(x)

% Calculating jump between consecutive elements

for i=1:1:length(x)-1

jump(i)= abs(x(i)-x(i+1));

end

  

% Finding Minimum Jump

Max_Jump=-Inf;

for i=1:1:length(jump)

if Max_Jump< jump(i)

Max_Jump=jump(i);

end

end

% Calculting y Matrix

s=1;

for i=1:1:length(jump)

if jump(i)==Max_Jump

y(s)=i;

s=s+1;

end

end

K=Max_Jump

y

end

Output:

>> x = [1 3 4 2 3];

>> FindMaxJump1(x)

K =

2

y =

1 3

----------

>> x = [1 2 5 5 0 2 3 3];

>> FindMaxJump1(x)

K =

5

y =

4

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
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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site