开发者

Finding Antilog in javascript and solving polynomial equation of n degree in javascript

Can anybody tell me how to solve polynomial equation of n degrees in JavaScript? Also how can I find antilogs 开发者_如何学JAVAin JavaScript? Is there any function by which I can find the antilog of any number?


To find the antilog(x) you just raise your base (usually 10) to the power of x. In JavaScript:

Math.pow(10, x); // 10^x

If you have another base, just put it in place of 10 in the above code snippet.


Math.pow(x,y);// x^y

Thats for polynomials

Math.log(x);

Thats for logs.

Math.pow(10,x); Thats for antilog

You have to come up with some function to solve antilog


const e = Math.exp(1)

function antilog(n, base = e) {
  if (base === e) return Math.exp(n)

  return Math.pow(base, n)
}

Math.log() uses base e. Math.exp(1) gives you the value of e.

This antilog function is nice because it has the opposite API of the following log function:

function log(n, base = e) {
  if (base === e) return Math.log(n)

  return Math.log(n) / Math.log(base)
}

I like these functions because they lead to cleaner code:

const a = log(someNumber)
const b = antilog(someNumber)

and when you want to work with a different base, no need to write math expressions:

const a = log(someNumber, 10)
const b = antilog(someNumber, 10)

Compare that to arbitrarily having to, or not having to, write:

const a = Math.log(someNumber)
const b = Math.exp(someNumber)

or

const a = Math.log(someNumber) / Math.log(10)
const b = Math.pow(10, someNumber)

log and antilog are more readable, easier.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜