MATLAB7.1 画弹簧摆的运动图,要程序!要在MATLAB7.1 上可以运行的theta0=pi/10 %\fs{初始角度,可由读者设不同的值}m = 1; k = 100; g = 9.8; L0 = 1; L = L0 + m*g/k; %\fs{L0为弹簧原来长度,L为弹簧静止时长度}[t,u1] =
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/29 00:01:14
MATLAB7.1 画弹簧摆的运动图,要程序!要在MATLAB7.1 上可以运行的theta0=pi/10 %\fs{初始角度,可由读者设不同的值}m = 1; k = 100; g = 9.8; L0 = 1; L = L0 + m*g/k; %\fs{L0为弹簧原来长度,L为弹簧静止时长度}[t,u1] =
MATLAB7.1 画弹簧摆的运动图,要程序!
要在MATLAB7.1 上可以运行的
theta0=pi/10 %\fs{初始角度,可由读者设不同的值}
m = 1; k = 100; g = 9.8;
L0 = 1; L = L0 + m*g/k; %\fs{L0为弹簧原来长度,L为弹簧静止时长度}
[t,u1] = ode45('thbfun',[0 :0.005 :15],[L0 0 theta0 0],L,k,m,g);
[y1,x1] = pol2cart(u1(:,3),u1(:,1)); y1 = -y1;
theta0 =
0.3142
Error using ==> funfun\private\odearguments
Correct syntax is ode45(THBFUN,tspan,y0,options).
Error in ==> ode45 at 173
[neq,tspan,ntspan,next,t0,tfinal,tdir,y0,f0,odeArgs,odeFcn,...
这是什么错误,该怎么改,才能运行!
MATLAB7.1 画弹簧摆的运动图,要程序!要在MATLAB7.1 上可以运行的theta0=pi/10 %\fs{初始角度,可由读者设不同的值}m = 1; k = 100; g = 9.8; L0 = 1; L = L0 + m*g/k; %\fs{L0为弹簧原来长度,L为弹簧静止时长度}[t,u1] =
function F = thbfun(t,u,flag,l,k,m,g)
F = [u(2);
u(1)*u(4)^2 + g*cos(u(3)) - k/m*(u(1) - l + m*g/k);
u(4);
-2*u(2)*u(4)/u(1) - g*sin(u(3))/u(1)];
-------------------------------------------------------------
theta0=pi/10 %\fs{初始角度,可由读者设不同的值}
m = 1; k = 80; ; g = 9.8;
L0 = 1; L = L0 + m*g/k; %\fs{L0为弹簧原来长度,L为弹簧静止时长度}
[t,u1] = ode45('thbfun',[0 :0.005 :15],[L0 0 theta0 0],[],L,k,m,g);
[y1,x1] = pol2cart(u1(:,3),u1(:,1)); y1 = -y1;%\fs{将极坐标换为直角坐标}
ymax = max(abs(y1));
axis([-1.2 1.2 -1.2*ymax 0.2]);%\fs{设置坐标范围}
axis off
title('弹簧摆','fontsize',14)
hold on;
R =0.055 ; %\fs{设置弹簧半径}
yy = -L0 :0.01 :0;
xx = R*sin(yy./L0*30*pi);%\fs{用正弦曲线表示弹簧}
[a,r] = cart2pol(xx,yy); %\fs{用坐标变换来画初始位置的弹簧}
a = a + theta0;
[xx,yy] = pol2cart(a,r);%\fs{弹簧的数据}
line([-1 1],[0 0],'color','r','linewidth',2)%\fs{画横杆,球与弹簧}
ball = line(xx(1),yy(1),'color','r','marker','.',...
'markersize',70,'erasemode','xor');
ball2 = line(xx(1),yy(1),'color',[0.5 0.51 0.6],'linestyle','-',...
'linewidth',1.3,'erasemode','none');
spring = line(xx,yy,'color','r','linewidth',2,'erasemode','xor');
pause(0.5)
for i = 1 :length(t) %\fs{画出每一步的弹簧位置}
yy = -u1(i,1) :0.01 :0;
xx = R*sin(yy./u1(i,1)*30*pi);
[a,r] = cart2pol(xx,yy);
a = a + u1(i,3);
[xx,yy] = pol2cart(a,r);
set(ball,'XData',x1(i),'YData',y1(i));
set(ball2,'XData',x1(i),'YData',y1(i));
set(spring,'XData',xx,'YData',yy);
drawnow;
end