Give the following commands to create a matrix called F: randn(\'seed\', 1234567
ID: 3807873 • Letter: G
Question
Give the following commands to create a matrix called F: randn('seed', 123456789) F = randn(5,10); I. Compute the minimum and maximum value of each column and assign the results to the elements of a vector called min_value and max_value respectively. II. Compute the mean of each column and assign the results to the elements of a vector called avg. III. Compute the standard deviation of each column and assign the results to the elements of a vector called s. s = Squareroot sigma(X -M)^2/n - 1 with X the current element, M the mean and in the number of elements In each case, you can check your results with the built-in functions.Explanation / Answer
Matlab code
randn('seed',123456789)
F = randn(5,10); % Creating a matrix of size 5 by 10
% part I
min_value = F(1,:); % Considering the min value in the first column
max_value = F(1,:);% Considering the max value in the first column
for k = 2:5 % Checking min and max for other colums
I = min_value > F(k,:); % Getting the index of F which is less than min_value
min_value(I) = F(k,I); % Update the value of min_value in I
I = max_value < F(k,:);% Getting the index of F which is greater than min_value
max_value(I) = F(k,I);% Update the value of max_value in I
end
% printing the results
fprintf('Using the code Min Values ');
disp(min_value);
fprintf('Max Values ');
disp(max_value);
fprintf('Using the Matlab function Min Values ');
disp(min(F));
fprintf('Max Values ');
disp(max(F));
% Part II
avg = F(1,:); % Considering first column
for k = 2:5 % Considering remaining columns
avg = avg+ F(k,:); % Finding the sum
end
avg = avg./5; % Finding the average
% printing the results
fprintf('Using the code Avg Values ');
disp(avg);
fprintf('Using the Matlab function Avg Values ');
disp(mean(F));
% part III
s = zeros(1,10); % Creating a vector of zeros
for k = 1:5 % Considering the columns
s = s+(F(k,:)-avg).^2; % Findig the Standard deviation
end
s = sqrt(s./(5-1));% Findig the Standard deviation
% printing the results
fprintf('Using the code Standard deviation Values ');
disp(s);
fprintf('Using the Matlab function Standard deviation Values ');
disp(std(F));
OUTPUT
Using the code
Min Values
0.0510 -0.9210 -0.6272 -0.9295 -1.3563 -0.9169 -1.9619 -1.8673 -0.4175 -0.8902
Max Values
3.0189 1.0971 0.1955 0.3871 0.6580 1.3061 0.7686 0.7241 0.9587 1.2964
Using the Matlab function
Min Values
0.0510 -0.9210 -0.6272 -0.9295 -1.3563 -0.9169 -1.9619 -1.8673 -0.4175 -0.8902
Max Values
3.0189 1.0971 0.1955 0.3871 0.6580 1.3061 0.7686 0.7241 0.9587 1.2964
Using the code
Avg Values
1.0265 -0.0674 -0.2153 -0.1415 -0.3151 0.3403 -0.6386 -0.3431 0.1726 0.3760
Using the Matlab function
Avg Values
1.0265 -0.0674 -0.2153 -0.1415 -0.3151 0.3403 -0.6386 -0.3431 0.1726 0.3760
Using the code
Standard deviation Values
1.2131 0.7533 0.3313 0.5499 0.7748 0.9208 1.1053 1.0867 0.6738 0.9204
Using the Matlab function
Standard deviation Values
1.2131 0.7533 0.3313 0.5499 0.7748 0.9208 1.1053 1.0867 0.6738 0.9204
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.