1
PROGRAM : 1
AIM : WAP to perform exercises for implementing the basic matrix operations in Scilab .
Matrix Multiplication :
CODE :
// Define matrices A and B
A = [11,22,43; 43,55,66; 78,87,91];
B = [31,72,10; 42,55,40; 89,28,17];
// Display results
disp("The first matrix is :");
disp(A);
disp("The second matrix is :");
disp(B);
//matrix multiplication and display result
disp("A.) The multiplication of Matrix A with B :" , A*B);
OUTPUT :
35815003122|Harshita Sahrawat | [50]
2
Matrix Addition :
CODE :
// Define matrices A and B
A = [11,22,43; 43,55,66; 78,87,91];
B = [31,72,10; 42,55,40; 89,28,17];
// Matrix Addition
C_add = A + B;
// Display results
disp("The first matrix is :", A);
disp("The second matrix is :", B);
disp("B.) The sum of the Matrices A and B :", C_add);
OUTPUT :
35815003122|Harshita Sahrawat | [50]
3
Matrix Transpose :
CODE :
// Define matrices A and B
A = [11,22,43; 43,55,66; 78,87,91];
B = [31,72,10; 42,55,40; 89,28,17];
// Transpose of matrices
A_transpose = A';
B_transpose = B';
// Display results
disp("The first matrix is : " , A);
disp("The second matrix is :" , B);
disp("C.) [i] The transpose of the matrix A :" , A_transpose);
disp(" [ii] The transpose of the matrix B :" , B_transpose );
OUTPUT :
35815003122|Harshita Sahrawat | [50]
4
PROGRAM : 2
AIM : WAP to perform exercises for finding the Eigenvalues and Eigenvectors in Scilab.
Eigen – Values :
CODE :
// Define matrices A and B
A = [11,2,3; 4,55,6; 7,8,99];
B = [3,7,1; 2,5,4; 9,1,8];
// Compute Eigenvalues for A
eigvals_A = spec(A);
// Compute Eigenvalues for B
eigvals_B = spec(B);
// Display results
disp("The first matrix is :" , A);
disp("The Eigen-values of matrix A are :" , eigvals_A);
disp("The second matrix is :" , B);
disp("The Eigen-values of matrix B are :" , eigvals_B);
OUTPUT :
35815003122|Harshita Sahrawat | [50]
5
Eigen – Vectors :
CODE :
// Define matrices A and B
A = [11,2,3; 4,55,6; 7,8,99];
B = [3,7,1; 2,5,4; 9,1,8];
// Compute Eigenvectors for A
[eigvecs_A] = spec(A, "vectors");
// Compute Eigenvectors for B
[eigvecs_B] = spec(B, "vectors");
// Display results
disp("The first matrix is :" , A);
disp("The second matrix is :" , B);
disp("The corresponding Eigen-vectors of matrix A is :" , eigvecs_A);
disp("The corresponding Eigen-vectors of matrix B is :" , eigvecs_B);
OUTPUT :
35815003122|Harshita Sahrawat | [50]
6
PROGRAM : 3
AIM : WAP to perform exercises for solving equations by Gauss Elimination , Gauss Jordan Method ,
Gauss Siedel in Scilab.
Gauss Elimination:
CODE :
clc;
A = [7, 0, 1; 3, 4, 4; 9, 6, 1]; // Coefficient matrix
B = [5; 8; 49]; //Right-hand side vector
A1 = A;
B1 = B;
disp("The matrix is :");
disp([A, B]); // Display augmented matrix [A | B]
// Forward Elimination (Gaussian Elimination)
for i = 1:size(A, 1)
m = A(i, i);
A(i, :) = A(i, :) / m; // Normalize the row
B(i) = B(i) / m;
for j = i + 1:size(A, 1)
m2 = A(j, i);
A(j, :) = A(j, :) - m2 * A(i, :);
B(j) = B(j) - m2 * B(i);
end
end
disp("After forward elimination (Upper Triangular Matrix):");
disp([A B]); // Display the matrix after forward elimination
//Back Substitution
x = zeros(1, 3); //Initialize the solution vector
x(3) = B(3) / A(3, 3);
for i = 2:-1:1
sum_val = 0;
for j = i + 1:size(A, 1)
sum_val = sum_val + A(i, j) * x(j);
end
x(i) = (B(i) - sum_val) / A(i, i); //Solve for the current unknown
end
disp("The Roots are: ");
disp(x'); // Display the solution vector (roots)
35815003122|Harshita Sahrawat | [50]
7
OUTPUT :
35815003122|Harshita Sahrawat | [50]
8
Gauss Jordan Method:
CODE :
clc;
A = [2, 1, 1; 3, 2, 3; 4, 6,
3]; //Coefficient matrix
B = [10; 12; 89]; //Right-hand side vector
A1 = A;
B1 = B;
disp("The augmented matrix is:");
disp([A, B]); //Display augmented matrix [A | B]
for i = 1:size(A, 1)
//Normalize the pivot row
m = A(i, i);
A(i, :) = A(i, :) / m;
B(i) = B(i) / m;
//Make other elements in column i zero
for j = 1:size(A, 1)
if i ~= j
m2 = A(j, i);
A(j, :) = A(j, :) - m2 * A(i, :);
B(j) = B(j) - m2 * B(i);
end
end
end
disp("Matrix in Reduced Row Echelon Form:");
disp([A B]);
//The solution is now in vector B
disp("The Roots are: ");
disp(B); //The roots are the elements of B after elimination
35815003122|Harshita Sahrawat | [50]
9
OUTPUT :
35815003122|Harshita Sahrawat | [50]
10
Gauss Siedel:
CODE :
clc
A = [4 1; 4 6];
b = [6; -8];
//Define the size of the system (2 equations, 2 unknowns)
m = 2;
// Initialize the solution vector x with zeros (initial guess)
x = zeros(m, 1);
//Set the maximum number of iterations for the iterative method
MaxIter = 100;
mprintf("iteration no. x1 computation x2 computation")
//Start the iteration process for the Jacobi method
for Iter = 0:MaxIter
prev_x = x; //Save the current solution vector for convergence check
for i = 1:m
s = 0;
//Loop through the other variables (j != i) to calculate the sum
for j = 1:m
if i ~= j //Avoid using the diagonal element A(i,i)
s = s + A(i, j) * x(j);
end
end
//Compute the new value for x(i) based on the current sum
x(i) = (b(i) - s) / A(i, i); //Use the equation A*x = b to update x(i)
end
//Print the current iteration no. and the updated solution vector x
mprintf("\n\n\t%d", Iter)
mprintf("\t %f", x)
//Check if the solution has converged by comparing the norm of the
difference
if norm(x - prev_x) < 0.0001 // If the change is small enough, stop iterating
break //Exit the loop if the solution has converged
end
prev_x = x; //Update prev_x for the next iteration
35815003122|Harshita Sahrawat | [50]
11
end
//Print the final approximate solution after the iterations
mprintf("\n\nThe approximate solutions are: \n\n");
mprintf("\t %f", x)
OUTPUT :
35815003122|Harshita Sahrawat | [50]
12
PROGRAM : 4
AIM : WAP to perform exercises for implementing the associative, commutative and distributive
property in a matrix in Scilab.
Associative Property :
CODE :
// Define matrices A, B, and C
disp("The original matrices are:");
A = [7 9; 4 6];
B = [3 5; 2 10];
C = [7 5; 8 1];
disp("Matrix A:");
disp(A);
disp("Matrix B:");
disp(B);
disp("Matrix C:");
disp(C);
// Compute (A + B) + C
disp("\nVerifying the Associative Property of Matrix Addition:");
disp("(A + B) + C Calculation:");
AB = A + B;
AB_C = AB + C;
disp(AB_C);
// Compute A + (B + C)
disp("A + (B + C) Calculation:");
BC = B + C;
A_BC = A + BC;
disp(A_BC);
35815003122|Harshita Sahrawat | [50]
13
// Verify associative property
disp("Final Verification: Are both matrices equal?");
if (AB_C == A_BC) then
disp("Yes, (A + B) + C is equal to A + (B + C). The associative property holds.");
else
disp("No, the matrices are not equal. The associative property does not hold.");
end
OUTPUT :
35815003122|Harshita Sahrawat | [50]
14
Commutative Property :
CODE :
# // Define matrices A and B
disp("The original matrices are:");
A = [7 9; 4 6];
B = [3 5; 2 10];
disp("Matrix A:");
disp(A);
disp("Matrix B:");
disp(B);
// Compute A + B
disp("\nVerifying the Commutative Property of Matrix Addition:");
disp("A + B Calculation:");
AB = A + B;
disp(AB);
// Compute B + A
disp("B + A Calculation:");
BA = B + A;
disp(BA);
// Verify commutative property
disp("Final Verification: Are both matrices equal?");
if (AB == BA) then
disp("Yes, A + B is equal to B + A. The commutative property holds.");
else
disp("No, the matrices are not equal. The commutative property does not hold.");
end
35815003122|Harshita Sahrawat | [50]
15
OUTPUT :
35815003122|Harshita Sahrawat | [50]
16
Distributive Property :
CODE :
# // Define matrices A, B and scalar lambda
disp("The original matrices and scalar are:");
A = [7 9; 4 6];
B = [3 5; 2 10];
lambda = 5;
disp("Matrix A:");
disp(A);
disp("Matrix B:");
disp(B);
disp("Scalar lambda:");
disp(lambda);
// Compute lambda * (A + B)
disp("\nVerifying the Distributive Property of Scalar Multiplication over Matrix Addition:");
disp("lambda * (A + B) Calculation:");
AB = A + B;
lambda_AB = lambda * AB;
disp(lambda_AB);
// Compute (lambda * A) + (lambda * B)
disp("(lambda * A) + (lambda * B) Calculation:");
lambda_A = lambda * A;
lambda_B = lambda * B;
lambdaA_lambdaB = lambda_A + lambda_B;
disp(lambdaA_lambdaB);
// Verify distributive property
35815003122|Harshita Sahrawat | [50]
17
disp("Final Verification: Are both matrices equal?");
if (lambda_AB == lambdaA_lambdaB) then
disp("Yes, lambda * (A + B) is equal to (lambda * A) + (lambda * B).");
disp("The distributive property holds.");
else
disp("No, the matrices are not equal. The distributive property does not hold.");
end
OUTPUT :
35815003122|Harshita Sahrawat | [50]
18
PROGRAM : 5
AIM : WAP to perform exercises to find the reduced row echelon form of a matrix in Scilab.
CODE :
# // Function to compute the Reduced Row Echelon Form (RREF) manually
function R = manual_rref(A)
[m, n] = size(A);
row = 1;
for col = 1:n
// Find the pivot row (first nonzero entry in the column)
pivot_row = row;
while (pivot_row <= m & A(pivot_row, col) == 0)
pivot_row = pivot_row + 1;
end
if pivot_row > m then
continue;
end
// Swap rows if necessary
if pivot_row ~= row then
temp = A(row, :);
A(row, :) = A(pivot_row, :);
A(pivot_row, :) = temp;
end
// Normalize pivot row (make leading coefficient 1)
A(row, :) = A(row, :) / A(row, col);
// Make all entries in the current column (except pivot) zero
for i = 1:m
if i ~= row then
A(i, :) = A(i, :) - A(i, col) * A(row, :);
end
end
35815003122|Harshita Sahrawat | [50]
19
row = row + 1;
if row > m then
break;
end
end
R = A;
endfunction
// Define the input matrix
disp("The original matrix is:");
A = [2 4 -2 2; 4 9 -3 8; -2 -3 7 10];
disp(A);
// Compute RREF manually
disp("\nThe Reduced Row Echelon Form (RREF) is:");
R = manual_rref(A);
disp(R);
OUTPUT :
35815003122|Harshita Sahrawat | [50]
20
PROGRAM : 6
AIM : WAP to perform exercises for implementing plotting the functions and to find its first and
second derivatives in Scilab.
CODE :
# // Define the function f(x)
declare function y = f(x)
y = x^3 - 4*x^2 + 6*x - 2;
endfunction
// Define the first derivative f'(x) analytically
declare function y = df(x)
y = 3*x^2 - 8*x + 6;
endfunction
// Define the second derivative f''(x) analytically
declare function y = d2f(x)
y = 6*x - 8;
endfunction
// Define the x range
x = linspace(-2, 4, 100);
h = 0.01; // Step size for numerical differentiation
// Compute function values
y = f(x);
dy_analytical = df(x);
d2y_analytical = d2f(x);
// Compute numerical first derivative using finite differences
dy_numerical = (f(x + h) - f(x)) / h;
35815003122|Harshita Sahrawat | [50]
21
// Compute numerical second derivative using central differences
d2y_numerical = (f(x + h) - 2*f(x) + f(x - h)) / h^2;
// Plot the function and its derivatives
clf;
plot(x, y, 'b', 'LineWidth', 2);
hold on;
plot(x, dy_analytical, 'r', 'LineWidth', 2);
plot(x, d2y_analytical, 'g', 'LineWidth', 2);
plot(x, dy_numerical, 'm--', 'LineWidth', 1.5);
plot(x, d2y_numerical, 'c--', 'LineWidth', 1.5);
hold off;
// Add labels and legend
title("Function and its Derivatives (Analytical & Numerical)");
xlabel("x-axis");
ylabel("y-axis");
legend("f(x) = x^3 - 4x^2 + 6x - 2", "f'(x) Analytical", "f''(x) Analytical", "f'(x) Numerical", "f''(x) Numerical");
grid on;
35815003122|Harshita Sahrawat | [50]
22
OUTPUT :
35815003122|Harshita Sahrawat | [50]
23
PROGRAM : 7
AIM : WAP to perform exercises to present the data as a frequency table in SPSS.
INPUT DATABASE:
35815003122|Harshita Sahrawat | [50]
24
OUTPUT :
35815003122|Harshita Sahrawat | [50]
25
PROGRAM : 8
AIM : WAP to perform exercises to find the OUTLIERS in a dataset in SPSS.
INPUT DATABASE:
OUTPUT :
35815003122|Harshita Sahrawat | [50]
26
35815003122|Harshita Sahrawat | [50]
27
35815003122|Harshita Sahrawat | [50]
28
35815003122|Harshita Sahrawat | [50]
29
35815003122|Harshita Sahrawat | [50]
30
PROGRAM : 9
AIM : WAP to perform exercises Exercise to find the riskiest project out of two mutually exclusive
projects in SPSS.
INPUT DATABASE :
OUTPUT :
35815003122|Harshita Sahrawat | [50]
31
35815003122|Harshita Sahrawat | [50]
32
PROGRAM :
AIM : WAP to perform exercises for implementing .
Non preemptive:
CODE :
OUTPUT :
35815003122|Harshita Sahrawat | [50]