I have a polynomial equation which needs to be solved programmatically. The equation is as below.
x/207000 + (x/1349)^(1/0.282) = (260)^2/(207000*x)
I need to solve for x. I am using javascript for this. Is there any library in javascript which can solve mathematical equation?
I have a polynomial equation which needs to be solved programmatically. The equation is as below.
x/207000 + (x/1349)^(1/0.282) = (260)^2/(207000*x)
I need to solve for x. I am using javascript for this. Is there any library in javascript which can solve mathematical equation?
Share Improve this question asked Mar 15, 2017 at 21:26 AmrAmr 813 silver badges15 bronze badges 1-
x/207000 + (x/1349)^(1/0.282) = (260)^2/(207000*x)
is not a polynomial equation because(260)^2/(207000*x)
is not a polynomial. – Anderson Green Commented Aug 10, 2019 at 17:55
3 Answers
Reset to default 4Some puter algebra systems in JavaScript can solve systems of polynomial equations. Using Algebrite, you can solve an equation like this one:
roots(x^2 + 2x = 4)
The roots of this equation are [-1-5^(1/2),-1+5^(1/2)]
.
It's also possible to solve systems of polynomial equations using Nerdamer. Its documentation includes this example:
var sol = nerdamer.solveEquations('x^3+8=x^2+6','x');
console.log(sol.toString());
//1+i,-i+1,-1
There are JavaScript solvers out there that will numerically solve your problem. The non-linear solver that I know of is Ceres.js. Here is an example adapted to your question. The first thing we have to do is rearrange to the form F(x)=0.
x0 = 184.99976046503917
async function ceresSolve(jsonSystem) {
const {Ceres} = await import('https://cdn.jsdelivr/gh/Pterodactylus/Ceres.js@latest/dist/ceres.min.js');
let solver = new Ceres()
let results = await solver.run(jsonSystem);
console.log(results.x) //Print solver results
console.log(results.report) //Print solver report
}
let jsonSystem = {
"variables": {
"x": {
"guess": 1,
},
},
"functions": [
"x/207000+(x/1349)^((1/0.282))-((260)^2/(207000*x))",
],
}
ceresSolve(jsonSystem) //Call the function
Try math.js
http://mathjs/
It allows you to do mathematical functions in a much cleaner look.