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

In Matlab Loop/Array Test Practice 2 Write a function that has two inputs, an ar

ID: 3595643 • Letter: I

Question

In Matlab

Loop/Array Test Practice 2 Write a function that has two inputs, an array called array and an integer multiple, and one output, an integer summation. Your program should look through an array and sum all of the numbers that are multiples of multiple. If there are no multiples of multiple, return 0 For example, if you function took the inputs: array = [1 2 3 4 5 6 7 8 9 101; multiple = 5; It would return: summation = 15 Recall that you can use the built-in functions rem(m,n) or mod(m,nto find the remainder of the division m/n.

Explanation / Answer

function summation = total(array, multiple)
l = length(array)
summation = 0
for i = 1:l
if mod(array(i), multiple) == 0
summation = summation + array(i)
end
end
end

array = [1 2 3 4 5 6 7 8 9 10];
multiple = 5;
total(array, multiple)

Output:

octave: X11 DISPLAY environment variable not set
octave: disabling GUI features
l = 10
summation = 0
summation = 5
summation = 15
ans = 15

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote