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