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

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

% set up simulation time range
t = [0 10];

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

x0 = [1 0];
[t_lin_large x_lin_large] = ode45(f_lin_pendulum,t,x0);
[t_nonlin_large x_nonlin_large] = ode45(f_nonlin_pendulum,t,x0);

% visualization
figure(1);
clf;
plot(t_nonlin_small,    x_nonlin_small(:,1),...
     t_lin_small,       x_lin_small(:,1),...
     t_nonlin_large,    x_nonlin_large(:,1),...
     t_lin_large,       x_lin_large(:,1)...
 );

legend('nonlin,small','lin,small','nonlin,large','lin,large')