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

Write a function named Gauss() that takes x and n as arguments and that returns

ID: 3734195 • Letter: W

Question

Write a function named Gauss() that takes x and n as arguments and that returns the sum of the first n terms of the series. You should not use factorial() or pow().

2 Exercise 6.4 One way to evaluate e is to use the infinite series expansion e-z-1-2x + 3x2/21-4x3/31 + 5x4/41-... In other words, we need to add up a series of terms where the ith term is equal to (-1), (1)Xi/i!. Write a function named Gauss() that takes x and n as arguments and that returns the sum of the first n terms of the series. You should not use factorial() or pow().

Explanation / Answer

function res = Gauss(x, n)
    res = 0;
    sign = 1;
    p = 1;
    f = 1;
    for i=0:n-1
        term = sign*(i+1)*p/f;
        res = res+term;
        p = p*x;
        f = f*(i+1);
        sign=-1*sign;
    end
end

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