% MatLab function for part 1 of the question for the CSC 336 tutorial % on 29 Sept. 2007. % % This function approximates e^x by summing the series % 1 + x + x^2/2! + x^3/3! + ... % from left to right until the value of the sum does not change. % % K.R.J. 24 Sept. 2007 function y = exp1(x) sumold = 0; sum = 1; k = 0; term = 1; % term will be x^k/k! We increment each time around the % while look to avoid having to recompute x^k/k! while sumold ~= sum, sumold = sum; k = k+1; term = term * x / k; sum = sum + term; end y = sum;