Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ estimate ii ] = exp_taylor(x,x0,tol)
- %Group 1
- %Intialization
- f_x = exp(x0); % This cancels the need for derivatives because d/dx of e^x = e^x
- err = tol + 1;
- estimate = 0;
- ii = 0;
- %Loop
- while err > tol
- lastestimate = estimate;
- estimate = estimate + (f_x./factorial(ii).*((x-x0)^ii));
- err = abs(estimate - lastestimate);
- ii = ii+1;
- end
- ii
- end
- % for x = 1, e = 2.7183, ii = 11
- % for x = 5, e = 148.4132, ii = 24
- % for x = 10, e = 2.2026e+04, ii = 38
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement