0
X0=linspace(-.3,.3,10);
[T,X] = ode45(@difflossy,[0 10],X0);
plot(T,X,'-');

function dX = difflossy(T,X)
    if X<-1
        dX=0;
    else
        dX= X.*(1-X);
    end
end

The above is my code to solve the nonlinear differential equation. The differential equation as a moving singularity in time. I am getting a warning Warning: Failure at t=1.466319e+00. I am getting a graph when tspan is reduced to [0 1]. But I need to know what's happening in a long time. I think an if and for loop imposing a condition such that for values of X less than 1, dX = 0 will solve. But the way I have implemented the same is somewhat wrong. Please help me

rimonmostafiz
  • 1,341
  • 1
  • 15
  • 33
Jasmine
  • 103
  • 3
  • Maybe try a different solver. See [Choose an ODE Solver](https://uk.mathworks.com/help/matlab/math/choose-an-ode-solver.html) in the documentation for more details. – am304 Dec 21 '17 at 10:11
  • Just for interest, as it does not influence the character of the problem, what exactly does `X<-1` compute for an array `X`? – Lutz Lehmann Dec 21 '17 at 11:12

1 Answers1

0

Your differential equation is not continuous. The ode45 solver expects that the derivatives up to 4th order of the ODE function are continuous and "tame". As that is not the case, the internal step size control will regulate the step size down to zero as the solution approaches the jump location resp. phase/mode separation plane.

You could use events to perform a controlled switching between the two phases of the ODE.

Of course any method that does not use an adaptive step size will also produce a more or less accurate result, one would have to explore how much the jump influences the global error.

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51