% Simple MATLAB Functions
% Tasks: input matrics, find their eigenvalues, use for loops, read and write out information
% Input matrices A and B
% Then find their eigenvalues
clc   % clear the command windo
clear % clear the workspace
A=[1 2 3; 4 5 6; 7 8 9]  % ";" separates the rows
B= [10 20 30
    40 50 60
    70 80 90]; % new line separates the rows, ";" at the end means suppress print out
fprintf (1,'eigenvalues of A are: first eigenvalue %10.3f second eigenvalue %10.3f third eigenvalue %10.3f', eig(A))

format long
eig(B)
% write out data to a comma separated value (csv) file that Excel can read
csvwrite('MatrixA.csv', A)
csvwrite ('MatrixB.csv', B)

% read a file from csv format into MATLAB
C= csvread('MatrixB.csv')
C-B

% for loops
for i=1:3
  for j=1:3
    D(i,j) = i+j;
  end
end
eig (D)