Advertisement
Guest User

Untitled

a guest
Sep 20th, 2014
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. a = 10;
  2. sol = NDSolve[{x'[t] == -10, x[0] == 10}, x, {t, 0, 10}];
  3. Plot[Evaluate[x[t] /. sol], {t, 0, 10}, PlotRange -> All]
  4.  
  5. Clear[a];
  6. sol = NDSolve[{x'[t] == -a[t], x[0] == 10, a'[t] == 0, a[0] == 10,
  7. WhenEvent[x[t] == 0, a[t] -> 0]}, x, {t, 0, 10}];
  8.  
  9. Plot[Evaluate[x[t] /. sol], {t, 0, 10}, PlotRange -> All]
  10.  
  11. solval = Piecewise[{{#[t], #[[1, 1]] <= t <= #[[1, 2]] &@#["Domain"]}}] &@
  12. NDSolveValue[{x'[t] == -10, x[0] == 10,
  13. WhenEvent[x[t] < 0, "StopIntegration"]}, x, {t, 0, 10}];
  14.  
  15. Plot[solval, {t, 0, 10}, PlotRange -> All]
  16.  
  17. solval = NDSolveValue[{x'[t] == -10, x[0] == 10,
  18. WhenEvent[x[t] < 0, "StopIntegration"]}, x, {t, 0, 10},
  19. "ExtrapolationHandler" -> {0 &, "WarningMessage" -> False}]
  20.  
  21. a = 10;
  22. sol = NDSolve[{x'[t] == If[x[t] >= 0, -10, 0], x[0] == 10}, x, {t, 0, 10}];
  23. Plot[Evaluate[x[t] /. sol], {t, 0, 10}, PlotRange -> All]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement