Posts

Showing posts from April, 2021

Taylor Series by Horner's Rule (Using Recursion and loop) in C++

Image
 The value of the Exponential function can be calculated using Taylor Series. Taylor series is …  e^x = 1 + x/1! + x^2/2! + x^3/3! + x^4/4!...... Now consider, the 1st term i.e.  1  - No multiplications here. 2nd term i.e.  x/1!  -  No multiplications here too 3rd term i.e.  x^2/2!  -  Two multiplications here    (x*x / 1 * 2) 4th term i.e.  x^3/3!   -   four multiplications here    (x * x * x / 1 * 2 * 3) 5th term i.e.  x^4/4!   -   six multiplications here    (x * x * x * x / 1 * 2 * 3 * 4) So, if we go till 4th power of x in Taylor series we have to do 2+4+6 = 12 multiplications. So this number of multiplications will take us   O(n^2)   time.  But we can reduce the no. of multiplications by using the Horner's rule. Horner's Rule is just to take common variables and constants outside of the bracket so as to reduce the power the inside the bracket. We can co...