【发布时间】: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