from sympy import * # Define variables x = symbols('x') # Define expression expr = x**2 + 5*x + 2 # Find maximum value max_value = Max(expr) print("Maximum value of expression:", max_value)
Maximum value of expression: Max(2 + 5*x + x**2)
from sympy import * # Define variables x = symbols('x') # Define expression expr = sin(x) + cos(x) # Find maximum value max_value = Max(expr) print("Maximum value of expression:", max_value)
Maximum value of expression: Max(cos(x) + sin(x), 0)In this example, the "Max" function returns two possible maximum values, since the expression is periodic with a range between -1 and 1.