% loop_test.m  2011-11-14
% example of doing a loop and calculations with vectors
clear;clc;
disp(sprintf(' MATLAB example: loop_test.m'));
%
firstvec(1:3) = 12.0;
secondvec(1) = 2.0;
secondvec(2) = 4.0;
secondvec(3) = 6.0;

disp(sprintf('firstvec')); disp(sprintf('%f \n', firstvec ))
disp(sprintf('secondvec')); disp(sprintf('%f \n', secondvec ))
%
% starting point at the first node
thirdvec(1) = firstvec(1)/secondvec(1);
disp(sprintf('thirdvec')); disp(sprintf('%f \n', thirdvec(1) ))
%
N = 3;
disp(sprintf('===== forward loop ====='));
for i=2:N
    disp (sprintf('i = %d',i));
    thirdvec(i) =  firstvec(i)/secondvec(i-1);
disp(sprintf('thirdvec')); disp(sprintf('%f \n', thirdvec ))
end

disp(sprintf('===== backward loop ====='));
for i=N-1:-1:1
    disp (sprintf('i = %d',i));
    thirdvec(i) =  firstvec(i)/secondvec(i+1);
    disp(sprintf('thirdvec')); disp(sprintf('%f \n', thirdvec ))
end
%
