# Vectorization generate the n vector sin at

• Assignment
• 1
• 100% (1) 1 out of 1 people found this document helpful

This preview shows page 1 out of 1 page.

3.Vectorization Generate the n-vector ࠵? =sin(࠵?()at equidistant points in the interval [0, ࠵?]in three ways: a) sequential, using a ‘for–loop’. b) the same as in a) preceded by the initialization of ࠵?, i.e. setting ࠵? = ࠵?࠵?࠵?࠵?࠵?(1, ࠵?)for appropriate c) vectorized, using the commands (familiarize yourself with Matlab ’dot’ operations): ࠵? = ࠵?࠵?࠵?࠵?࠵?࠵?࠵?࠵?(0, ࠵?, ࠵?); ࠵? = sin(࠵?.∗ ࠵?); Verify experimentally using Matlab how the cost, ࠵?, of these operations depends on ࠵?, the size of the problem (suggestion: use ‘tic’ and ‘toc’ to measure the cpu time). Plot the cost ࠵?vs ࠵?for the three methods on the same plot. Label the axes, title the plot, and identify each set of data points using different lines for each plot. What are your observations from the results of this experiment? 4.Single vs Double precision Evaluate ࠵?(࠵?) = ࠵?BC(sin(2࠵?࠵?) + 5)at 401 equidistant points between 0 and 1, using the usual double precision of MATLAB as well as the single precision and plot the relative differences vs t. Note. We’ll talk more about round off errors which is related to this problem very soon. Hint: by default MATLAB uses double precision. Use the command single to obtain single precision. Obtain the relative differences using ࠵?࠵?࠵?GHII=(GCBJC)GC,where ࠵?࠵? ࠵?tand for double and ࠵?࠵? for single precision.5.Open MATLAB and in the help icon explore documentation and examples. Get a brief look at some of the commands and examples of numerical applications. Note: there is an extensive set of examples and resources available at the Mathworks website. Take a look at some of them and discover the enormous applications of numerical algorithms in the industry and academia. k
• • • 