2
$\begingroup$

Following Code was simulated easy in Wolfram System Modeler. But how to implement this equation in NDSolve? Mathematica code:

sol = NDSolve[{v'[t] + a[t] - b[t - 1] == 0, v[t] == a[t] + b[t - 1], 
    b[t] == -a[t - 1]/3, a[t /; t < 0] == 0, b[t /; t < 0] == 0, 
    v[t /; t < 0] == 0, WhenEvent[t > 1, v[t] -> 1]}, {a, b, v}, {t, 0, 10}];

Gives: Error test failure at t == 1.9999999999999432`; unable to continue. >> System Modeler solver gives: SystemModeler results:

$\endgroup$
1
  • 1
    $\begingroup$ Please display your code in Mathematica format. $\endgroup$
    – bbgodfrey
    Oct 30 '16 at 19:17
3
$\begingroup$

Like so:

sol = NDSolveValue[{v'[t] + a[t] - b[t - 1] == 0, 
    v[t] == a[t] + b[t - 1], b[t] == -a[t - 1]/3, a[t /; t < 0] == 0, 
    b[t /; t < 0] == 0, v[t /; t < 0] == 0, 
    WhenEvent[t > 1, v[t] -> 1]}, {a[t], b[t], v[t]}, {t, 0, 10}, 
   Method -> {"EquationSimplification" -> "MassMatrix"}, 
   MaxStepSize -> 0.025];
Plot[Evaluate[sol], {t, 0, 10}, PlotRange -> All]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.