Yashprit
Yashprit

Reputation: 522

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 in JavaScript? Is there any function by which I can find the antilog of any number?

Upvotes: 1

Views: 6352

Answers (3)

trusktr
trusktr

Reputation: 45504

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.

Upvotes: 0

Bill the Lizard
Bill the Lizard

Reputation: 405995

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.

Upvotes: 3

Naftali
Naftali

Reputation: 146350

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

Upvotes: 2

Related Questions