我正在尝试在Malab中实现动画效果。从本质上讲,它是质量弹簧系统的仿真。我正在Matlab中实现一个弹簧质量系统的动画。固体质量(m)附着在螺旋弹簧上。弹簧刚性地固定在一端,弹簧和附接的质量块沿着水平表面自由地移动。如下图所示:
固定端弹簧附着质量
| - /////////////////////// [|||||||]
| ----------------------------------------- X = 0-- --------------> x轴
图1.平衡弹簧 - 质量系统
我们假设: (1)如果弹簧被压缩长度为L米,则它在质量上沿正x轴方向施加k L的力; (2)如果弹簧拉伸L长度,则它在质量上沿负x轴方向施加k L的力。 (3)弹簧是一个线性弹簧。
这是用于实现上图的数学模型,
x = e ^( - h / 2m)t(C1 cos(ɷt)+ C2 sin(ɷt))
Vo =( - h)/ 2m C1 +C2ɷ
其中C1 = Xo,C2 = 1 /ɷ(Vo + h / 2m xo)和ɷ=√(4mk-h ^ 2)/ 2m
表示X值范围为0,1,2 ... n。 使用这些输入参数:
V0 - 初始速度(双精度) X0 - 初始位置(双精度) k, - 弹簧常数(正)(双精度) m - 物体质量(双精度) h - 时间步长(双精度)
I need to implement this model in a spring mass system as shown above in Matlab. I have however, managed to come up with these :
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h1=handles.axes1;
h2=handles.axes2;
h3=handles.axes3;
h4=handles.axes4;
t=0:0.1:10;
M=str2num(get(handles.M_value,'String'));
H=str2num(get(handles.H_value,'String'));
K=str2num(get(handles.K_value,'String'));
Xo=str2num(get(handles.Initial_X_value, 'String'));
Vo=str2num(get(handles.Initial_V_value, 'String'));
C1=Xo;
W=((4*M*K-H^2)^0.5)/(2*M);
C2=(1/W)*(Vo+H/(2*M)*Xo);
X=exp(-H/(2*M).*t).*(C1*cos(W.*t)+C2*sin(W.*t));
V=exp(-H/(2*M).*t).*((-H/(2*M)*C1+W*C2).*cos(W.*t)-(H/(2*M)*C2+W*C1).*sin(W.*t));
axes(h1);
plot(t,X,'b.','MarkerSize',5);
axes(h3);
plot(X,V,'b.','MarkerSize',5);
axes(h2);
plot(t,V,'b.','MarkerSize',5);
% this graph displays the animation of the Spring mass system's movement
axes(h4);
clc
clear;
%Set an array of abscissas
x=-10:0.1:10;
% We then get an array of cordinates
y=x.*x;
% we then represent the gradual construction of the schedule by
%Looping from #1 throughout the entire elements in the array x
for j=1:length(x)
%Build a graph of the points from the first to the j-th
plot(x(1:j),y(1:j),'-b', 'LineWidth' , 1)
%Draw the background grid
grid on
%Fix a graph
hold on
%Draw a point on the graph (the end point of the graph)
plot(x(j),y(j), '.g' , 'MarkerSize', 20)
%Fix Coordinates of the plane: from 0 to 5 for the x axis and from 0 to
%5 on the y axis.
axis([-10 10 0 100])
%Turn off the lock to draw a graph for the next redrawing
hold off
%remember the current frame
F(j)= getframe;
end
Figure showing the portrait diagrams for the 4 plots 对于3幅肖像,但最终的肖像似乎并没有像我需要的那样显示出来。我谦卑地请求你放纵解决这个挑战。谢谢。