Often I end up using Math.sqrt in projects whenever I need to get the square root of a number. However what if I want the nth root of a number? Such as the cubed root of a number, or any other degree beyond of that of just the number 2 that is what I am set with when using the Math sqrt method. I can not say that I end up having to use this kind of method that often, but still there does not seem to be a built in mMath object method for it.
One solution is to use the Math.pow method to get the nth root of a given root number and degree. This works by just passing the root number as the base for Math.pow, and then diving 1 by the degree number to get the exponent argument for the Math pow to get a value that can be the return value for nth root.
So there we have it a basic nth root method that seems to work they way it should. However what is the big deal with nth root? Is there some kind of project where a Math method such as this would come into play? I Guess now it is a question of looking for and see about making artful and practical use case examples of nth root.
I am sure that there are many use case examples of nth root, but I would not be surprised if the bulk of them are artful examples rather than ones that might prove to be useful for some kind of real problem. Artful examples can often prove to be piratical examples actually I suppose of what it is that I am workong on is some kind of artful thing when it comes to finding ways to use the nth root method for such projects. There is however at least a few practical examples of nth root however.
When it comes to using the Math.pow method the first argument that is given is a base, and the second argument that is given is an exponent. The resulted result of calling this method is then a power that is the given base that is then raised to the given exponent. So then there is the question of getting into inverse functions for this function, that is having a function where if the exponent is known, but not the base, having a function where I can pass the power and the exponent to have the base returned.
There is also the question of how to go about making another kind of function that will give me the exponent when all I know is the base and the power. I have found that the Math log method can be used to make this kind of method.
One such example might have to do with compounding interest and that can often prove to be useful when it comes to figuring out something g that has to do with money, regardless of it is game money or real worked money. For example what if I want to know an interest rate that I need to see in order to double an investment of one hundred dollars over say seven years? I can pass 2 for the value of n, and 7 for the degree and get a value of around 1.104, or in another way 10.4%. I can then confirm this by using that value with the Math.pow method to see if it results in double the money, and when I do it indeed does given me just that.
I can not say that I end up using this often in projects, but it is something that I think about now and then. If I find out some other ways to go about using nth root in projects that are helpful, or at least interesting I will be sure to update this post.
There is just having the basic idea at the ready though, which is one reason why I wrote this post. I like to have methods like this at the ready. In time I hope to find, and or make interesting code examples that make use of nth root and other Math methods. I am sure that there is some fun and interesting things that can be done with it when it comes to something artful.