calculate_expression
Compute mathematical expressions using symbolic computation, including arithmetic, algebra, calculus, equation solving, and matrix operations.
Instructions
calculate mathematical expressions using the sympify function from sympy, parse and compute the input mathematical expression string, supports direct calls to SymPy functions (automatically recognizes x, y, z as symbolic variables)
Parameters:
expression (str): Mathematical expression, e.g., "223 - 344 * 6" or "sin(pi/2) + log(10)".Replace special symbols with approximate values, e.g., pi → 3.1415"
Example expressions:
"2 + 35" # Basic arithmetic → 17
"expand((x + 1)2)" # Expand → x² + 2x + 1
"diff(sin(x), x)" # Derivative → cos(x)
"integrate(exp(x), (x, 0, 1))" # Definite integral → E - 1
"solve(x2 - 4, x)" # Solve equation → [-2, 2]
"limit(tan(x)/x, x, 0)" # Limit → 1
"Sum(k, (k, 1, 10)).doit()" # Summation → 55
"Matrix([[1, 2], [3, 4]]).inv()" # Matrix inverse → [[-2, 1], [3/2, -1/2]]
"simplify((x2 - 1)/(x + 1))" # Simplify → x - 1
"factor(x2 - 2x - 15)" # Factorize → (x - 5)(x + 3)
"series(cos(x), x, 0, 4)" # Taylor series → 1 - x²/2 + x⁴/24 + O(x⁴)
"integrate(exp(-x2)*sin(x), (x, -oo, oo))" # Complex integral
"solve([x2 + y**2 - 1, x + y - 1], [x, y])" # Solve system of equations
"Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).eigenvals()" # Matrix eigenvalues
Returns:
str: Calculation result. If the expression cannot be parsed or computed, returns an error message (str).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |