close all; clear; clc

pendulums = 100;

states = cell(1, pendulums);

initial = linspace(-2.9, 2.9, pendulums);

for i = 1:pendulums
    states{i} = [initial(i); 0];
end

dt = 0.001;
t = 0:dt:10;

g = 9.8;
l = 1;

plot_data = zeros(pendulums, length(t));

tic
for i = 1:length(t)
    for j = 1:pendulums
        states{j} = states{j} + dt * [states{j}(2); -g * sin(states{j}(1)) /l];
    end
    current_states = cell2mat(states);
    plot_data(:, i) = current_states(1, :);
end
toc

figure
plot(t, plot_data)