MATLAB Answers

Pendulum problem, diff equation, error message

1 view (last 30 days)
Esteban
Esteban on 2 Dec 2012
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?

Answers (1)

bym
bym on 2 Dec 2012
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 Comment
Esteban
Esteban on 2 Dec 2012
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by