Skip to content

Instantly share code, notes, and snippets.

@danielvarga
Created May 29, 2024 19:16
Show Gist options
  • Select an option

  • Save danielvarga/e342dc45c3c75bdf1c5fec5b73999933 to your computer and use it in GitHub Desktop.

Select an option

Save danielvarga/e342dc45c3c75bdf1c5fec5b73999933 to your computer and use it in GitHub Desktop.
ChatGPT numerically solves ODE
# https://chatgpt.com/share/a06552d3-778a-4bfc-b411-3cb5bee4d6d3
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
# Define the system of ODEs
def system(y, t):
f, g = y
dfdt = g
dgdt = (f**4 + g**2 * f**2 - f**2 - 2 * g**2) / (-f) if f != 0 else 0
return [dfdt, dgdt]
# Initial conditions
c = 2.0 # Example value for c, you can set it to any value
initial_conditions = [c, 0]
# Time points where the solution is computed
t = np.linspace(0, 10, 10000)
# Solve the ODE
solution = odeint(system, initial_conditions, t)
# Extract the results
f = solution[:, 0]
g = solution[:, 1]
# Plot the results
plt.plot(t, f, label='f(t)')
plt.plot(t, g, label="f'(t)")
plt.xlabel('t')
plt.ylabel('Functions')
plt.legend()
plt.title("Solution of the differential equation")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment