// Scilab file made available as part of TEQIP-NCM-NBHM workshop: Nov 2019
//Tested on scilab version 6.0.1
// Conducted at IIT Bombay. Scilab scripts written by Sudarshan Pulapadi
// License: GPL
//


//Find determinants amd eigenvalues
A = [1 2 3; 4 5 6;8 9 10];

//-->determinant of A
D = det(A)

//--> eigen values of A
spec(A)

//--> eigen values and eigen vectors pf A
[E,V] =spec(A)



// Solve Ax + b = 0
A = [2 3 4 5;5 6 9 1;7 8 2 6];
b = [5 11 15]';

//-->  solves for x
linsolve(A,b)

//--> solves for x and gives kernal splace of A
[X,ker] = linsolve(A,b)



//Svd 
A = [1 2 3; 4 5 6;8 9 10];

//--> singular values of A
svd(A)

//--> finds u,s,v for singular value decomposition of A
[u,s,v] = svd(A)

//--> verify that u*s*v' = A (by subtracting and taking norm, etc)
A - u*s*v'

//--> things will not be exactly zero: so use norm (and first without norm.)
norm(A - u*s*v')



// Rank of A
A = [2 3;5 6;7 8];
b = [1 2 3]';
c = [5 4 2]';
d = [6 6 5]';

//-->rank of a matrix 
rank(A)

//--> rank of stacked columns
rank([b c d])

//-->check if a new vector is in span of columns of a matrix: for example
//   for solvability. Ax = b: if vector b is in span of columns of matrix A
rank([A b])



//Generate Random vectors or matrices

//--> random seed to get different random value at every session
rand('seed',getdate('s'))

//--> random matrix of size(4,5):
rand(4,5)

//--> random matrix of size same as A
rand(A)

//--> This would give only a random number so for random vector put (1,4)
rand(4) 

