pkg load control

% nonlinear pendulum as anonymous (lambda) function 
l = 1;
g = 9.81;
f_nonlin_pendulum = @(x,t) [x(2) (-g/l * sin(x(1)))];

% linear pendulum as anonymous (lambda) function 
f_lin_pendulum    = @(x,t) [x(2) (-g/l * x(1))];

% set up time steps
t = (0:0.02:10);

% simulate system starting at x0
x0 = [0.1 0];
x_lin_small     = lsode(f_lin_pendulum,x0,t);
x_nonlin_small  = lsode(f_nonlin_pendulum,x0,t);

x0 = [1 0];
x_lin_large     = lsode(f_lin_pendulum,x0,t);
x_nonlin_large  = lsode(f_nonlin_pendulum,x0,t);

% visualization
figure(1);
clf;
plot(t,[x_nonlin_small(:,1),x_lin_small(:,1),...
        x_nonlin_large(:,1),x_lin_large(:,1)]);
legend('nonlin,small','lin,small','nonlin,large','lin,large')