Search code examples
matlabodematlab-deploymentdifferential-equations

Error in `ode45` matlab


The main function of ode is given as follows.

function dxdt = state( t,x,vgth,vgval1,vgval2)
vgval=vgval1+vgval2;
p=1;
k=10^0.7;
window1=1-((2*x)-1).^(2*p); 
dxdt=k*(vgval-vgth+1.2)*window1;  
end

The Script is given below.

step=0.01;
t = 0:step:10;
f=4*0.157;
vgate1= @(t) abs(5*sin(2*f*t)).*heaviside(5-t);
vgate2=@(t) -abs(5*sin(2*f*t)).*heaviside(t-5);

The Function call part is as follows.

x0=0.01;
vgth=1.9;
[t,x] = ode45(@(t,x) state1 (t,x,vgth,vgate1(t),vgate2(t)), t, x0);
plot(t,x)

Issue It gives me error when I use the negative sign with vgate2 . It works fine If i remove the negative sign of vgate2.

Desired Result I want my plot with a negative sign in vgate2.Actually I want to use two positive sine pulses and two negative sign pulses.That is why I have used negative value of vgate2.


Solution

  • ODE integrators of order p expect the differential equation to be p+2 times continuously differentiable with decent sized derivatives.

    Any deviation from that is seen as "stiffness" by step-size adaptation strategies, and reacted to by increasingly violent reductions in step-size. Any kink or jump in the lower derivatives is seen as similar to wild oscillations in the higher derivative, throwing the step-size adaptor for a loop.

    However, if the integration is stopped directly at an event and then restarted using the values there as initial values, the integrator does not "see" the event, and thus has no need to react to it.