Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with ODE solving

Tags:

julia

I'm trying to solve typical example from the DifferentialEquation package, according to the guide from their page.

Here is the example:

using DifferentialEquations
using Plots

function lorenz(t,u, du)
    du[1] = 10.0(u[2]-u[1])
    du[2] = u[1]*(28.0-u[3]) - u[2]
    du[3] = u[1]*u[2] - (8/3)*u[3]
end
   
u0 = [1.0;0.0;0.0]
tspan = (0.0,100.0)
prob = ODEProblem(lorenz,u0,tspan)
sol = solve(prob)
plot(sol,vars=(1,2,3))

Then I get:

ERROR: LoadError: Parameters were indexed but the parameters are nothing. You likely forgot to pass in parameters to the DEProblem!

What is wrong here? Thanks in advance!

like image 389
Sergei Avatar asked Nov 10 '20 12:11

Sergei


People also ask

Is ODE or PDE harder?

ODEs involve derivatives in only one variable, whereas PDEs involve derivatives in multiple variables. Therefore all ODEs can be viewed as PDEs. PDEs are generally more difficult to solve than ODEs.

Can every ODE be solved?

The answer is in fact yes (under usual conditions for existence and uniqueness).

How to solve Ode long-time integration problems?

Long-time integration is a hard problem. Break tspan into smaller pieces. If the ODE function does not change noticeably on the tspan interval, it could be that your problem is stiff. Try using one of the stiff solvers ode15s, ode23s, ode23t, or ode23tb. Finally, make sure that the ODE function is written in an efficient way.

How can I improve my ode function?

If the ODE function does not change noticeably on the tspan interval, it could be that your problem is stiff. Try using one of the stiff solvers ode15s, ode23s, ode23t, or ode23tb. Finally, make sure that the ODE function is written in an efficient way. The solvers evaluate the derivatives in the ODE function many times.

How to use ode45 solver?

The syntax for the solvers is [t,y] = ode45 (odefun, [t0 tf],y0); and the syntax accepts t0 > tf. My integration proceeds very slowly, using too many time steps. First, check that tspan is not too long. Remember that the solver uses as many time points as necessary to produce a smooth solution.

How to solve backward and forward in Ode?

All the solvers of the ODE suite allow you to solve backward or forward in time. The syntax for the solvers is [t,y] = ode45 (odefun, [t0 tf],y0); and the syntax accepts t0 > tf. My integration proceeds very slowly, using too many time steps. First, check that tspan is not too long.


1 Answers

You could try to follow this example which builds on what you've done:

using DifferentialEquations
using Plots

function lorenz(du,u,p,t)
 du[1] = p[1]*(u[2]-u[1])
 du[2] = u[1]*(p[2]-u[3]) - u[2]
 du[3] = u[1]*u[2] - p[3]*u[3]
end

u0 = [1.0;0.0;0.0]
tspan = (0.0,100.0)
p = (10.0,28.0,8/3)
prob = ODEProblem(lorenz, u0, tspan,p)
sol = solve(prob)
xyzt = plot(sol, plotdensity=10000,lw=1.5)
xy = plot(sol, plotdensity=10000, vars=(1,2))
xz = plot(sol, plotdensity=10000, vars=(1,3))
yz = plot(sol, plotdensity=10000, vars=(2,3))
xyz = plot(sol, plotdensity=10000, vars=(1,2,3))
plot(plot(xyzt,xyz),plot(xy, xz, yz, layout=(1,3),w=1), layout=(2,1))
like image 188
Serge de Gosson de Varennes Avatar answered Jan 04 '23 08:01

Serge de Gosson de Varennes