All problems
Maclaurin Polynomial for Exponential
Problem
Evaluate the degree-n Maclaurin polynomial of f(x) = e^x at the point x:
P_n(x) = sum from k = 0 to n of x^k / k!
Build the terms iteratively rather than using a factorial library.
Hint
Each new term is the previous term times x / k; add as you go.
Test cases
case 1
in: [1,5]
expected: 2.7166666666666663
case 2
in: [0,3]
expected: 1
case 3
in: [2,0]
expected: 1
case 4
in: [-1,4]
expected: 0.37500000000000006
case 5
in: [1,10]
expected: 2.7182818011463845
Starter codePython
def maclaurin_exp(x, n):
# Your code here
pass5 test cases · run your code against them in the editor