OBJECTIVE:
To study basic matrix constructors and operations using Scilab.
SOURCE CODE:
Matrix Constructors:
zeros(3,2)
//
// ans =
// 0. 0.
// 0. 0.
// 0. 0.
eye(2,3)
//
// ans =
// 1. 0. 0.
// 0. 1. 0.
ones(2,2)
//
// ans =
// 1. 1.
// 1. 1.
rand(4,4)
//
// Random 4x4 matrix with values in [0,1]
Matrix Y:
Y = [1 4 6;
2 7 3;
4 1 1];
Basic Operations:
max(Y) // Maximum element
min(Y) // Minimum element
sum(Y) // Sum of all elements (use sum(Y(:)) if needed)
prod(Y) // Product of all elements
Mathematical Functions:
sin(Y)
cos(Y)
tan(Y)
asin(Y)
acos(Y)
exp(Y)
log(Y) // Natural log
log10(Y) // Log base 10
sqrt(Y) // Square root
Floating-Point Functions:
ceil(Y)
floor(Y)
round(Y)
fix(Y) // Truncates values toward zero
nthroot(Y, 4) // 4th root of elements (custom function may be needed in older versions)
Sign Function:
sign(Y)
//
// ans =
// 1. 1. 1.
// 1. 1. 1.
// 1. 1. 1.
Modulo Operations:
modulo(10, 3) // Returns remainder
pmodulo(10, 3) // Returns positive remainder (Scilab specific)
Concatenation:
Z = [9 8 7;
5 6 4;
3 2 1];
cat(1, Y, Z) // Row-wise concatenation
cat(2, Y, Z) // Column-wise concatenation
Matrix Analysis:
A = [1 -2;
-2 0];
det(A) // Determinant
rank(A) // Matrix rank
trace(A) // Sum of diagonal elements
spec(A) // Eigenvalues
RESULT:
Thus, the Matrix constructors and operations in Scilab are successfully executed and verified.