Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
99
rated 0 times [  101] [ 2]  / answers: 1 / hits: 32263  / 14 Years ago, wed, december 22, 2010, 12:00:00

Is there a JavaScript library or function that will solve equations for variables?



Such as 9 = 3 + x and solve for x. But it should also solve more advanced equations that include sine, cosine, and tangent.


More From » equation

 Answers
43

You can approximate the solution by doing what excel calls Goal Seek - testing values for x until both sides of the equation approximately match. You can do this by splitting the equation by the = sign, replacing each occurence of x with a value, evaling both sides, and determining if the difference falls below a certain threshold. While relatively simple, there are flaws to this method though (other than the fact that it is an approximation), for example the algorithm may think the two sides are converging when in fact it is just a local min/max and will diverge after the difference falls just below your threshold. You'll also need to test multiple start points to solve equations with more than one solution.



For a program to actually solve an equation as a human would (by rearranging the two sides of the equation and applying inverse functions, derivatives/integrals and whatnot) is far more complex, and somehow feels entirely proprietary ;)


[#94514] Monday, December 20, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
freddiejarretk

Total Points: 612
Total Questions: 103
Total Answers: 88

Location: Armenia
Member since Sat, Dec 31, 2022
1 Year ago
;