0

I have attempted to solve the differential equation $\frac{dy}{dt} = -ay^3 $ analytically. My solution is

$y = \sqrt{\frac{1}{2[C_4-at]}}$

When I attempt to use the odeint function in scipy.integrate, I do not get the same graphed result

#Import useful routines from modules
#The equation to be solved is $\frac{dy}{dt} = -ay^3 $ 
from scipy.integrate import odeint
from numpy import linspace, exp, sqrt
import matplotlib.pyplot as plt

#Here we define our function which returns df/dt = -a*f*f*f
#Note we’ve assumed that a=10
def dfdt(curF,curT,a):
    #We don’t do anything with curT
    return -a*curF*curF*curF

#Now define the times at which we want to know the result
time=linspace(0,20,400)

a=20

#Set the initial condition
f0=0.086


#Now we can solve the equation for this a
#Note we need a comma after the a here to
#make sure args is a *tuple*
result = odeint(dfdt,f0,time,args=(a,))
plt.plot(time,result,'x',label='odeint')
plt.plot(time,sqrt(1/(2*(100 -(a*time)))),label='analytic')
  
#Plot

plt.legend() 
plt.show()
  • 1
    Please explain how your plot differs from what you expect and identify why you think your expected result is in fact correct. – itprorh66 Nov 02 '22 at 19:28

0 Answers0