OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Unique solution to ODE

  • Thread starter Thread starter estellec
  • Start date Start date
E

estellec

Guest
There is a graphical regular ODE solution .

Code:
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

# function that returns dy/dt
def model(y,t):
    k = 0.3
    dydt = -k * y
    return dydt

# initial condition
y0 = 5

# time points
t = np.linspace(0,20)

# solve ODE
y = odeint(model,y0,t)

# plot results
plt.plot(t,y)
plt.xlabel('time')
plt.ylabel('y(t)')
plt.show()

Result :

ode result

What If I do not need to plot, I only need the numeric solution for x = 3 .

I have this Interpolation code, but solution is not accurate compared to sympy :

Code:
print(" At time 3, my result will be  " ,np.interp(3, x, y))

I guess there should be a faster numeric code ?

Thank you
<p>There is a graphical regular ODE solution .</p>
<pre><code>import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

# function that returns dy/dt
def model(y,t):
k = 0.3
dydt = -k * y
return dydt

# initial condition
y0 = 5

# time points
t = np.linspace(0,20)

# solve ODE
y = odeint(model,y0,t)

# plot results
plt.plot(t,y)
plt.xlabel('time')
plt.ylabel('y(t)')
plt.show()
</code></pre>
<p>Result :</p>
<p><a href="https://i.sstatic.net/Jpcb9EF2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Jpcb9EF2.png" alt="ode result" /></a></p>
<p>What If I do not need to plot, I only need the numeric solution for x = 3 .</p>
<p>I have this Interpolation code, but solution is not accurate compared to sympy :</p>
<pre><code>print(" At time 3, my result will be " ,np.interp(3, x, y))
</code></pre>
<p>I guess there should be a faster numeric code ?</p>
<p>Thank you</p>
 

Latest posts

Top