範例 共 4 個步驟,在同一個工作階段中依序執行。每一步都在引擎上實際執行過,下方的輸出就是它產生的結果。
de[δ_] := {Subscript[x, 1]'[t] == Subscript[x, 2][t], Subscript[x, 2]'[t] == -Subscript[x, 1][t] + 2δ Subscript[x, 2][t] + 1};
ic = {Subscript[x, 1][0] == .5, Subscript[x, 2][0] == .5};
sol = NDSolve[{de[0.1], ic, WhenEvent[And[Subscript[x, 2][t] == 0, Subscript[x, 1][t] < 0], {Subscript[x, 1][t] -> -Subscript[x, 1][t]}]}, {Subscript[x, 1], Subscript[x, 2]}, {t, 0, 500}];沒有輸出——這個步驟是在為下一步做準備。
Row[Map[ParametricPlot[{Subscript[x, 1][t], Subscript[x, 2][t]} /. sol, {t, 0, #}, PlotPoints -> 500, PlotRange -> {{-1, 2.5}, {-2, 1.5}}]&, {10, 50, 150}]]-Graphics--Graphics--Graphics-resetOsc[δ_] := NDSolve[{de[δ], ic, WhenEvent[And[Subscript[x, 2][t] == 0, Subscript[x, 1][t] < 0], {Subscript[x, 1][t] -> -Subscript[x, 1][t]}]}, {Subscript[x, 1], Subscript[x, 2]}, {t, 0, 500}];
{sol1, sol2, sol3} = Map[resetOsc, {.1, .15, .2}];沒有輸出——這個步驟是在為下一步做準備。
Grid[{Map[ParametricPlot[{Subscript[x, 1][t], Subscript[x, 2][t]} /. sol1, {t, 0, #}, PlotPoints -> 500, PlotRange -> {{-3, 3}, {-3, 3}}]&, {10, 50, 150}],
Map[ParametricPlot[{Subscript[x, 1][t], Subscript[x, 2][t]} /. sol2, {t, 0, #}, PlotPoints -> 500, PlotRange -> {{-3, 3}, {-3, 3}}, PlotStyle -> Green]&, {10, 50, 150}], Map[ParametricPlot[{Subscript[x, 1][t], Subscript[x, 2][t]} /. sol3, {t, 0, #}, PlotPoints -> 500, PlotRange -> {{-3, 3}, {-3, 3}}, PlotStyle -> Red]&, {10, 50, 150}]}]Grid[{{-Graphics-, -Graphics-, -Graphics-}, {-Graphics-, -Graphics-, -Graphics-}, {-Graphics-, -Graphics-, -Graphics-}}]所有操作範例 · 函式參考 · 從 MCP 用戶端使用這個