The program calculates e^x by adding terms of the series and stopping when the absolute value of the term that was added last is smaller than 0.0001. Use a while-end loop, but limit the number of passes to 30. If in the 30th pass the value of the term that is added is not smaller than 0.0001, the program stops and displays a message that more than 30 terms are needed.
clearclcfprintf('Solving e^x using Taylor Series\n');x=input('x = ');n=30; i=0;f=1;while i<n || i==n f=f+(x.^i)/factorial(i); i=i+1;endy=f-1
This is where I am stuck, I don't know how to limit the n to 30 and how can I make a condition that if the value of the term is smaller than 0.0001 it will stop.
Any help would be appreciated, Thank you!
Best Answer