Reputation: 91
I am trying to solve a stiff ODE system with other methods rather than Rosenbrock as ode23s from Matlab. I would like to use scipy library with various methods such as LSODA or Sundials.
A matlab ODE complex function defined as;
function [dpdt]=damper_rebo(t,P,amp,freq,pars)
.....
with amp, frequency constants and pars a cell of parameters with constants parameters. It works fine with;
tic
[tsol,ysol]=ode23s(@(t,P) damper_rebo(t,P,amp,freq,pars),[0 0.5/freq],P_0,options);
toc
I am trying to compare with other methods to solve ODE with stiff equations like LSODA and BDF. I loaded the python environment and installed all the path requirements, then I tried this:
py.importlib.import_module("scipy")
%--Call out the constant parameters from the function--%%
pars=params7();
pyrun("from scipy.integrate import LSODA")
%-----------------------------------------%
%---Excitation Signal Properties of the Damper---%
amp=25.25e-3; % Modal excitational amplitudes (m)
v_n=0.151;
freq=v_n/2/pi/amp; % Modal frequency (Hz)
%-------------------------------------%
%--Initial Pressure conditions--%
Pg_0=pars{68};
P_0=[0.01,0.001,1e5,2e5,Pg_0]; % At equilibrium three chambers at the same pressure
%-------------------------------%
% %-------------------------------%
%--Atmospheric Surrounding Temp and Pressure--%
T_atm=15; % Fluid Initial Properties by the supplier
p_atm=101325;
%---------------------------------------------%
Tspan = py.list([0.0, 0.5/freq]);
pyfun = py.str('lambda t,P: damper_rebo(t,P,amp,freq,pars)');
or
pyfun = py.function_handle(@(t,P) damper_rebo(t,P,amp,freq,pars));
sol=py.scipy.integrate.solve_ivp(pyfun,Tspan, py.numpy.array(P_0),pyargs(method="BDF", rtol=0.00001, atol=1e-06));
The first pyfun
option brings an error that Python Error: TypeError: 'str' object is not callable
The second option brings an error too with Unable to resolve the name 'py.function_handle'.
Upvotes: 1
Views: 42
Reputation: 91
This subject is as complicated as making a nuclear bomb in the 70's it seems. The function handles from two different languages aren't the same and attempting to convert types and arrays of the right format is nerve wrecking.
Upvotes: 0