level 1
31431271a
楼主
如题,想问问bug出在哪了,代码如下:
Clear["Global`*"]; Remove["Global`*"]; Get["VariationalMethods`"];
x0[t_] := Cos[omega*t]; y0 = 0; xx1[t_] := x0[t] + l*Cos[theta1[t]];
yy1[t_] := (-l)*Sin[theta1[t]];
ek[t_] := 0.5*m*(Derivative[1][xx1][t]^2 + Derivative[1][yy1][t]^2);
ep[t_] := m*9.81*yy1[t]; lag[t_] := ek[t] - ep[t];
equ = EulerEquations[lag[t], theta1[t],
t]; m = 1; l = 2; omega = 2; ini = {theta1[0] == 0.,
Derivative[1][theta1][0] == 0};
sol = NDSolve[{equ, ini}, theta1, {t, 0, 50},
Method -> {"IndexReduction" -> "Pantelides",
"EquationSimplification" -> "Residual"}];
theta1[t_] = theta1[t] /. sol;
fig[t_] :=
ListLinePlot[{{x0[t], 0}, {xx1[t][[1]], yy1[t][[1]]}},
PlotRange -> {{-2.5, 2.5}, {-2.5, 2.5}}, AspectRatio -> 1,
PlotLabel -> "摆",
PlotMarkers -> {"\[FilledCircle]", 20}];
gif = Table[fig[t], {t, 0, 50, 1/24}];
ListAnimate[gif, 24]
2023年07月04日 09点07分
1
Clear["Global`*"]; Remove["Global`*"]; Get["VariationalMethods`"];
x0[t_] := Cos[omega*t]; y0 = 0; xx1[t_] := x0[t] + l*Cos[theta1[t]];
yy1[t_] := (-l)*Sin[theta1[t]];
ek[t_] := 0.5*m*(Derivative[1][xx1][t]^2 + Derivative[1][yy1][t]^2);
ep[t_] := m*9.81*yy1[t]; lag[t_] := ek[t] - ep[t];
equ = EulerEquations[lag[t], theta1[t],
t]; m = 1; l = 2; omega = 2; ini = {theta1[0] == 0.,
Derivative[1][theta1][0] == 0};
sol = NDSolve[{equ, ini}, theta1, {t, 0, 50},
Method -> {"IndexReduction" -> "Pantelides",
"EquationSimplification" -> "Residual"}];
theta1[t_] = theta1[t] /. sol;
fig[t_] :=
ListLinePlot[{{x0[t], 0}, {xx1[t][[1]], yy1[t][[1]]}},
PlotRange -> {{-2.5, 2.5}, {-2.5, 2.5}}, AspectRatio -> 1,
PlotLabel -> "摆",
PlotMarkers -> {"\[FilledCircle]", 20}];
gif = Table[fig[t], {t, 0, 50, 1/24}];
ListAnimate[gif, 24]