Qurak

Billiard balls

مثال 5 خطوات تُشغَّل بالترتيب في جلسة واحدة. كل خطوة نُفِّذت على المحرك والمخرج أدناه هو ما أنتجته.

الخطوة 1
{sol1, sol2} = Map[NDSolve[{x'[t] == a[t], y'[t] == b[t], x[0] == 0, y[0] == 0, a[0] == 1, b[0] == #, WhenEvent[x[t] ^ 2 == 1, a[t] -> -a[t]], WhenEvent[y[t] ^ 2 == 1, b[t] -> -b[t]]}, {x, y}, {t, 0, 100}, DiscreteVariables -> {a, b}]&, {Rationalize[Sqrt[2], .01], Sqrt[2]}];

لا مخرجات - هذه الخطوة تجهّز شيئًا للخطوة التالية.

الخطوة 2
GraphicsGrid[{Map[ParametricPlot[{x[t], y[t]} /. sol1, {t, 0, #}, Frame -> True, FrameTicks -> None, PlotRange -> 1, Axes -> False, PlotStyle -> Blue]&, {5, 20, 100}],
	Map[ParametricPlot[{x[t], y[t]} /. sol2, {t, 0, #}, Frame -> True, FrameTicks -> None, PlotRange -> 1, Axes -> False, PlotStyle -> Red]&, {5, 20, 100}]}, ImageSize -> Large]
المخرجات
-Graphics-
الخطوة 3
ball3d[r1_ ? NumericQ, r2_ ? NumericQ] := NDSolve[{x'[t] == a[t], y'[t] == b[t], z'[t] == c[t], x[0] == 0, y[0] == 0, z[0] == 0, a[0] == 1, b[0] == r1, c[0] == r2, WhenEvent[x[t] ^ 2 - 1, a[t] -> -a[t]], WhenEvent[y[t] ^ 2 - 1, b[t] -> -b[t]], WhenEvent[z[t] ^ 2 - 1, c[t] -> -c[t]]}, {x[t], y[t], z[t]}, {t, 0, 200}, DiscreteVariables -> {a, b, c}];

لا مخرجات - هذه الخطوة تجهّز شيئًا للخطوة التالية.

الخطوة 4
{sol3d1, sol3d2} = {ball3d[1 / 3, 2 / 3], ball3d[Sqrt[2], Sqrt[3]]};

لا مخرجات - هذه الخطوة تجهّز شيئًا للخطوة التالية.

الخطوة 5
GraphicsGrid[{Map[ParametricPlot3D[{x[t], y[t], z[t]} /. sol3d1, {t, 0, #}, Axes -> False, PlotStyle -> Blue]&, {5, 20, 100}],
	Map[ParametricPlot3D[{x[t], y[t], z[t]} /. sol3d2, {t, 0, #}, Axes -> False, PlotStyle -> Red]&, {1, 50, 200}]}, ImageSize -> Large]
المخرجات
-Graphics-

الدوال المستخدمة

وصفات ذات صلة

كل الوصفات · مرجع الدوال · استخدم هذا من عميل MCP