Pendulum problem, diff equation, error message

1 次查看(过去 30 天)
I have the following code:
clc;
l=1.3; m=0.1; g=9.82;
theta_1_0=30; theta_1_0=theta_1_0*pi/180;
theta_2_0=150; theta_2_0=theta_2_0*pi/180;
t=linspace(0,2);
options=odeset('RelTol',1e-6,'AbsTol',1e-8);
[t,U]=ode45(@dubbelpendel_vis,t,[theta_1_0 0 theta_2_0 0],options,l,g);
theta_1=U(:,1);
theta_1_prim=U(:,2);
theta_2=U(:,3);
theta_2_prim=U(:,4);
clf;
subplot(1,2,1), plot(t,theta_1*180/pi)
subplot(1,2,2), plot(t,theta_2*180/pi)
And the following function:
function dubbelpendel_vis(t,theta_1,theta_2)
l=1.3;
X1=l*sin(theta_1); Y1=-l*cos(theta_1);
X2=X1+l*sin(theta_2); Y2=Y1-l*cos(theta_2);
figure(2), clf, shg
for k=1:length(t)
clf, axis equal, axis([-2.6 2.6 -2.7 1.2]), axis off, hold on, set(gcf,'color','w')
plot(X1(1:k),Y1(1:k),'r','linewidth',1)
plot(X2(1:k),Y2(1:k),'g','linewidth',1)
plot([0 X1(k)],[0 Y1(k)],'k','linewidth',3)
plot([X1(k) X2(k)],[Y1(k) Y2(k)],'k','linewidth',3)
plot(X1(k),Y1(k),'o','linewidth',1,'markersize',9,'markerfacecolor','r','markeredgecolor','k')
plot(X2(k),Y2(k),'o','linewidth',1,'markersize',9,'markerfacecolor','g','markeredgecolor','k')
hold off
shg
if k==1, pause(1), end
end
But I get the error:
Error using dubbelpendel_vis
Too many input arguments.
Any ideas on what is wrong?

回答(1 个)

bym
bym 2012-12-2
try changing this line
[t,U]=ode45(@dubbelpendel_vis,t,[theta_1_0 0 theta_2_0 0],options,l,g);
to
[t,U]=ode45(@dubbelpendel_vis,t,[0 theta_1_0 theta_2_0],options,l,g);
  1 个评论
Esteban
Esteban 2012-12-2
I tried it and I get the same error. Although I think that line should be as it is, no? Because that's the initial condition.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by