Question

Use a while-end loop in a script file to calculate
0 0
Add a comment Improve this question Transcribed image text
Answer #1

In the following Im adding the scripts along with sample output which solves the requirements Part a: Coding function [outpu

function [output] = Summation(n)

    disp(['for n = ' num2str(n)])

    sumI = 0;

    while n>0

        sumI = sumI + (((-1).^n*n.^2 + 5*n )/3.^n);

        n=n-1;

    end

    output = sumI;

end

Summation(10)

Summation(20)

%--------------------------------------------

function [output] = Summation(n)

    disp(['for n = ' num2str(n)])

    sumI = 0;

    for k=1:1:n

        sumI = sumI + (((-1).^k*k.^2 + 5*k )/3.^k);

    end

    output = sumI;

end

Summation(10)

Summation(20)

Add a comment
Know the answer?
Add Answer to:
Use a while-end loop in a script file to calculate the sum of the first n...
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