Function [x] = function a(x) %This will take the squareroot of 2 times every val
ID: 3868130 • Letter: F
Question
Function [x] = function a(x) %This will take the squareroot of 2 times every value of x x = squareroot (2 * x): function [x] = function b(x) %This determines the row and column dimensions of x [rows, columns] = size (x): %This sums all of the values of each row of x, resulting in a %column array of sums y = zeros (rows, 1): for i = 1: rows for j = 1: columns y(i) = y(i) + x(i, j): end end x = y: function [x] = function_c(x) %This takes the transpose of x x = x': Using only a function header and calls to the three functions above, write a new function that takes one input, a matrix, and returns one output, a single number. That number should be the sum of the squareroot of every number in the original matrix multiplied by 2, as in sum( squareroot (number * 2)). For example, if your original matrix was: [2 2: 2 2] Your function would return the number 8.Explanation / Answer
Create a file myfunct.m and paste given code into it. Filename must be myfunct.m
function [out] = myfunct(x)
%multiply each element of x by 2
for i = 1:size(x,1)
for j = 1:size(x,2)
x(i,j) = 2*x(i,j);
end
end
%take square root of each element
for i = 1:size(x,1)
for j = 1:size(x,2)
x(i,j) = sqrt(x(i,j));
end
end
%sum all the elements of x
out = 0;
for i = 1:size(x,1)
for j = 1:size(x,2)
out = out + x(i,j);
end
end
end
Sample Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.