Advertisement
aalhendi

IC3_3

Jan 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.50 KB | None | 0 0
  1. function [ estimate ii ] = exp_taylor(x,x0,tol)
  2. %Group 1
  3.  
  4. %Intialization
  5. f_x = exp(x0); % This cancels the need for derivatives because d/dx of e^x = e^x
  6. err = tol + 1;
  7. estimate = 0;
  8. ii = 0;
  9.  
  10. %Loop
  11. while err > tol
  12.     lastestimate = estimate;
  13.     estimate = estimate + (f_x./factorial(ii).*((x-x0)^ii));
  14.     err = abs(estimate - lastestimate);
  15.     ii = ii+1;
  16.    
  17. end
  18.  
  19. ii
  20.  
  21. end
  22.  
  23. % for x = 1, e = 2.7183, ii = 11
  24. % for x = 5, e = 148.4132, ii = 24
  25. % for x = 10, e = 2.2026e+04, ii = 38
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement