求助,方程可以解但是画图出错,完全和方程结果无关了
mathematica吧
全部回复
仅看楼主
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
吧务
level 10
我看结果好像挺正常的啊,具体是什么问题?
另外,theta1[t_] = theta1[t] /. sol这种给符号表示加定义的句子最好不要再写了。
2023年07月05日 23点07分 2
已经大概解决了,可能我对一些语法的理解还不到位,谢谢您
2023年07月12日 14点07分
1