Pendulum problem, diff equation, error message

조회 수: 2 (최근 30일)
Esteban
Esteban 2012년 12월 2일
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