The following built-in MATLAB functions and commands are permitted for this assignment.
Vector/Matrix
Flow Control
Strings and Character Arrays
Other
Points will be deducted from any programs using functions outside this list.
AI for any part of this problem.function_name.m, where each function_name is listed below.list_sum
| Inputs: | list (1 x N) double vector.
|
| Outputs: | |
| Details: | |
βΈ Do NOT use MATLABβs sum command.
|
S = list_sum([2 1 3 -1])
% should return S = 5
S = list_sum([-2 1 0 -8 10 9 0 3.22 9 -1 -100 9.54])
% should return S = -69.2400
list_is_nonnegative
true if a list contains no negative numbers. The list may have any length.
| Inputs: | list (1 x N) β list of numeric values (doubles)
|
| Outputs: | |
| Details: | |
βΈ No other built-in MATLAB commands are allowed.
|
|
βΈ Zero is a non-negative number.
|
result = list_is_nonnegative([111 -90 20 66 -167 42])
% returns false (0)
result = list_is_nonnegative([1 1 1 0 1 2 3 9 7 5 0 9 9 4])
% returns true (1)
list_occurrences
| Inputs: | list (1 x N) double vector
|
| Outputs: | |
| Details: | |
βΈ No other built-in MATLAB commands are allowed.
|
num_count = list_occurrences([1 1 1 -9 0 0 6 6 -1 6 7 1 2], 1)
% returns 4
num_count = list_occurrences([1 1 1 -9 0 0 6 6 -1 6 7 1 2], -6)
% returns 0
list_sign_change_count
| Inputs: | list (1 x N) double vector
|
| Outputs: | |
| Details: | |
βΈ Changing from a positive or negative to a zero does not count as a change of sign.
|
|
βΈ Only count changes between adjacent numbers.
|
count = list_sign_change_count([1 -1 1 -9 6 6 -1 -2 4])
% returns 6
count = list_sign_change_count([1 1 1 -9 0 0 6 6 -1 6 7 1 2])
% returns 3
get_direction
position_old and the final position position_new. The direction must be one of the eight cardinal directions:
| Inputs: | position_old (1 x 2) double vector β contains the (x, y)-coordinates of the initial position
|
position_new (1 x 2) double vector β contains the (x, y)-coordinates of the final position
|
|
| Outputs: | direction (1x1) or (1 x 2) character vector β indicating the movement direction
|
| Details: | |
βΈ Any movement in a primary direction should be reflected (for example, moving 10 units north and only 0.1 units west should return 'NW')
|
|
βΈ Use an if-statement.
|
direction = get_direction([2 1], [3 1])
% returns 'E'
direction = get_direction([-2 1], [0 -8])
% returns 'SE'
direction = get_direction([8 -2], [-2 5])
% returns 'NW'
direction = get_direction([0 -2], [0 -2])
% returns ''