Python_Primer / sympyappoutlier.py
eaglelandsonce's picture
Create sympyappoutlier.py
582f428 verified
raw
history blame
766 Bytes
import sympy as sp
def evaluate_derivative():
# Define the variables
u = sp.symbols('u')
x = sp.symbols('x')
# Define the outer function
f_outer = sp.sin(u)
# Calculate the derivative of the outer function
f_outer_prime = sp.diff(f_outer, u)
# Define the inner function
g = sp.exp(x) - 2*x + 1
# Calculate the derivative of the inner function
g_prime = sp.diff(g, x)
# Substitute g(x) into the derivative of the outer function
f_prime = f_outer_prime.subs(u, g)
# Multiply by the derivative of the inner function
f_prime = f_prime * g_prime
# Evaluate the derivative at x=1
result = f_prime.subs(x, 1)
return result
# Execute the function
result = evaluate_derivative()
print(result)