MATLAB Answers

Edvin
0

Pendulum problem, diff equation, error message

Asked by Edvin
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?

  0 Comments

Products

No products are associated with this question.

1 Answer

Answer by 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

Edvin
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.


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!