Skip to main content
7 votes
Accepted

Stiff ODE solver in the web browser

I am the author of diffeq-js (https://github.com/martinjrobins/diffeq-js), which is a javascript library for solving DAE (and ODE) models in the browser using ...
Martin Robinson's user avatar
7 votes

Numerical implementation of ODE differs largely from analytical solution

The equation for the square resistance can be easily solved by remembering the pattern $$(e^y)''=e^y\,(y''+y'^2)$$ and considering $u=\exp(-cx)$. This gives $\dot u=cvu$ (with $v=-\dot x$) and $$\ddot ...
Lutz Lehmann's user avatar
  • 6,109
5 votes
Accepted

Numerical implementation of ODE differs largely from analytical solution

From the link that you have posted in the comment, I guess your function definition is not correct. def f(v, g, k, m): return g - k/m * v Hope the above should ...
RandomElasticity's user avatar
5 votes
Accepted

How should I solve generalized eigenvalue problems in Python? (Orr-Sommerfeld equation)

The performance of the two methods should be very close, because scipy.linalg.eig internally calls Lapack's ggev, which itself ...
Federico Poloni's user avatar
5 votes

Solving IVP backward in time via python

The error magnification factor is $e^{42}=1.739274941520501\cdot10^{+18}$. You are allowing an absolute error of $10^{-8}$ in the forward integration. Thus it is not astonishing to get an error n the ...
Lutz Lehmann's user avatar
  • 6,109
4 votes

Choice between DAE or ODE formulation for chemical systems

Let's look at the results from 3 different chemical reaction DAE systems: Chemical Akzo OREGO ROBER These are all implemented using ModelingToolkit.jl in order to generate the various forms. It's 3 ...
Chris Rackauckas's user avatar
4 votes

Raman model equations using RK4

Don't write your own ODE solver. There are perfectly good libraries (e.g https://pypi.org/project/diffeqpy/) that use better algorithms (e.g. Tsit5), with adaptive time-stepping and error control, ...
Oscar Smith's user avatar
3 votes

inverse problem of predicting parameters of ODEs driven by data

The problem of finding coefficients $a,b,c,d$ from the trajectory $v(u)$ is ill posed, it is not solvable. For the linear system of homogeneous equations with constant coefficients, $ \frac{d}{dt} \...
Maxim Umansky's user avatar
3 votes

inverse problem of predicting parameters of ODEs driven by data

$\DeclareMathOperator*{\argmin}{argmin}$ Before you try to solve the inverse problem, you have to address an issue of identifiability. That is, from the observations along $v(u)$, it is impossible to ...
whpowell96's user avatar
  • 2,636
3 votes
Accepted

Order of numerical solver when calculating difference between forwards and backwards solution

The paths of the forward and backward integration have a global error of $O(h^4)$, their distance is thus at most that large. In consequence, contributions of that difference to the coefficients of ...
Lutz Lehmann's user avatar
  • 6,109
3 votes

Order of numerical solver when calculating difference between forwards and backwards solution

What you observe should be an even-odd related problem. Recall that even- and odd functions are defined as $$ \begin{align} \text{even function:}\quad f(t)-f(-t)=0,\\ \text{odd function:}\quad f(t)+f(-...
ConvexHull's user avatar
  • 1,379
3 votes

Isolating decaying solutions to nonlinear second-order ode

Eliminating the constants, the approximation close to $x=0$ is $y(x)=\pi+xy'(x)$ with $y'$ nearly constant. Or one could multiply the leading terms with $2x^2y'$ and integrate $$ 2x^2y'y''+2xy'^2-2\...
Lutz Lehmann's user avatar
  • 6,109
3 votes

Approximating the solution of a non-linear ODE using Python

The canonical form of Newton's law for a particle in the classical mechanics is $ \ddot{x}= f(t,x,\dot{x}) $ That is, the second time derivative of the coordinate x is a function of time, space, and ...
Maxim Umansky's user avatar
2 votes

Approximating the solution of a non-linear ODE using Python

please find my suggestions below. For Computing b Ignoring the $\frac{db}{dt}$ on the RHS, This is an ODE with integral terms on the RHS. $$ \frac{db}{dt} = \int_t^{t1} f(b,h,t) dt $$ First thing is ...
ThivinAnandh's user avatar
2 votes

scipy odeint - Excess work done on this call

I modified your code to use the more up-to-date solve_ivp and it no longer gets the problem: ...
Tarik's user avatar
  • 173
2 votes
Accepted

Using Sundials CVODE in MATLAB

There is a now a new way to call CVODE from within matlab, fairly seamlessly, from v2024a onwards. See this blog entry for the new syntax: https://blogs.mathworks.com/matlab/2024/04/17/faster-ordinary-...
mirams's user avatar
  • 468
2 votes

Solving IVP backward in time via python

Consider an ODE of the form: $$d_t u(t) = \alpha u(t) + b(t), \quad b(t) = \exp(t\beta ).$$ By using an integrating factor of $\exp(-t\alpha)$ you can get the solution: \begin{align} u(t) &= \exp(...
lightxbulb's user avatar
  • 2,197
2 votes

How to estimate the stage error for Runge kutta method

What you're hoping to prove is (in general) not true. In words, you want to show that for a method of order $p$, each stage of the Runge-Kutta method also approximates the solution (at $t_n + c_i \...
David Ketcheson's user avatar
2 votes

How to estimate the stage error for Runge kutta method

The extension of Taylor expansions to Runge-Kutta methods are the B-series based on single-rooted trees as formalized by Butcher. Such a series has the general form $$ \Delta y=\Psi(y,h)=\sum_{\tau\in ...
Lutz Lehmann's user avatar
  • 6,109
2 votes
Accepted

How to use a custom OdeSolver in Scipy's solve_ivp

This error is entirely normal. You should be giving a OdeSolver subclass (e.g. scipy.integrate.RK45) which implements the correct interface. In particular, the OdeSolver class is not meant to be ...
Laurent90's user avatar
  • 1,943
2 votes

Can I combine the backward and forward euler methods - simialr to modified euler method?

You can construct an ODE solver out of basically any set of function evaluations you want. The better question to ask is what makes a good combination? This is a topic that has had a lot of research, ...
Oscar Smith's user avatar
2 votes
Accepted

Raman model equations using RK4

While writing the method you should have gotten doubts: k1,k2,... updates Ps r1,r2,... updates Pp q1,q2,... updates Ns v1,v2,... updates Np This is realized in your code in the naming of the ...
Lutz Lehmann's user avatar
  • 6,109
2 votes

From Runge-Kutta Butcher tableau to general linear methods matrices?

Given a Runge-Kutta method with the tableau $$ \begin{array}{c|c} c & A \\ \hline & b^T \end{array} = \begin{array}{c|ccc} c_1 & a_{1,1} & \dots & a_{1,s} \\ \vdots & \vdots &...
Steven Roberts's user avatar
2 votes

Educational Purpose: How to synchronize chaotic systems

The exact manner in which you couple the systems seems to be the issue here. This can be done for the Lorenz system. Consider the coupled Lorenz systems given by $$ \begin{aligned} \dot{x}_1 &= \...
whpowell96's user avatar
  • 2,636
2 votes

ode23, 45, 15s, 15i in matlab for conservative ODEs

None of those ODE solvers are conservative*. For a conservative integrator you typically need a symplectic integrator. There are implementations of various symplectic integrators on Matlab file ...
helloworld922's user avatar
1 vote

inverse problem of predicting parameters of ODEs driven by data

This is a well studied problem with relatively good solvers. That said, there are about a million different methods and which ones work depend on lots of complicated details. For an example of how to ...
Oscar Smith's user avatar
1 vote

shooting method to compute the interface shape

Given your differential equation is nonlinear, it is not clear that using the bisection method to find the desired value for $\theta_q$ so that $\theta|_{s = l} = \pi/2$ is reasonable. Let $f(\theta_q)...
spektr's user avatar
  • 4,258
1 vote

Local truncation error of given implicit 1-step scheme

You insert the exact solution on both sides so that $y'(t_{n+1})=f(t_{n+1},y(t_{n+1}))$ and $y''(t_{n})=f'(t_{n},y(t_{n}))$. Thus \begin{align} O(h^{p+1})=g(h)&=-y(t+h)+y(t)+\frac{h}{6}[4y'(t)+2y'(...
Lutz Lehmann's user avatar
  • 6,109
1 vote

Is there a Python version of the ODE tool pplane?

I would like to provide with my codes with a result resembling that of matlab, although not 100% the same. Codes are maintained and extended to more general cases via pplane for python. ...
Wei Shan Lee's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible