MATLAB: Taylor series while loop

basicsiterationtaylor serieswhile loops

Thanks for the help!

Best Answer

You code is quite good. You made three error:
  • the sign of term must change at each iteration
  • in term again, the power of x is odd (2*k+1)
term = (-1)^k * x^(2*k+1)/factorial(2*k+1);
  • Pn is the result you're calculating. It's what you want to display, not term.