Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md

This file was deleted.

Binary file added extratasks givs/lab_3_extratask1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extratasks givs/lab_3_extratask2_var_a.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extratasks givs/lab_3_extratask2_var_b.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extratasks givs/lab_3_extratask2_var_c.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extratasks givs/lab_3_extratask3_h.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extratasks givs/lab_3_extratask3_v.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extratasks givs/lab_3_extratask4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extratasks givs/lab_3_extratask5.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions extratasks/lab_3_extratask1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

t = np.arange(0, 10000, 0.5)

def decay_func(z, t):
A, B, C = z
dA_dt = - k1*A
dB_dt = k1*A - k2*B
dC_dt = k2*B - k3*C
return dA_dt, dB_dt, dC_dt

k1 = 0.02
k2 = 0.05
k3 = 0.01

A0 = 500
B0 = 0
C0 = 0
z0 = A0, B0, C0

sol = odeint(decay_func, z0, t)
A = sol[:, 0]
B = sol[:, 1]
C = sol[:, 2]

def animate(i):
A_sum.set_data([t[:i]], [A[:i]])
B_sum.set_data([t[:i]], [B[:i]])
C_sum.set_data([t[:i]], [C[:i]])

fig, ax = plt.subplots()

A_sum, = plt.plot([], [], '-', color='r')
B_sum, = plt.plot([], [], '-', color='g')
C_sum, = plt.plot([], [], '-', color='b')

ax.set_xlim(0, 200)
ax.set_ylim(0, 500)

ani = FuncAnimation(fig, animate, frames=300, interval=30)
ani.save('extratasks givs/lab_3_extratask1.gif')
46 changes: 46 additions & 0 deletions extratasks/lab_3_extratask2_var_a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

t = np.arange(0, 2000, 0.05)

def move_func(z, t):
y, v = z

dy_dt = v
dv_dt = g - k*y/m
return dy_dt, dv_dt

m = 0.5

delta_L = 0.08
F_0 = 1
k = F_0 / delta_L

v0 = 0.5
g = 9.8
y0 = - delta_L

z0 = y0, v0

sol = odeint(move_func, z0, t)
y = sol[:, 0]
print(y)

def animate(i):
move.set_data([0], [y[i]])
move_line.set_data(np.full(20, 0), np.linspace(y[i], 1, 20))

fig, ax = plt.subplots()

move_line, = plt.plot([], [], '-', color='g')
move, = plt.plot([], [], 'o', color='r')
roof, = plt.plot(np.linspace(-1, 1, 20), np.full(20, 1), '-', color='0')

edge = 2
ax.set_xlim(-edge, edge)
ax.set_ylim(-edge, edge)

ani = FuncAnimation(fig, animate, frames=300, interval=50)
ani.save('extratasks givs/lab_3_extratask2_var_a.gif')
46 changes: 46 additions & 0 deletions extratasks/lab_3_extratask2_var_b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

t = np.arange(0, 2000, 0.05)

def move_func(z, t):
y, v = z

dy_dt = v
dv_dt = g - k*y/m - 0.8*v
return dy_dt, dv_dt

m = 0.5

delta_L = 0.08
F_0 = 1
k = F_0 / delta_L

v0 = 0.5
g = 9.8
y0 = - delta_L

z0 = y0, v0

sol = odeint(move_func, z0, t)
y = sol[:, 0]
print(y)

def animate(i):
move.set_data([0], [y[i]])
move_line.set_data(np.full(20, 0), np.linspace(y[i], 1, 20))

fig, ax = plt.subplots()

move_line, = plt.plot([], [], '-', color='g')
move, = plt.plot([], [], 'o', color='r')
roof, = plt.plot(np.linspace(-1, 1, 20), np.full(20, 1), '-', color='0')

edge = 2
ax.set_xlim(-edge, edge)
ax.set_ylim(-edge, edge)

ani = FuncAnimation(fig, animate, frames=300, interval=50)
ani.save('extratasks givs/lab_3_extratask2_var_b.gif')
48 changes: 48 additions & 0 deletions extratasks/lab_3_extratask2_var_c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

t = np.arange(0, 2000, 0.05)

def move_func(z, t):
y, v = z

dy_dt = v
dv_dt = g - k*y/m - 5 * np.cos(omega*t) / m
return dy_dt, dv_dt

m = 0.5

delta_L = 0.08
F_0 = 1
k = F_0 / delta_L

omega = 1/2

v0 = 0.5
g = 9.8
y0 = - delta_L

z0 = y0, v0

sol = odeint(move_func, z0, t)
y = sol[:, 0]
print(y)

def animate(i):
move.set_data([0], [y[i]])
move_line.set_data(np.full(20, 0), np.linspace(y[i], 1, 20))

fig, ax = plt.subplots()

move_line, = plt.plot([], [], '-', color='g')
move, = plt.plot([], [], 'o', color='r')
roof, = plt.plot(np.linspace(-1, 1, 20), np.full(20, 1), '-', color='0')

edge = 2
ax.set_xlim(-edge, edge)
ax.set_ylim(-edge, edge)

ani = FuncAnimation(fig, animate, frames=300, interval=50)
ani.save('extratasks givs/lab_3_extratask2_var_c.gif')
63 changes: 63 additions & 0 deletions extratasks/lab_3_extratask3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

t = np.arange(0, 1000, 1)

def decay_func(z, t):
M, h, v = z

if M > 0:
dM_dt = - dM0_dt
else:
dM_dt = 0

dh_dt = v
dv_dt = -u*dM_dt / (M+m) - G * M_earth/(R_earth + h)**2

return dM_dt, dh_dt, dv_dt

h_0 = 0
v_0 = 0

M_0 = 200
m = 50
u = 3 * 1000
dM0_dt = 1

G = 6.67 * 10**(-11)
M_earth = 5.974 * 10**24
R_earth = 6378.1 * 10**3

z0 = M_0, h_0, v_0

sol = odeint(decay_func, z0, t)
h_t = sol[:, 1] / 10**3
v_t = sol[:, 2]

def animate_h(i):
h_func.set_data([t[:i]], [h_t[:i]])

def animate_v(i):
v_func.set_data([t[:i]], [v_t[:i]])

fig_h, ax_h = plt.subplots()

h_func, = plt.plot([], [], '-', color='r')

ax_h.set_xlim(0, 1000)
ax_h.set_ylim(0, 800)

ani_h = FuncAnimation(fig_h, animate_h, frames=1000, interval=30)
ani_h.save('extratasks givs/lab_3_extratask3_h.gif')

fig_v, ax_v = plt.subplots()

v_func, = plt.plot([], [], '-', color='g')

ax_v.set_xlim(0, 1000)
ax_v.set_ylim(0, 3000)

ani_v = FuncAnimation(fig_v, animate_v, frames=1000, interval=30)
ani_v.save('extratasks givs/lab_3_extratask3_v.gif')
53 changes: 53 additions & 0 deletions extratasks/lab_3_extratask4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

t = np.arange(0, 10, 0.01)

def decay_func(z, t):
x, y, v = z

dx_dt = -v
dy_dt = -v
dv_dt = g

return dx_dt, dy_dt, dv_dt

L = 2.5
l = 0.1
h = 1
g = 10

x0 = L - l
y0 = l
v0 = 0

z0 = x0, y0, v0

sol = odeint(decay_func, z0, t)
x = sol[:, 0]
y = sol[:, 1]
print(x)
print(y)

def animate(i):
if x[i] > 0:
x_func.set_data(np.linspace(0, x[i], 20), [np.full(20, l)])
y_func.set_data([np.full(20, 0)], np.linspace(y[i], l, 20))
else:
x_func.set_data([], [])
y_func.set_data([np.full(20, 0)], np.linspace(y[i], y[i] + L, 20))

fig, ax = plt.subplots()

x_func, = plt.plot([], [], '-', color='r')
y_func, = plt.plot([], [], '-', color='r')
# table, = plt.plot(np.full(20, np.linspace(0, L, 20)), np.full(20, np.linspace(0, l, 20)), '-', color='0')

edge = 5
ax.set_xlim(-edge, edge)
ax.set_ylim(-edge, edge)

ani = FuncAnimation(fig, animate, frames=100, interval=30)
ani.save('extratasks givs/lab_3_extratask4.gif')
46 changes: 46 additions & 0 deletions extratasks/lab_3_extratask5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

t = np.arange(0, 50, 0.4)

def decay_func(z, t):
T_1, T_2 = z

dT1_dt = dT0_dt + alpha_1*(T_g-T_1) + 4*alpha_2*(T_e-T_1) + alpha_3*(T_2-T_1)
dT2_dt = 4*alpha_2*(T_e-T_2) + alpha_1*(T_1-T_2)

return dT1_dt, dT2_dt

T_g = 0
alpha_1 = 0.05
T_e = 20
alpha_2 = 0.02
alpha_3 = 0.01

T_10 = 10
T_20 = 20
dT0_dt = 5

z0 = T_10, T_20

sol = odeint(decay_func, z0, t)
T_1 = sol[:, 0]
T_2 = sol[:, 1]

def animate(i):
T_1_func.set_data([t[:i]], [T_1[:i]])
T_2_func.set_data([t[:i]], [T_2[:i]])

fig, ax = plt.subplots()

T_1_func, = plt.plot([], [], '-', color='r')
T_2_func, = plt.plot([], [], '-', color='g')

edge = 40
ax.set_xlim(0, 40)
ax.set_ylim(0, 50)

ani = FuncAnimation(fig, animate, frames=100, interval=30)
ani.save('extratasks givs/lab_3_extratask5.gif')
Binary file added less_1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading