Determine a matrix size that you can comfortably fit into your available RAM. For example, if you have a 4 GB machine, you should be able to comfortably store a matrix that occupies about 800MB. Store this value in a variable
Mb
. Use the following information to compute a maximum matrix dimension N that you can store in Mb megabytes of memory.
A megabyte has
1024
kilobytesA kilobyte is
1024
bytesA floating point number is
8 bytes
.An
N × N
matrix containsN^2
floating point numbers.Call the N you compute
nmax
.(b) Create two random matrices
A
andB
each of sizeNmax × Nmax
. Using the MATLAB functionstic
andtoc
, determine how much time (seconds) it takes to compute the productAB
. Determine the number of floating point operations (additions and multiplications) it takes to compute theNmax × Nmax
matrix-matrix product(2/3)n^3.
Use this number to estimate the number of floating point operations per second (’flops’) your computer can carry out. Call this flop rateflops
.
% Part A
nmax = sqrt((1600*1024*1024)/8); % 8GB of RAM
% Part B
A = (nmax:nmax);
B = (nmax:nmax);
tic
prod = A*B;
prod_time = toc
flops = (2/3)*(prod).^3
Everything runs fine but I feel like I am not creating a matrix for the values A
and B
. What am I doing wrong?