% ---
% jupyter:
%   jupytext:
%     text_representation:
%       extension: .m
%       format_name: light
%       format_version: '1.5'
%       jupytext_version: 1.14.4
%   kernelspec:
%     display_name: Octave
%     language: octave
%     name: octave
% ---

% +
size = ceil(rand() * 10^6)

u = rand(1, size);
v = rand(1, size);

w1 = zeros(1, size);
w2 = zeros(1, size);

% +
ti_0 = now();

for i=1:length(u),
    w1(i) = 2 * u(i) + 5 * v(i);
end;

diff_i = now() - ti_0;
disp(diff_i)

% +
tv_0 = now();

w2 = 2 * u + 5 * v;

diff_v = now() -tv_0;
disp(diff_v)
% -

disp(
    sprintf("Relative time vectorial/iterative approach %0.3f%%", diff_v * 100 / diff_i)
)

if sum(w1 == w2) == length(w1),
    disp('Equal vectors');
else
    disp('Something is wrong')
end

StarcoderdataJupyterScriptsDedupFiltered