# problem2 - c %In this case the same x matrix has been...

This preview shows page 1. Sign up to view the full content.

x=rand(4000,3000); y=zeros(size(x)); tic; t for i=1:4000 for j=1:3000 y(i,j)=sin(x(i,j)); end end toc t % In this problem x is a 4000x3000 matrix of random numbers from 0 to 1. y %is a matrix of equal dimensions of zeros. the for loop goes to the ith row %and jth column of x and evaluates the sin of this point and places it in %the matrix y in the same location of the row and column. The estimated %time is about 3.3 seconds. % tic; y=sin(x); toc clear x y;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: c %In this case the same x matrix has been created as is the case with y. The %entire matrix x is placed inside the sin function, so MATLAB will %calculate the sin of every element of x, and now assign it into the matrix %y. This method is much more direct as MATLAB doesn't have to look for the %row and the column of x, it just evaluates the sin everywhere. This %process takes approximately 0.9 seconds....
View Full Document

## This note was uploaded on 02/18/2010 for the course ENGINEERIN 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

Ask a homework question - tutors are online