-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInitialValueProblems.py
More file actions
47 lines (39 loc) · 925 Bytes
/
InitialValueProblems.py
File metadata and controls
47 lines (39 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
# Constants
f = 0.36
h = 0.0
m = 0.02
# Define the system of equations
def equations(t, variables):
x, y, v = variables
dx_dt = f * x - x * v
dy_dt = x * v - y
dv_dt = y - m * x * v - h * v
return [dx_dt, dy_dt, dv_dt]
# Initial conditions
x0 = 0.4
y0 = 0.0
v0 = 0.1
# Time range
t_start = 0.0
t_end = 20.0
num_points = 100
# Time array
t = np.linspace(t_start, t_end, num=num_points)
# Solve the system of equations
sol = solve_ivp(equations, [t_start, t_end], [x0, y0, v0], t_eval=t)
# Extract the solutions
x_values = sol.y[0]
y_values = sol.y[1]
v_values = sol.y[2]
# Plot the solutions
plt.plot(t, x_values, label='x')
plt.plot(t, y_values, label='y')
plt.plot(t, v_values, label='v')
plt.xlabel('Time')
plt.ylabel('Value')
plt.legend()
plt.title('Solution of the Nonlinear Equation System')
plt.show()