Enter the following code into an input cell in a worksheet, and evaluate the cell:
var('x, y') # Solve a single equation f(x) = x^3 - 1 solution1 = solve(f == 0, x) for solution in solution1: print(solution) # Solve a system of equations solutions = solve([x^2 + y^2 == 1, y^2 == x^3 + x + 1], x, y, solution_dict=True) print("\nSolution to system:") for solution in solutions: print("x = {0} y = {1}".format(solution[x], solution[y])) # Solve an inequality print("\nSolution to inequality:") solve(-20 * x - 30 <= 4 * x^3 - 7 * x, x) # Plotted in previous example
The output is shown in the following screenshot:
We used the solve
function to solve an equation, a system of equations, and an inequality. The first argument to solve
is an equation or a list of equations. The next argument (or arguments) is the variable or variables to solve for. By default, the solutions are returned as a list of symbolic expressions. The...