% this is a script file to demonstrate functions
% Exa = 1;  % choose the example to run

% explain

switch Exa
  case 1                 % vector creation
    x = [1 2 3 4 5]'
    x = [1; 2; 3; 4; 5]
    y = [0 2 4 6 8 10]
    y = 0:2:10
    y = 2*(0:5)
  case 2                 % vector operations
    clear *
    a = [1 2 3]  % create a row vector
    b = [4;5;6]  % create a column vector
    
    a + b      % not permitted, but watch out for broadcasting
    a + b'     % permitted
    a * a      % not permitted
    a * a'     % permitted, leading to the scalar product
    a' * a     % permitted, leading to a 3x3 matrix
    a .* a     % permitted, leading to element wise multiplication
    [a  b']    % permitted, leading to a concatenation of the two vectors
  case 3                 % vectorized code
    clear
    n = 1000;
    x = linspace(-10,10,n);
    y = cos(x);   s = sign(y);
    plot(x,s.*y);
  case 4                % speed of vectorized code
    clear
    N = 100000;
    t0 = cputime();
    for n = 1:N
      x(n) = sin(n);
    end%for
    timer1 = cputime()-t0

    t0 = cputime();
    x = zeros(N,1);
    for n = 1:N
      x(n) = sin(n);
    end%for
    timer2 = cputime()-t0

    t0 = cputime();
    x = sin([1:N]);
    timer3 = cputime()-t0
  case 5                  % matrix operations
    a = [1 2 3; 4 5 6; 7 8 10]
    det(a)    % compute the determinant of the matrix
    inv(a)    % compute the inverse matrix
    a^2       % compute the square of the matrix, using the matrix product
    a.^2      % compute the square of each entry in the matrix
    (a+a')/2  % compute the symmetric part of the matrix
    a*inv(a)  % should yield the identity matrix
    a.*inv(a) % multiply each entry in the matrix with the corresponding
	      % entry in the inverse matrix
  case 6                % solve one system
    A = [1 2 3; 4 5 6; 7 8 0]
%    A = [1 2 3; 4 5 6; 7 8 9]
    b = [1;2;4]
    x = A\b
    test_deviation = A*x-b
end%switch

% define a function stat(), computing the average and standard deviation
% call the above in a script file

% generate elementary graphs in a script file
