how can i evaluate e^x using maclaurin expansion?
Show older comments
I already have the factorial function
Answers (1)
Torsten
on 30 Oct 2014
0 votes
Don't use factorials explicitly ; define the terms of the Taylor series recursively:
x=2;
n=10;
y=1;
summe=y;
for i=1:n
y=y*x/i;
summe=summe+y;
end
The variable 'summe' will contain an approximation to exp(x).
Now try to include an estimate for n such that
abs(sum_{i=0}^{n} x^i/i! - exp(x)) < eps
for a prescribed accuracy eps > 0.
Best wishes
Torsten.
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!