User Tools

Site Tools


gibson:teaching:fall-2013:math445:hw2

**This is an old revision of the document!** ----

A PCRE internal error occured. This might be caused by a faulty plugin

====== Math 445 HW2 ====== **Problem 1.** Write a Matlab function ''mysort'' that takes an input vector ''x'', rearranges its components so they are in increasing order, and then returns the sorted vector. For example, ''mysort([0.38 0.57 0.22])'' should return ''[0.22 0.48 0.57]''. Your ''mysort'' function should use the "bubble sort" algorithm and just basic comparisons and control-flow operations. That is, no cheating by using Matlab's ''sort'' function! **Problem 2.** Test ''mysort'' on a random vector of length 4. That is, set ''x = rand(4,1)'' and then ''y = mysort(x)''. Verify by eye that ''x'' and ''y'' have the same set of elements and that ''y'' is sorted correctly. If there are any problems, go back and fix your ''mysort'' function. **Problem 3.** Run ''mysort'' on a random vector of length 1000. Checking this by eye would take too long and would not be reliable. Come up with a simple way to test the correctness of the sort with Matlab code.

gibson/teaching/fall-2013/math445/hw2.1379380518.txt.gz · Last modified: 2013/09/16 18:15 by gibson