40 likes | 144 Views
COMP 116: Introduction to Scientific Programming . Lecture 18: Nested loops and review. Quiz 4 function. Nested loops: what does this code do?. % Assume A and B are pre-assigned % matrices and of the same size C=zeros(size(A)); for i =1:size(A,1) for j=1:size(A,2)
E N D
COMP 116: Introduction to Scientific Programming Lecture 18: Nested loops and review
Nested loops: what does this code do? % Assume A and B are pre-assigned % matrices and of the same size C=zeros(size(A)); for i=1:size(A,1) for j=1:size(A,2) C(i,j)=A(i,j)*B(i,j) end end
Exercise • Write a function that • given two matrices • returns their product (matrix multiplication not element-wise multiplication) • Use nested for loops • For the first version of the code you can assume that the input matrices are the right size • For the final version, make no such assumption