Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(Efficiency & Vectorization) For this problem, you will use the built-in commands tic and toc to time how long it takes code to run. Below
(Efficiency \& Vectorization) For this problem, you will use the built-in commands tic and toc to time how long it takes code to run. Below is the pseudocode that is showing you HOW to do this timing. tic ostarts the timer (The code that you are timing) timeElapsed = too sstops the timer Start by creating a matrix mat using the following code: mat=magic(5000); a. Use for loops to go through all the elements of the matrix mat and calculate the mean of the entire matrix. Store this number as averageMat. Use tic and toc and store the running time in time1. b. Repeat the same operation (finding the mean value of all elements of mat) but now use vectorized code (i.e without using any loops!), and again determine the time it took to run this code. Use tic and toc and store the running time in time2. c. Print both time1 (looped time) and time2 (vectorized time) to the Command Window. Determine how many times faster the vectorized code was, and print this to the Command Window as well. An example run is provided below. The time values will be different based on your
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started