OBJECTIVE:
To study Matrix Bitwise operations, Relational Operations, and Logical Operations in Scilab.
SOURCE CODE:
Relational Operators: <, <=, >, >=, ==, ~=
X = 5 * ones(3,3); // Create a 3x3 matrix of 5's
// X >= [1 2 3; 4 5 6; 7 8 9]
X >= [1 2 3; 4 5 6; 7 8 9]
/*
ans =
T T T
T T F
F F F
*/
X <= [1 2 3; 4 5 6; 7 8 9]
/*
ans =
F F F
F T T
T T T
*/
X < [1 2 3; 4 5 6; 7 8 9]
/*
ans =
F F F
F F T
T T T
*/
X ~= [1 2 3; 4 5 6; 7 8 9]
/*
ans =
T T T
T F T
T T T
*/
Logical Operators: and, or, not
a = 0;
b = 10;
if a & b then
disp("Condition is true");
else
disp("Condition is false");
end
if a | b then
disp("Condition is true");
end
if ~a then
disp("Condition is true");
end
// Running a script using exec
exec('C:\Users\admin\Documents\relational.sce', -1);
// Outputs:
// Condition is false
// Condition is true
Bitwise Operators:
U = [0 0 1 1 0 1]; // Bitwise vector U
V = [0 1 1 0 0 1]; // Bitwise vector V
// Bitwise OR operation
U | V
/*
ans =
F T T T F T
*/
// Bitwise AND operation
a = 60; // 0011 1100
b = 13; // 0000 1101
c = bitand(a, b); // Bitwise AND
disp(c); // Output: 12
// Bitwise OR operation
d = bitor(a, b); // Bitwise OR
disp(d); // Output: 61
// Bitwise XOR operation
e = bitxor(a, b); // Bitwise XOR
disp(e); // Output: 49
RESULT:
The study on Relational, Logical, and Bitwise operations on matrices in Scilab is successfully performed.