feat: derivates
This commit is contained in:
15
src/main.py
15
src/main.py
@@ -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)
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user