<jupyter_start><jupyter_text>Integral simbólica usando SymPy<jupyter_code>import numpy as np
import sympy as sy
from sympy.utilities.lambdify import lambdify
from scipy.integrate import quad
from scipy.misc import derivative
x = sy.Symbol('x')
f = sy.exp(-x)*sy.sin(3.0*x)
res_symbolic = sy.integrate(f)
res = sy.integrate(f, (x, 0, 2*sy.pi))

print(res.evalf())
f
res_symbolic
%timeit sy.integrate(f, (x, 0, 2*sy.pi))
# Lambdfy integrals
res_symbolic = sy.integrate(f)
integ = lambda x0, x1: res_symbolic.evalf(subs={x: x1}) - res_symbolic.evalf(subs={x: x0})
%timeit integ(0, 2*np.pi)
integ = lambda x0, x1: float(sy.integrate(f, (x, x0, x1)))
%timeit integ(0, 2*np.pi)<jupyter_output>171 ms ± 12.6 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)<jupyter_text>Multi-varible<jupyter_code>x, y = sy.symbols('x, y')
f = x**2
h = y**2
g = f + h
g1 = g.subs(x,1)

# Integrate g(x,y)*dx
sy.integrate(g,x)
# Integrate g(x,y)*dy
sy.integrate(g,y)
# Double integral g(x,y)*dx*dy
sy.integrate(sy.integrate(g,x),y)
# Double integral g(x,y)*dx*dy, xfrom 0 to 1, y from zero to 1
sy.integrate(sy.integrate(g,(x,0,1)),(y,0,1))
# Evaluating the results
sy.integrate(sy.integrate(g,(x,0,1)),(y,0,1)).evalf()
# Show the symbolic
sy.Integral(sy.Integral(g,(x,0,1)),(y,0,1))<jupyter_output><empty_output><jupyter_text>Using Scipy to Numerical integrate defined functions<jupyter_code>def f(x):
    return np.exp(-x)*np.sin(3.0*x)

i, err = quad(f, 0, 2*np.pi)
print(i)
%timeit i, err = quad(f, 0, 2*np.pi)
def foo(x, y):
  return(x**2 + x*y**3)

from scipy.misc import derivative
derivative(foo, 1, dx = 1e-6, args = (2, ))<jupyter_output><empty_output><jupyter_text>Derivada simbólica<jupyter_code>x = sy.Symbol('x')
f = 3*x**2 + 1
f
# Lambdfy derivatives
ddx = lambdify(x, sy.diff(f, x)) # creates a function that you can call
%timeit ddx(2)
dx = sy.diff(f, x)
ddx = lambda x0: dx.subs(x, x0)
%timeit ddx(2)
# Derivada de segunda ordem
sy.diff(f, (x, 2))<jupyter_output><empty_output><jupyter_text>Derivada numérica usando Scipy<jupyter_code>def f(x):
    return 3*x**2 + 1

%timeit derivative(f, 2)<jupyter_output>13.3 µs ± 401 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
{'fraction_non_alphanumeric': 0.17183985605038238, 'fraction_numerical': 0.03733693207377418, 'mean_word_length': 4.914893617021277, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '151475', 'license': 'MIT', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1029, 'n_words': 228, 'path': 'VA/work1/numerical_and_symbolic_integration.ipynb', 'repo_name': 'lucas-schroeder/Master_program_UFSC', 'size': '2223'}