Question

USING MATLB PLEASE SHOW commands and output. QUESTION 1. Create a function sumcomp that compares the...

USING MATLB

PLEASE SHOW commands and output.

QUESTION 1. Create a function sumcomp that compares the sum of all the odd-indexed elements with the sum of all the even-indexed elements and returns:

0, if they are equal,

1, if the sum of the odd-indexed elements is greater,

2, if the sum of the even-indexed elements is greater

0 0
Add a comment Improve this question Transcribed image text
Answer #1
function result = sumcomp(lst)
    oddSum = 0;
    evenSum =0;
    result =0;
    for i=1:length(lst)
        if(mod(i,2) == 0)
            evenSum = evenSum + lst(i);
        else
            oddSum = oddSum + lst(i);
        end
    end
    if(oddSum == evenSum)
        result = 0;
    elseif(oddSum > evenSum)
        result = 1;
    else
        result = 2;
    end
end

Add a comment
Know the answer?
Add Answer to:
USING MATLB PLEASE SHOW commands and output. QUESTION 1. Create a function sumcomp that compares the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT