I want to write a program to find e^x using Taylor series representation.The limit of the number of passes is 30.When the absolute value of last added term is smaller than 0.0001 adding should be stopped.This should be handled using a while loop.And if in the 30 th pass the value of added term is not smaller than 0.001 a message should be diaplayed. I've tried it myself.But it doesn't seem to be working.Following is my code.
function exponen(x) clceX=1; %when x=0;
y(n+1)=x^(n+1)/factorial(n+1);while abs(y(n+1))>0.0001 for n=0:30 eX=eX+sum(y); if abs(y(31))<0.0001 fprintf('The answer is %.5f',eX); else fprintf('More than 30 terms are needed'); end endendend
Best Answer