【问题标题】:Matlab mass pendulum simulationMatlab质量摆模拟
【发布时间】:2022-01-07 23:43:54
【问题描述】:

我尝试自己模拟质量钟摆来训练我的 matlab 技能。我编写了一个没有错误的函数,但是它并没有做它应该做的事情。

我想为每个时间步迭代它。我的想法是计算当前的力和由此产生的加速度。速度和位置 s 将是所有先前加速度的总和。但不知何故,它忽略了弹簧和摩擦。

The results for the following parameters pendel(80,10,0.2,0.2,2)

function pendel (m,te,k,c,s0)
t = linspace(1,te,100*te);
g = 9.81;
s = zeros(1,length(t));
v = zeros(1,length(t));
a = zeros(1,length(t));

for i = 1:length(t)
    f1 = -m*g;
    f2 = -k*s(i);
    f3 = -v(i)*c;
    a(i) = (f1+f2+f3)/m;
    v(i) = sum(a(1:i));
    s(i) = sum(v(1:i))+s0;
end

subplot(3,1,1);
plot (t,s)
title('Ortsdiagramm')

subplot(3,1,2);
plot(t,v)
title('Geschwindigkeitsdiagramm')

subplot(3,1,3);
plot(t,a)
title('Beschleunigungsdiagramm')

end

【问题讨论】:

  • 您可能希望在某些地方与时间步长相乘。另请查看 Euler 方法,以更有效地计算您在此处所做的工作。然后考虑使用更高阶的方法。还要阅读弹簧和钟摆之间的区别。

标签: matlab simulation physics differential-equations pendulum


【解决方案1】:

我现在明白了, 对于每次迭代,我都使用了 v(i) 和 s(i) 的当前值,它们为零,因为它们在迭代后得到了新值。我对其进行了调整,以便使用 i-1 条目来计算摩擦力和弹簧力。

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-23
  • 1970-01-01
  • 2016-03-19
  • 1970-01-01
相关资源
最近更新 更多