WarmUp - c = an p , and plot it (all three cases in one...

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

View Full Document Right Arrow Icon
Warm-up Homework: Vectorization in Matlab Generate the vector y = sin ( x 2 ) for x [0 ] in three ways: a) sequential, using a ‘for–loop’, for example: h = pi/n ; for i = 0 : n, y ( i ) = sin (( i * h ) 2 ); end b) the same as in a) preceded by the initialization of y, i.e. setting y = zeros (1 ,n ); c) vectorized, using: x = linspace (0 ,pi,n - 1); y = sin ( x. * x ); (familiarize yourself with Matlab ’dot’ operations) Verify experimentally how the cost, c, of these operations depends on n, the size of the problem (suggestion: use ‘tic’ and ‘toc’ to measure the cpu). Derive the form of this dependence,
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: c = an p , and plot it (all three cases in one frame) using loglog scale. Compare the computed values of p and a with the theoretically predicted ones. Draw conclusions. Note: the values of n should be suciently large so that the measured cpu values are large enough to make sense (formula c = an p is an asymptotic one), and only sensibly large. You may want to increase n as a power of 2: n = 2 k with, say, k > 10 (and ignore measurements that are too small)....
View Full Document

Ask a homework question - tutors are online