Computational Lab
Computational Lab
Computational Lab
Solution:
*INPUT*
% Input for Matrix A
rows_A = input('Enter the number of rows for Matrix A: ');
cols_A = input('Enter the number of columns for Matrix A: ');
A = zeros(rows_A, cols_A);
for i = 1:rows_A
for j = 1:cols_A
A(i, j) = input(sprintf('Enter element at position (%d, %d) for Matrix A: ', i,
j));
end
end
for i = 1:rows_B
for j = 1:cols_B
B(i, j) = input(sprintf('Enter element at position (%d, %d) for Matrix B: ', i,
j));
end
end
% Perform operations
C = A + B;
D = A - B;
E = A * B;
F = B * A;
trace_A = trace(A);
transpose_B = B';
scalar_factor = input('Enter the scalar factor: ');
% Calculate results
Z = scalar_factor * B;
Y = B * Z;
rank_B = rank(B);
eigenvalues_A = eig(A);
inverse_B = inv(B);
% Display results
disp('Addition of Matrix A and B:');
disp(C);
disp('Subtraction of Matrix A and B:');
disp(D);
disp('Product A * B:');
disp(E);
disp('Product B * A:');
disp(F);
disp('Trace of Matrix A:');
disp(trace_A);
disp('Transpose of Matrix B:');
disp(transpose_B);
disp('Scaled Matrix B:');
disp(Z);
disp('Result of B * scaled B:');
disp(Y);
disp('Rank of Matrix B:');
disp(rank_B);
disp('Eigenvalues of Matrix A:');
disp(eigenvalues_A);
disp('Inverse of Matrix B:');
disp(inverse_B);
*OUTPUT*
Solution:
*INPUT*
% Initializing variables
total_sum = 0;
% Division operation
numerator = input('Enter the numerator: ');
denominator = input('Enter the denominator: ');
if denominator == 0
disp('Division by zero is undefined.');
else
result = numerator / denominator;
remainder = mod(numerator, denominator);
% Cubic operation
x_value = input('Enter the value for x: ');
y_value = input('Enter the value for y: ');
cubic_result = (x_value - y_value)^3;
disp(['(6) The result of (' num2str(x_value) ' - ' num2str(y_value)
')^3 is: ' num2str(cubic_result)]);
% Selection operation
L = 3.1;
m = -1.5;
n = pi / 2;
x_val = 2 / pi;
y_val = 3^(1/2);
% Summation condition
total_sum = 0;
for i = 1:100
if mod(i,5)==0 && mod(i,8)~=0
total_sum = total_sum + i;
end
end
fprintf('(9) The summation is: %d\n', total_sum);
% Cubic summation
n_value = input('Enter the value of n: ');
total_sum = 0;
for i = 1:n_value
cube_val = i^3;
total_sum = total_sum + cube_val;
end
fprintf('(10) The summation is: %d\n', total_sum);
*OUTPUT*
Solution:
*INPUT*
*OUTPUT*