Question

In: Computer Science

MATLAB Given a 20x20 matrix named G and a 20x1 vector named H, multiply the elements...

MATLAB

Given a 20x20 matrix named G and a 20x1 vector named H, multiply the elements in the 14th column of G by the values in H (element-by-element multiplication, not a multiplication table).

Solutions

Expert Solution

CODE

function result = doIt(G, H)
    for i = 1:20
        G(i, 14) *= H(1,14); 
    end
    result = G;
end

G = randi([1 9], [20 20])
H = randi([1 9], [1 20])
result = doIt(G, H)

OUTPUT

G =

   1   9   6   5   7   3   6   1   3   9   3   9   2   3   6   8   3   5   2   6
   7   1   8   4   8   3   3   5   8   3   1   6   3   6   7   1   5   4   7   9
   9   8   4   8   4   2   2   2   4   2   3   2   2   7   8   7   5   6   8   6
   1   1   2   6   1   3   1   2   5   9   3   9   2   6   1   6   6   8   5   5
   7   4   5   7   9   1   3   1   7   5   7   5   5   8   3   8   5   2   7   3
   8   7   8   7   3   8   3   6   1   6   9   1   2   3   8   2   2   8   3   4
   5   5   5   7   7   6   4   2   3   6   8   6   7   5   7   9   9   8   2   9
   1   9   1   8   1   2   3   3   3   6   1   3   6   5   1   4   1   5   2   5
   1   5   6   1   8   7   8   4   4   6   2   5   6   8   4   6   7   4   7   3
   7   3   4   4   2   2   4   2   4   3   7   5   5   3   8   7   2   1   1   2
   5   1   8   8   8   3   5   5   8   1   8   9   8   7   3   3   3   8   6   3
   1   9   5   9   3   6   6   8   9   1   2   3   9   1   8   5   9   4   7   9
   3   5   9   5   9   2   4   3   6   3   2   8   2   5   6   3   6   8   2   5
   9   1   4   7   2   4   9   9   9   7   4   7   5   6   1   2   3   6   5   7
   7   2   2   7   8   4   3   8   5   6   6   5   9   5   3   4   5   1   3   6
   9   2   2   1   4   9   1   1   6   1   9   5   7   6   6   9   6   8   7   3
   8   1   5   1   1   7   5   3   5   6   7   9   4   2   2   3   1   6   3   3
   6   8   8   8   5   4   1   6   6   8   9   7   7   1   8   4   9   8   7   3
   9   3   5   1   2   2   9   6   9   5   1   6   6   4   9   4   6   6   1   9
   9   1   6   5   4   1   7   6   5   1   4   5   6   1   7   6   4   6   8   8

H =

   8   2   7   4   6   1   3   2   6   3   2   7   5   4   3   4   9   7   5   1

result =

 Columns 1 through 16:

    1    9    6    5    7    3    6    1    3    9    3    9    2   12    6    8
    7    1    8    4    8    3    3    5    8    3    1    6    3   24    7    1
    9    8    4    8    4    2    2    2    4    2    3    2    2   28    8    7
    1    1    2    6    1    3    1    2    5    9    3    9    2   24    1    6
    7    4    5    7    9    1    3    1    7    5    7    5    5   32    3    8
    8    7    8    7    3    8    3    6    1    6    9    1    2   12    8    2
    5    5    5    7    7    6    4    2    3    6    8    6    7   20    7    9
    1    9    1    8    1    2    3    3    3    6    1    3    6   20    1    4
    1    5    6    1    8    7    8    4    4    6    2    5    6   32    4    6
    7    3    4    4    2    2    4    2    4    3    7    5    5   12    8    7
    5    1    8    8    8    3    5    5    8    1    8    9    8   28    3    3
    1    9    5    9    3    6    6    8    9    1    2    3    9    4    8    5
    3    5    9    5    9    2    4    3    6    3    2    8    2   20    6    3
    9    1    4    7    2    4    9    9    9    7    4    7    5   24    1    2
    7    2    2    7    8    4    3    8    5    6    6    5    9   20    3    4
    9    2    2    1    4    9    1    1    6    1    9    5    7   24    6    9
    8    1    5    1    1    7    5    3    5    6    7    9    4    8    2    3
    6    8    8    8    5    4    1    6    6    8    9    7    7    4    8    4
    9    3    5    1    2    2    9    6    9    5    1    6    6   16    9    4
    9    1    6    5    4    1    7    6    5    1    4    5    6    4    7    6

 Columns 17 through 20:

    3    5    2    6
    5    4    7    9
    5    6    8    6
    6    8    5    5
    5    2    7    3
    2    8    3    4
    9    8    2    9
    1    5    2    5
    7    4    7    3
    2    1    1    2
    3    8    6    3
    9    4    7    9
    6    8    2    5
    3    6    5    7
    5    1    3    6
    6    8    7    3
    1    6    3    3
    9    8    7    3
    6    6    1    9
    4    6    8    8

Related Solutions

the question should be done on Matlab. There is a vector defined as H = [-88,...
the question should be done on Matlab. There is a vector defined as H = [-88, 45, 75, 24, 14, 19, -11, 9, -5, -3, 12, 19 ,56, -4, 5, 17, -6, -8, -9, 6, 15] Write a program as a script file that triples the elements that are positive and a divisible by 3 or 5, and, raises to the power of 2 the elements that are negative but greater than -11.
hat are the values of the elements in the vector named names_1 after the following code...
hat are the values of the elements in the vector named names_1 after the following code is executed? vector<string> names_1 { "Mike", "Ben", "Joel", "Anne" }; vector<string> names_2 { "Judy", "Samantha", "Kelly" }; names_1.insert(names_1.end(), "Mary"); names_1.erase(names_1.begin());         names_1.insert(names_1.begin() + 2, ++names_2.begin(), names_2.end()); names_1.swap(names_2); names_1.erase(++names_1.begin()); names_1.insert(names_1.begin(), ++names_2.begin(), names_2.begin() + 2); a. Joel, Judy, Samantha b. Judy, Mary, Joel, Mary c. Joel, Anne, Judy, Samantha d. Joel, Judy, Kelly 1.5 points    QUESTION 12 What are the values of the key/value pairs in...
Write a Matlab script that computes the element level stiffness matrix and force vector for linear...
Write a Matlab script that computes the element level stiffness matrix and force vector for linear elasticity.
I have a 3-D matrix with (100,100,100) elements in Matlab, but it exceeds the limit of...
I have a 3-D matrix with (100,100,100) elements in Matlab, but it exceeds the limit of display. I want to extract those values from Matlab to excel. I want to know how to extract all the data values?
USING MATLAB In signal processing applications, the Hankel matrix is useful. The elements of a (N...
USING MATLAB In signal processing applications, the Hankel matrix is useful. The elements of a (N × N) Hankel matrix are given by h?? =0   ?+?−1>? =?+?−1 otherwise Write a script that takes as input from the user an integer, n. Your code should accept input ≥1 and <10. The user should be repeatedly prompted until acceptable input is entered. Next, create n Hankel matrices for N=1,2,...,n. That is, if the user enters 4, you’ll generate 1×1, 2×2, 3×3, and...
Direct product of groups: Let (G, ∗G) and (H, ∗H) be groups, with identity elements eG...
Direct product of groups: Let (G, ∗G) and (H, ∗H) be groups, with identity elements eG and eH, respectively. Let g be any element of G, and h any element of H. (a) Show that the set G × H has a natural group structure under the operation (∗G, ∗H). What is the identity element of G × H with this structure? What is the inverse of the element (g, h) ∈ G × H? (b) Show that the map...
Assume the vector AM contains an even number of elements. Develop a MATLAB script that asks...
Assume the vector AM contains an even number of elements. Develop a MATLAB script that asks the user for the vector AM and once the vector is found to contain an even number of elements, divide the product of its even elements by the sum of its odd elements without using the MATLAB functions prod or sum. Store the result in a variable called PDS. If AM is found to contain an odd number of elements, display an error message...
MATLAB Create a matrix named P which has 2000 rows and 100 columns of all zeros....
MATLAB Create a matrix named P which has 2000 rows and 100 columns of all zeros. Replace the zeros in rows 46-58 and columns 3-18 of matrix P from the previous question with ones.
Calculate delta H for the reaction H(g) + Br(g) = HBr(g), given the following information: H2(g)...
Calculate delta H for the reaction H(g) + Br(g) = HBr(g), given the following information: H2(g) + Br2(g) = 2HBr(g) delta H = -72 kJ H2(g) = 2H(g) delta H = +436 kJ Br2(g)= 2Br(g) delta H = +224 kJ
Fix a group G. We say that elements g1, g2∈G are conjugate if there exists h∈G...
Fix a group G. We say that elements g1, g2∈G are conjugate if there exists h∈G such that hg1h−1 = g2. Prove that conjugacy is an equivalence relation. Prove that if g∈Z(G), the center of G, then its conjugacy classes has cardinality one. Let G = Sn. Prove that h(i1i2 ... it)h−1  = (h(i1) h(i2) ... h(it)), where ij∈{1, 2, ... , n }. Prove that the partition of S3 into conjugacy classes is {{e} , {(1 2), (2 3), (1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT