How can I integrate the Ordinary differential equation using odeint from scipy.integrate?
By : ankit
Date : March 29 2020, 07:55 AM
To fix the issue you can do I am trying to integrate function defined as f in the code using odeint from scipy. The function f takes theta, t, and K as arguments, which are defined below the function f. y is the result, for which I am getting error. The reason for error is theta which is 2 dimensional. I am not able to perform integration. Could somebody help me in this ? , Write code :
y = odeint(f, theta.ravel(), t, args=(K,))
def f(theta, t, K):
global N
theta = theta.reshape(T, N)
...
return dtheta.ravel()

What is the difference between scipy.integrate.odeint and scipy.integrate.ode?
By : William Son
Date : March 29 2020, 07:55 AM
may help you . If you can solve your problem with odeint, I would recommend that. It is simply a function that integrates an ode using lsoda. If you want a lot more options, ode is a class with many methods and solvers:

TypeError when using scipy.integrate.odeint
By : Sahil Dilwali
Date : March 29 2020, 07:55 AM
this will help as @Warren Weckesser says and as you suspected, you need to lambdify the expressions first, so that the various partial derivatives dV/dvar[j] return a floating point value. More in general, one problem of your afleiden function is that it evaluates the analytical derivatives of V, without calculating the value of those expressions. I assume that v,a,c are parameters of your problems, deacribing a potential function V(x,y,z). I also assume that your o.d.e. is code :
import numpy as np
from sympy import lambdify, sympify
from scipy.integrate import odeint
var = ['x', 'y', 'z']
V = sympify("v**2/2*log(1+x**2 + (y/a)**2 + (z/c)**2)")
dVdvar_analytical = [V.diff(var[i]) for i in range(len(var))]
dVdvar = [lambdify(('x', 'y', 'z', 'v', 'a', 'c'), df) for df in dVdvar_analytical]
def afleiden(variables, _, params, dVdvar):
x, y, z = variables
v, a, c = params
return [dVdvarj(x, y, z, v, a, c) for dVdvarj in dVdvar ]
variables0, params = [0.3, 0.2, 0.9], [0.2, 0.6, 0.7]
t = np.arange(0, 10, .1)
y = odeint(afleiden, variables0, t, args=(params, dVdvar))
plot(t, y)
#example with minus sign
V = sympify("v**2/2*log(1+x**2 + (y/a)**2 + (z/c)**2)")
t = np.arange(0, 100, .1)

Error in using `scipy.integrate.odeint`
By : Claranz
Date : March 29 2020, 07:55 AM
Any of those help I am using the function scipy.integrate.odeint, but I get an unexpected error. My code is as follows: , The problem is this line: code :
y0 = (1λ, np.zeros(len(μ)))
In [7]: y0 = (1, np.zeros(4))
In [8]: np.array(y0)

ValueError Traceback (most recent call last)
<ipythoninput89a58cb72863b> in <module>()
> 1 np.array(y0)
ValueError: setting an array element with a sequence.
y0 = [1λ] + [0]*len(μ)
y0 = np.zeros(len(μ) + 1)
y0[0] = 1λ

Is it possible for scipy.integrate.odeint to output internal calculations
By : sameul
Date : March 29 2020, 07:55 AM
Hope this helps It is possible, you just can't use the return values of your eom function. So you need some other way of smuggling data out from eom. There are many, many different ways to do this. The simplest is probably to just use a global variable: code :
import scipy.integrate as spi
count = 0
def pend(t, y):
global count
theta, omega = y
dydt = [omega, .25*omega  5*np.sin(theta)]
count += 1
return dydt
sol = spi.solve_ivp(pend, [0, 10], [np.pi  0.1, 0.0])
print(count)
182
class Acc:
def __init__(self):
self.x = 0
def __str__(self):
return str(self.x)
def pend_partial(acc):
def pend(t, y):
theta, omega = y
dydt = [omega, .25*omega  5*np.sin(theta)]
acc.x += 1
return dydt
return pend
count = Acc()
sol = spi.solve_ivp(pend_partial(count), [0, 10], [np.pi  0.1, 0.0])
print(count)
182

