<jupyter_start><jupyter_text>Classes and Objects-Part-2  Example-1: Vertical Motion of a Projectile (Extended)<jupyter_code>class Y:
    def __init__(self, v0):
        self.v0 = v0
        self.g = 9.81
    def value(self, t):
        # Print y(t)
        return self.v0*t - 0.5*self.g*t**2
    def formula(self):
        # Print the formula:
        return 'y(t)=v0*t - 0.5*g*t**2; and v0=%g'%self.v0

y = Y(5)
t = 0.2
v = y.value(t)
print('y(t=%g; v0=%g) = %g'% (t, y.v0, v),'with the formula:', y.formula())<jupyter_output>y(t=0.2; v0=5) = 0.8038 with the formula: y(t)=v0*t - 0.5*g*t**2; and v0=5<jupyter_text>Example-2: Fibonacci sequence<jupyter_code>"""
Fibonacci_OOP.py
Computes Fibonacci numbers with OOP
n=position of last Fibonacio computed; positions start at zero
a=first Fib; b= second Fib

Created on Sat Dec 11 00:29:31 2021
@author: marco
"""

class Fibonacci:
    def __init__(self,a,b,n):
        self.a, self.b, self.n = a, b, n

    def seq(self):
        a,b,n=self.a,self.b,self.n   # quick forms    
        ca=[a,b]                    # initialized with first two Fibos
        for i in range(2,n):
            c=a+b
            b,a=c,b  # roll values
            ca.append(c)
        return ca
            
F=Fibonacci(0,1,6)
print(F.seq())<jupyter_output>[0, 1, 1, 2, 3, 5]<jupyter_text>Example-3: Trapezoidal Integration<jupyter_code>"""
TrapezoidalIntegration_OOP.py
Trapezoidal Integration by OOP programming

This is a modified example from the book: A Primer in Scientific Programming in Pyhton by <NAME>
Created on Sat Dec 11 00:00:11 2021
@author: marco
"""
import numpy as np

class Trapezoidal:
    
    def __init__(self, a, b, n):
        self.a, self.b, self.n = a, b, n
        self.points, self.weights = self.construct_method() # this function capture two results

    def construct_method(self):
        x = np.linspace(self.a, self.b, self.n)
        h = (self.b - self.a)/float(self.n - 1)
        w = np.zeros(len(x)) + h
        w[0] /= 2
        w[-1] /= 2
        return x, w
    
    def integrate(self, f):
        s = 0
        for i in range(len(self.weights)):
            s += self.weights[i]*f(self.points[i])
        return s

# Function f(x) must be defined before the "integrate" function call
m = Trapezoidal(0, 2, 101)
def f(x): return x*x
print(m.integrate(f))<jupyter_output>2.666800000000001
{'fraction_non_alphanumeric': 0.14091680814940577, 'fraction_numerical': 0.042869269949066216, 'mean_word_length': 2.6486068111455108, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '659613', 'license': 'CC0-1.0', 'n_tokens_mistral': 991, 'n_tokens_neox': 910, 'n_words': 241, 'path': 'OOP2.ipynb', 'repo_name': 'MarcoArochaOrdonez/ConqueringPython-with-JupyterNotebooks', 'size': '2363'}