Code Explanation:
from sympy import symbols, diff
symbols('x'): Creates a symbolic variable
𝑥
x that can be used in algebraic expressions.
diff(): Computes the derivative of a given function.
Define the function
f(x)
x = symbols('x')
f = x**3 + 5*x**2 - 2*x + 7
This defines the function:
f(x)=x 3+5x 2−2x+7
Compute the Derivative
derivative = diff(f, x)
diff(f, x) calculates the first derivative of
f(x).
Evaluate at
x=3
derivative = derivative.subs(x, 3)
subs(x, 3) replaces
x with 3
Print the Result
print(derivative)
The output will be:
55
0 Comments:
Post a Comment