1 / 4

Understanding Nested Loops in Scientific Programming: Matrix Multiplication Exercise

In this lecture, we explore the concept of nested loops through the lens of matrix multiplication in scientific programming. We provide a code snippet that demonstrates how to multiply two matrices element-wise using nested loops. The exercise challenges students to write a function that computes the product of two matrices (not element-wise) using nested loops. Initially, we can assume the matrices are the correct size, but ultimately, the function should handle any matrix sizes, ensuring robustness. Join us as we deepen our understanding of nested loops and their applications in matrix operations.

thane
Télécharger la présentation

Understanding Nested Loops in Scientific Programming: Matrix Multiplication Exercise

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMP 116: Introduction to Scientific Programming Lecture 18: Nested loops and review

  2. Quiz 4 function

  3. 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

  4. 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

More Related