<jupyter_start><jupyter_text>Differentation by first principlef'(x) = lim h -->0 ( f(x+h) - f(x))/(h)<jupyter_code>def differentation(func,x):
    # first principle
    h=0.0000001
    f = func(x)
    fh = func(x+h)
    dif_1 = ( fh-f)/h
    
    # two point formulae
    diff_2 = (func(x+h)-func(x-h))/(2*h)
    
    return (dif_1+diff_2)/2 
def function(x):
    import numpy as np
    func = np.sin(x)
    return func
differentation(function,1)<jupyter_output><empty_output><jupyter_text>Checking Lets try to see if the differentation of a continuous function like sine can be calculated with such a basic function or not.<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-np.pi*2,np.pi*2,100)
y = np.sin(x)
yd =  [differentation(np.sin,i) for i in x ]
plt.plot(y,label='sine')
plt.plot(yd,label='cosine')
plt.legend()<jupyter_output><empty_output><jupyter_text>Practical Packagehttps://github.com/maroba/findiff  Itegration by Summation<jupyter_code>def integration(func,l,h,N=10000):
    """
    func: Univariate function ex. f(x) = x**2
    l : lowest limit of integration
    h : upper limit of integration
    N : No. of summation 
    """
    width = (h-l)/N
    result = 0
    while l <= h :
        result+=func(l+width/2)
        l+=width
    return result*width
integration(function,1,3)<jupyter_output><empty_output><jupyter_text>Check for integration functionHere, we check the integration for functions including 1,x2,x3,sin.<jupyter_code># Integration of 1 in [1,3]
integration(lambda x:1,1,3)
# Integration of x**2 in [1,3]
integration(lambda x:x**2,1,3)
# Integration of x**3 in [1,3]
integration(lambda x:x**3,1,3)
(3**4-1**4)/4<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1411007025761124, 'fraction_numerical': 0.03337236533957846, 'mean_word_length': 4.226299694189603, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 1, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '436554', 'license': 'MIT', 'n_tokens_mistral': 683, 'n_tokens_neox': 644, 'n_words': 150, 'path': 'Numerical Differentiation & Integration.ipynb', 'repo_name': 'PundirShivam/Portfolio', 'size': '1708'}