Online Univariate Function (Equation) Solution Calculation Tool

This masters-tool practical tool website can very simply and intuitively solve univariate functions (equations), provide calculation results while giving detailed operation steps, and also provide detailed textual explanations of the solution principles below for friends who need it.


Univariate Function Auto Solver / Online Univariate Equation Solver

  • Please consider this problem first: Solve for x such that e^(-x) - x = 0. If you can solve this problem with pen and paper, please leave a message to inform me of the method. If you cannot solve it with pen and paper, then we can completely rely on code to solve it.
  • The following is the solver I wrote, which can almost automatically solve all univariate functions. You can try any univariate function in the input box, press Enter or click the solve button to solve. If there are bugs, please leave a message, thank you.
  • Supported functions: addition +, subtraction -, multiplication *, division /, exponentiation ^, trigonometric functions, logarithmic functions ln(x) and log(base, x)
 Univariate Function: 
= 0

Principle of Univariate Function (Equation) Solving Tool

  • Newton's method is the core method for solving. Its definition is: Newton's method is an approximation method for solving equations in both real and complex number domains. The method uses the first few terms of the Taylor series of the function f(x) to find the roots of the equation f(x)=0. In short, Newton's method iterates x until it converges within a very small range.
  • Therefore, for any univariate function, we can try to use Newton's method to obtain its approximate solution. When the error is less than 10^-9, or the number of iterations exceeds 10^5, the iteration ends.
  • When building the solver, there are several key issues that need to be resolved: parsing the input expression, expressing the function, deriving the derivative function equation, and substituting the function for evaluation. Among them, the most important issue is: how do we store (express) the function?
  • Why choose this binary expression tree representation? Mainly because it is a tree structure, which facilitates recursive processing of nodes. Later, the derivation of the derivative function actually uses the recursive idea, including the recursive idea of substitution evaluation.
  • Preprocessing expressions: First, we need to preprocess the input expression string. Because in mathematics, some abbreviations or redundant notations need to be standardized here. After natural input strings are preprocessed, they should be infix expression strings, which are human-understandable expression forms. However, in order to store expressions as binary expression trees, we also need to convert infix expressions into postfix expressions.
  • Shunting Yard Algorithm: The shunting yard algorithm is basically similar to the method of using stacks to calculate expressions mentioned in the article about stacks, recursion, and the Tower of Hanoi. It uses queues to express the output postfix expressions and uses stacks to store operators and functions.
  • Building Binary Expression Trees: Assuming the input expression is: (a+b) * (c * (d+e)), after the shunting yard algorithm, we get the postfix expression a b + c d e + * *. At this point, we can quickly build a binary expression tree using the characteristics of postfix expressions.
  • Evaluation: The algorithm for substituting and evaluating binary expression trees should be easy to think of. Using the recursive nature of binary trees, the root is an operator or function, and the left and right subtrees are recursively defined. We just need to recursively calculate the values of the left and right subtrees, and then perform the operation of the operator.
  • Building Derivative Function Tree: We are left with the step of solving the derivative function. This step is also a relatively complex operation, because there are so many rules for derivative functions. First of all, the derivative function should be represented by a binary expression tree, because it can be directly substituted for evaluation, and the binary expression tree has recursive characteristics; secondly, since the root node of the binary expression tree is always an operator or function, and the left and right subtrees are also expressions, we can use recursive ideas to solve the derivative function.
  • For more content related to algorithm principles.