<jupyter_start><jupyter_text>class<jupyter_code>class ABC:
    def __init__(self):
        self.word = "Coool"
    def NotCool(self):
        self.word = "Not Coool"
    def NewWord(self, new_word):
        self.word = new_word
object_sample = ABC()
object_sample.word
object_sample.NotCool()
object_sample.word
object_sample.NewWord("Jesus")
object_sample.word<jupyter_output><empty_output><jupyter_text>class over  Grid convergence<jupyter_code># different grids
dt_values = [0.1, 0.05, 0.01, 0.005, 0.001]

# empty list for solutions
u_values = []

for dt in dt_values:
    N = int(T/dt) + 1
    u = numpy.empty((N,4)) # N by 4 empty array
    u[0] = numpy.array([v0, theta0, x0, y0]) # initial conditions
    for n in range(N-1):
        u[n+1] = euler_step(u[n], rhs_phugoid, dt, CL, CD, g, vt)
    u_values.append(u)
def l1_diff(u_coarse, u_fine, dt):
    """
    Returns the difference in the L1-norm between the solution on
    a coarse grid and the solution on a fine grid.
    
    Parameters
    ----------
    u_coarse : numpy.ndarray
        Solution on the coarse grid as an array of floats.
    u_fine : numpy.ndarray
        Solution on the fine grid as an array of floats.
    dt : float
        Time-step size.
    
    Returns
    -------
    diff : float
        The difference between the two solutions in the L1-norm
        scaled by the time-step size.
    """
    N_coarse = len(u_coarse)
    N_fine = len(u_fine)
    ratio = math.ceil(N_fine / N_coarse)
    # u_fine[::ration] means it takes sample from it begin to
    # the end, seperated by ratio
    diff = dt * numpy.sum(numpy.abs(u_coarse - u_fine[::ratio]))
    return diff
# computing error down below
diff_values = []

# from dt_values first to last
for i, dt in enumerate(dt_values[:-1]):
    diff = l1_diff(u_values[i][:, 2], u_values[-1][:, 2], dt)
    diff_values.append(diff)
# plot:
pyplot.figure(figsize=(6.0, 6.0))
pyplot.title('L1-norm difference vs. time-step size')  # set the title
pyplot.xlabel('$\Delta t$')  # set the x-axis label
pyplot.ylabel('Difference')  # set the y-axis label
pyplot.grid()
pyplot.loglog(dt_values[:-1], diff_values,
              color='C0', linestyle='--', marker='o')  # log-log plot
pyplot.axis('equal');  # make axes scale equally<jupyter_output><empty_output><jupyter_text>Order of convergence<jupyter_code>r = 2 # a constant ratio
h = 0.001 # finest grid

dt_values2 = [h, r*h, r**2*h] # h, 2h, 4h - three grids

u_values2 = []

for dt in dt_values2:
    N = int(T/dt) + 1
    
    # initialization
    u = numpy.empty((N,4))
    u[0] = numpy.array([v0, theta0, x0, y0])
    
    for n in range(N-1):
        u[n+1] = euler_step(u[n], rhs_phugoid, dt, CL, CD, g, vt)
    
    u_values2.append(u)
    
# calculate f2 - f1
f2_f1 = l1_diff(u_values2[1][:, 2], u_values2[0][:, 2], dt_values2[1])

# calculate f3 - f2
f3_f2 = l1_diff(u_values2[2][:,2], u_values2[1][:, 2], dt_values2[2])

# calculate the observed order of convergence
p = math.log(f3_f2/f2_f1)/math.log(r)
print("The observed order of convergence: p = {:.3f}".format(p))<jupyter_output>The observed order of convergence: p = 1.008<jupyter_text>Paper Airplane Challenge<jupyter_code>vt_paper = 4.9 # paper airplane trim velocity
CD_paper = 1/50.0
CL_paper = 1.0
x0_paper = 0.0
y0_paper = 2.0 # given initial height is 2 meters
dt_paper = 0.001 # set up grid
T_paper = 100 # time length
N_paper = int(T_paper/dt_paper) + 1

u_paper = numpy.empty((N_paper, 4))
# give a casual value of initial speed and angle
# the max speed of paper airplane could be set to 42 m/s, which could be found
# [here](https://www.quora.com/What-is-the-maximum-speed-a-paper-plane-can-be-launched-by-hand)
# the angle could go from -90 degree to 90 degree.
v0_paper_max = 42.0
v0_paper_min = 0.2 # avoid 0 division problem
d_v0_paper = 0.2 # initial speed resolution

theta0_paper_max = numpy.pi/180*(90)
theta0_paper_min = numpy.pi/180*(-90)
d_theta0_paper = numpy.pi/180*(1)

# unfinished down below
v0_paper = 36.9
theta0_paper = numpy.pi/180*(-90)

u_paper[0] = numpy.array([v0_paper, theta0_paper, x0_paper, y0_paper])
for n_paper in range(N_paper-1):
    u_paper[n_paper+1] = euler_step(u_paper[n_paper], rhs_phugoid, dt_paper, CL_paper, CD_paper, g, vt_paper)
# plot:
x_paper = u_paper[:, 2]
y_paper = u_paper[:, 3]

pyplot.figure(figsize=(9.0, 4.0))
pyplot.title('Path of the glider (flight time = {})'.format(T_paper))
pyplot.xlabel('x')
pyplot.ylabel('y')
pyplot.grid()
pyplot.plot(x_paper, y_paper, color='C0', linestyle='-', linewidth=2);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13940193491644678, 'fraction_numerical': 0.0395778364116095, 'mean_word_length': 3.6135902636916835, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '313630', 'license': 'MIT', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1756, 'n_words': 452, 'path': 'Week3 Part 1 Lesson 01_03.ipynb', 'repo_name': 'Chao8219/mae6286-chao', 'size': '4548'}