Skip to content

Instantly share code, notes, and snippets.

@drusepth
Created February 20, 2014 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drusepth/9109417 to your computer and use it in GitHub Desktop.
Save drusepth/9109417 to your computer and use it in GitHub Desktop.
## Author: Andrew Brown
## Created: 2014-02-11
## Estimates ln(x) with Taylor series
function void = taylor_log (x)
# Estimate value with Taylor series
approx = x - 1
tic
for term_index = 1 : 100
approx += ((-1)^term_index)*((x-1)^(term_index+1))/(term_index+1);
end
toc
fprintf('ln(%f) approximated to be %f\n', x, approx);
fprintf('ln(%f) is actually %f (off by %f)\n', x, log(x), abs(approx - log(x)));
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment