You are on page 1of 3

I. CASE NO.

5: “LOOPS”
It is known that the non-growth rate of yeast(k) has the following relationship
with the food concentration(x).

k = 𝑎𝑥 /(𝑏 + 𝑐𝑥 + 𝑑𝑥^2 + 𝑒𝑥^3)

According to this equation, due to the limitation of food volume, growth


approaches zero at very low concentrations. It also approaches zero at high
concentrations due to the effects of toxic effects.

OBJECTIVE/S

 Identify the largest element of the array and places it first, then the second
largest, and places it second, and so on until the smallest element is placed last
in the array.
 Came up with right code without using auxiliary array and min, max, sort, or any
other MATLAB command.

RESULTS AND DISCUSSION


Using MatLab, suppose that there are N elements to sort. Organize a loop which
goes from 1 to N − 1. Naturally, the loop does not have to go to N because, once N − 1
values are sorted, so is the last one.

In each pass through the loop, one value will be placed in its destination. The first
pass will identify the largest element and place it at the top of the array. The second
largest element will be identified in pass 2, and will replace the second element of A.
Thus, at iteration i, we will be positioning an element at i in A.

To identify the largest element, set a variable to the smallest value MATLAB can
handle, -Inf. Search through the unsorted part of the array by comparing the current
maximum with the array entry. If array entry is larger, store the value as the new
maximum, and the index where this maximum value is found.

Table 05.1
Complete Code and Result of Case No.5
In this case or problem, you can see how easy it is to swap two elements in an
array in MATLAB: A ([i index_max]) = A ([index_max i] );. If another language was used,
we first need to save the content of one of the cells in a temporary variable, for
example, temp = A(i); Then the i th entry can be replaced as A(i) = A (index_max);.
Finally, the saved value should be placed in the array as A(index_max) = temp;.

You might also like