I need to implement a script that calculate the Taylor series expansion of e^x. There are two inputs: n = the number of terms in the expansions, and tolerance = basically the percent change in adding one more term.
In other words, the tolerance = | (sum_previous – sum_new) / sum_previous | < 0.000001
So the user inputs the number of terms to be added, and they specify a tolerance. I am not sure how to get the while loops to work correctly. Here's what I have so far:
old_sum = 1;new_sum = 0;steps = 0;approx = 0;i = 0;while (abs((old_sum-new_sum)/(old_sum)))>= tolerance old_sum = (x^i)/myFactorial(i); new_sum = new_sum + old_sum; i = i + 1; steps = steps + 1;end
Best Answer