feat: derivates

This commit is contained in:
2025-11-16 18:45:08 +01:00
parent 420a9049b3
commit 1fb7616c93
4 changed files with 26 additions and 1 deletions

View File

@@ -1,4 +1,8 @@
from sympy import diff, limit, oo, symbols
from modules.math import (
t_build_partial_derivate,
t_build_derivate,
t_calculate_e,
t_calculate_e_limit,
t_compound_interest,
@@ -23,3 +27,14 @@ if __name__=="__main__":
print(t_limit())
print(t_calculate_e_limit())
print(t_calculate_e_limit().evalf())
x = symbols("x")
derivative = t_build_derivate(x ** 2)
value_on_two = derivative.subs(x,2)
print(derivative, value_on_two)
# Partial derivates are applied to one variable at a time
y = symbols("y")
z = symbols("z")
partial_derivative_y = t_build_partial_derivate((3 * y ** 3) + 2 * z ** 2, y)
partial_derivative_z = t_build_partial_derivate((3 * y ** 3) + 2 * z ** 2, z)
print(partial_derivative_y, partial_derivative_z)

View File

Binary file not shown.

View File

Binary file not shown.

View File

@@ -2,7 +2,7 @@ from cmath import log as complex_log # used for complex numbers
from math import e, exp, log
# Sympy is powerful since it does not make aproximations, it keeps every primitive as it is, this means that it's slower but more precisse
from sympy import limit, oo, symbols
from sympy import diff, limit, oo, symbols
def t_summ():
@@ -50,3 +50,13 @@ def t_calculate_e_limit():
x = symbols("x")
f = (1 + 1 / x) ** x
return limit(f, x, oo)
# Calculate the slope by taking a close enough point
def t_calculate_derivative(f, x, step_size):
return (f(x + step_size) - f(x)) / (x +step_size - x)
def t_build_derivate(f):
return diff(f)
def t_build_partial_derivate(f,symbol):
return diff(f, symbol)