最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

math - Finding Antilog in javascript and solving polynomial equation of n degree in javascript - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited May 25, 2011 at 12:50 Bill the Lizard 406k212 gold badges574 silver badges892 bronze badges asked May 20, 2011 at 12:36 YashpritYashprit 5221 gold badge8 silver badges22 bronze badges 2
  • eh? Why the change of heart. The now accepted answer is wrong... – Naftali Commented Apr 19, 2012 at 12:54
  • i posted one question nobody is giving me answer saying you have less accepted rate. i am very much frustrated with this munity seems like this place is only for those who have brilliant skills in puter science not the person like me who are no-voice in this field – Yashprit Commented Apr 19, 2012 at 16:36
Add a ment  | 

3 Answers 3

Reset to default 3

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 e 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)

  1. 暂无评论