-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDifferentiation.py
More file actions
45 lines (36 loc) · 1.25 KB
/
Differentiation.py
File metadata and controls
45 lines (36 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sympy as sp
# Define variables
x = sp.symbols('x')
# a. Derivative of a constant multiple of a function
c = sp.symbols('c') # constant
f = sp.Function('f')(x)
expr_a = c * f
result_a = sp.diff(expr_a, x)
# b. Derivative of the sum (or difference) of two functions
g = sp.Function('g')(x)
expr_b = f + g # Sum of two functions
result_b = sp.diff(expr_b, x)
# c. Derivative of the product of two functions
expr_c = f * g # Product of two functions
result_c = sp.diff(expr_c, x)
# d. Derivative of the quotient of two functions
expr_d = f / g # Quotient of two functions
result_d = sp.diff(expr_d, x)
# e. Power Rule Example
# Example 1: f(x) = x^3
power_expr1 = x**3
power_result1 = sp.diff(power_expr1, x)
# Example 2: f(x) = 2x^4 + 3x^2
power_expr2 = 2*x**4 + 3*x**2
power_result2 = sp.diff(power_expr2, x)
# Print results
results = {
"a. Derivative of constant multiple of a function": result_a,
"b. Derivative of sum or difference of two functions": result_b,
"c. Derivative of product of two functions": result_c,
"d. Derivative of quotient of two functions": result_d,
"e1. Power Rule - f(x) = x^3": power_result1,
"e2. Power Rule - f(x) = 2x^4 + 3x^2": power_result2
}
for key, value in results.items():
print(f"{key}: {value}\n")