How to create a pow() function? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 5

How to create a pow() function?

I want to create a pow function to return a^b, but also want it to return a correct value if b<0, like 1/2, 1/3, 1/4 etc... How can I achieve this via a for loop? How to multiply 5 , 0.4325 times?

3rd Apr 2017, 9:51 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
6 Réponses
+ 8
Find the Taylor expansion of the function x^b and calculate the polynomial. You need to know the derivative of x^b which is b*x^(b-1).
3rd Apr 2017, 11:53 AM
Karl T.
Karl T. - avatar
+ 8
No problem, here's a nifty tool to calculate Taylor series of a function: http://www.wolframalpha.com/widgets/view.jsp?id=f9476968629e1163bd4a3ba839d60925
3rd Apr 2017, 12:22 PM
Karl T.
Karl T. - avatar
+ 4
Thank You, @JPM7
3rd Apr 2017, 11:48 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 3
Yes, this exists, but what if I want to define it myself?
3rd Apr 2017, 10:03 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 3
@Frost How will that work differently w.r.t. a for loop? What change will I bring each time?
3rd Apr 2017, 10:18 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 3
@Helioform Thank You!!
3rd Apr 2017, 12:14 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar