I am trying to solve the differential equation 4(y')^3-y'=1/x^2 in python. I am familiar with the use of odeint to solve coupled ODEs and linear ODEs, but can't find much guidance on nonlinear ODEs such as the one I'm grappling with.
Attempted to use odeint and scipy but can't seem to implement properly
Any thoughts are much appreciated
NB: y is a function of x
The problem is that you get 3 valid solutions for the direction at each point of the phase space (including double roots). But each selection criterion breaks down at double roots.
One way is to use a DAE solver (which does not exist in scipy) on the system y'=v, 4v^3-v=x^-2
The second way is to take the derivative of the equation to get an explicit second-order ODE y''=-2/x^3/(12*y'^2-1).
Both methods require the selection of the initial direction from the 3 roots of the cubic at the initial point.
Related
I am looking to solve (in Python) a differential algebraic equation of the form x'(t) = f(x(t),y(t)) subject to g(x)=0 for a function g:R^n->R^m defining the constraints on the state variable x. I think it should be possible to do that without needing to use fsolve and hence manually building up a numerical method.
For example, it seems reasonable this is possible using sci.integrate.solve_ivp or something similar. Can you suggest some specific effective option?
I am implementing a kalman filter based on a paper. The state-space vector has 6 variables, as the state variable changes with the evaluation of time, and the paper also provides the differential equations of the variables with the evaluation of time (dt).
My question is that when implementing this concept in python, how I should use the differential equation with the dt. I was wondering to simply multiply the equation with dt but I think that this is not the solution as it is a differential equation. Kindly guide me in this respect. Also, I want to ask that as these equations will estimate the new states, so they should be added in the update step? Thanks!
There are two different useful functions for solving ODEs in scipy.integrate - scipy.integrate.odeint() and scipy.integrate.solve_ivp() for initial value problems. I don't know enough about your system to answer your last question.
I am trying to figure out the differences between Optimize.fsolve and SymPys solve function? **Is there a difference in computation or are the constraints as to which method to use?**Is Scipy fsolve more accurate than Numpy solve function?
The obvious difference I found is that Scipy.Optimize.Fsolve can solve non linear equations given a guess value, whereas SymPys solve function can be used to solve equations and expressions that contion symbolic math variables.
Any reference literature or website which you can share will be much appreciated.
Link to Complicated Equation
I'm trying to find Ts for a given time. I have all necessary variables in the above equation, except for Ts. I realized that I can integrate with respect to t, which makes things a little easier. From there, how do I go about solving for Ts?
This is not a root-finding problem. This is a differential equation, which you can solve using e.g. solve_ivp from scipy.integrate. You will need the initial value for T(t=0).
I'm trying to set up a fast numerical solver in Python for a differential problem of the form:
where r is some constant.
I want to integrate A over some time period, t of interest. However, this is complicated by the fact that the dA/dt equation includes another variable B, which itself is described by an ODE dB/dt. B is actually a vector, but I've simplified the expression to try and highlight my problems more clearly.
I currently have a solution using a manual Euler method: ie compute dB/dt (then use B = B_previous + dB/dt * dt) and manually step along using a fixed time step size dt. However, this is slow and unreliable. I imagine it would be far better to use the built-in ODE solvers in Numpy, but I'm not sure this is possible given the coupled nature of the problem I'm trying to solve?
Is this possible using Numpy odeint or solve_ivp please? And if so, can anyone suggest any pointers please! Thanks.
What you have is a coupled differential equation which are standard to solve using Runge kutta, Eulers, and many other methods. You can use this example to guide you in writting your python code:
https://scipy-cookbook.readthedocs.io/items/CoupledSpringMassSystem.html
Keep in mind that that not all equations can be solved with ODEINT. If your ODE is a "stiff" ODE then you will have to choose your algorithm precisely. The definition of a stiff ODE is not completely defined but usually they arise if you have large or non-integral powers of your dependent variable in your ODE.
The first step in solving a coupled ODE though is to use standard methods. If they don't work then look into something else.