User Tools

Site Tools


gibson:teaching:fall-2013:math445:hw2

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
gibson:teaching:fall-2013:math445:hw2 [2013/09/17 05:33]
gibson
gibson:teaching:fall-2013:math445:hw2 [2013/09/17 05:35] (current)
gibson
Line 1: Line 1:
 ====== Math 445 HW2: Bubble sort ====== ====== Math 445 HW2: Bubble sort ======
  
-**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 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.38 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 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.
gibson/teaching/fall-2013/math445/hw2.1379421238.txt.gz · Last modified: 2013/09/17 05:33 by gibson