I'm trying to make the code below work by modifying it so that e^-x will work, essentially I'm trying to modify it so that e^-x is 1/e^x I'm really not sure how to do that..Here is my code..
function [result] = eTaylor(x, n)
% approximate e^x
% using first n non-zero terms of the Taylor series
% e^x = 1 + x + x^2/(2!) + x^3/(3!) + x^4/(4!) + ...
% Input arguments:
% x = real argument to function e^x
% n = number of non-zero terms of Taylor series
result = 0.0; term = 1.0;
for i = 1:1:n
result = result + term;
term = term*x/i;
end