Question

Write a function that accepts as input a scalar x and an integer n and computes f(x), where

f(x) = 1 + x + ... + x^n.

For example, if x = 2 and n = 3, the function should return 1 + 2 + 4 + 8 = 15.

Hint: Use point-wise operations and the MATLAB sum function.

Your Function 1 1 function yf(x) 3 end Code to call your function

0 0
Add a comment Improve this question Transcribed image text
Answer #1
% Your Function
function y=f(x, n)
    y = 0;
    for i=0:n
        y = y+x^i;
    end
end

% Code to call your function
f(2, 3)
Add a comment
Know the answer?
Add Answer to:
Write a function that accepts as input a scalar x and an integer n and computes f(x), where f(x) = 1 + x + ... + x^n. For example, if x = 2 and n = 3, the function should return 1 + 2 + 4 + 8 = 15. Hi...
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