The test suite generates a random M times N matrix with a random number of rows
ID: 3786740 • Letter: T
Question
The test suite generates a random M times N matrix with a random number of rows columns that is assigned to the variable A. and The element values of the matrix are random double precision numbers that fall in the range from -10 to 10. The matrix has between 5 and 10 rows and between 5 and 10 columns. Assuming A is defined in the workspace, write a script with commands to perform the operations described below and assign the results to the indicated variable names. Add a row to the bottom of A that consists of the mean of each column of A and assign the resulting matrix to B. Still starting with the original matrix A add to the bottom of A that consists of the sum of each column of A and assign a row the resulting matrix to C. Next add a column to C that consists of the sum of each row of C and assign the resulting matrix to D. Solution % Enter the commands for your script in file here. Be sure to assign the matrices specified in the A (n+1, : b = mean (A) B = b (end) C = A D = A;Explanation / Answer
Matlab Script file
M = round(6*rand(1)+4); % generating random number between 5 and 10
N = round(6*rand(1)+4); % generating random number between 5 and 10
A = 20*rand(M,N)-10; % generating random matrix of size MxN with elements -10 to 10
B = [A; mean(A)]; % The matrix with mean of columns in the additional row
C = [A; sum(A)]; % The matrix with sum of columns in the additional row
D = [C, sum(C')']; % The matrix with sum of rows in the additional column
fprintf('A = ');disp(A); % Displaying A
fprintf('B = ');disp(B);% Displaying B
fprintf('C = ');disp(C);% Displaying C
fprintf('D = ');disp(D);% Displaying D
OUTPUT
>> MatrixOperation
A =
-2.4278 -5.8452 -1.2860 -4.8387 -3.6244 -0.2278 2.4812 -8.0258
6.2316 -3.9751 -3.7780 -1.8256 -1.5167 1.5705 3.5827 -4.7626
0.6565 -0.5815 8.4676 1.8979 0.1572 -5.2543 -2.0897 -3.2929
-2.9855 -5.3902 -1.3959 -4.7558 -8.2897 -0.8230 -2.6513 3.5946
8.7800 6.8862 -6.3037 2.0569 -4.7504 9.2618 9.7596 -7.2689
7.5189 -6.1047 8.0976 4.2243 6.0203 0.9361 -9.2452 4.4245
1.0031 -5.4816 9.5950 -5.5651 -9.4156 0.4227 7.7034 -7.8648
2.4495 -6.5858 -1.2226 -7.6516 8.5771 -5.3681 8.2657 3.0751
1.7409 -5.4467 -7.7776 -4.0665 4.6066 -0.2220 5.9237 -0.1165
B =
-2.4278 -5.8452 -1.2860 -4.8387 -3.6244 -0.2278 2.4812 -8.0258
6.2316 -3.9751 -3.7780 -1.8256 -1.5167 1.5705 3.5827 -4.7626
0.6565 -0.5815 8.4676 1.8979 0.1572 -5.2543 -2.0897 -3.2929
-2.9855 -5.3902 -1.3959 -4.7558 -8.2897 -0.8230 -2.6513 3.5946
8.7800 6.8862 -6.3037 2.0569 -4.7504 9.2618 9.7596 -7.2689
7.5189 -6.1047 8.0976 4.2243 6.0203 0.9361 -9.2452 4.4245
1.0031 -5.4816 9.5950 -5.5651 -9.4156 0.4227 7.7034 -7.8648
2.4495 -6.5858 -1.2226 -7.6516 8.5771 -5.3681 8.2657 3.0751
1.7409 -5.4467 -7.7776 -4.0665 4.6066 -0.2220 5.9237 -0.1165
2.5519 -3.6139 0.4885 -2.2805 -0.9151 0.0329 2.6367 -2.2486
C =
-2.4278 -5.8452 -1.2860 -4.8387 -3.6244 -0.2278 2.4812 -8.0258
6.2316 -3.9751 -3.7780 -1.8256 -1.5167 1.5705 3.5827 -4.7626
0.6565 -0.5815 8.4676 1.8979 0.1572 -5.2543 -2.0897 -3.2929
-2.9855 -5.3902 -1.3959 -4.7558 -8.2897 -0.8230 -2.6513 3.5946
8.7800 6.8862 -6.3037 2.0569 -4.7504 9.2618 9.7596 -7.2689
7.5189 -6.1047 8.0976 4.2243 6.0203 0.9361 -9.2452 4.4245
1.0031 -5.4816 9.5950 -5.5651 -9.4156 0.4227 7.7034 -7.8648
2.4495 -6.5858 -1.2226 -7.6516 8.5771 -5.3681 8.2657 3.0751
1.7409 -5.4467 -7.7776 -4.0665 4.6066 -0.2220 5.9237 -0.1165
22.9673 -32.5247 4.3965 -20.5242 -8.2356 0.2958 23.7301 -20.2372
D =
-2.4278 -5.8452 -1.2860 -4.8387 -3.6244 -0.2278 2.4812 -8.0258 -23.7945
6.2316 -3.9751 -3.7780 -1.8256 -1.5167 1.5705 3.5827 -4.7626 -4.4731
0.6565 -0.5815 8.4676 1.8979 0.1572 -5.2543 -2.0897 -3.2929 -0.0392
-2.9855 -5.3902 -1.3959 -4.7558 -8.2897 -0.8230 -2.6513 3.5946 -22.6967
8.7800 6.8862 -6.3037 2.0569 -4.7504 9.2618 9.7596 -7.2689 18.4215
7.5189 -6.1047 8.0976 4.2243 6.0203 0.9361 -9.2452 4.4245 15.8718
1.0031 -5.4816 9.5950 -5.5651 -9.4156 0.4227 7.7034 -7.8648 -9.6028
2.4495 -6.5858 -1.2226 -7.6516 8.5771 -5.3681 8.2657 3.0751 1.5393
1.7409 -5.4467 -7.7776 -4.0665 4.6066 -0.2220 5.9237 -0.1165 -5.3582
22.9673 -32.5247 4.3965 -20.5242 -8.2356 0.2958 23.7301 -20.2372 -30.1319
>>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.