Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CHE 492 HW 2

Abdulaziz Alhouti
Problem 1

Using the following algorithm in MATLAB:

Line 1: clear previous data in the previous MATLAB run


Line 2: generate a 10x10 matrix of random numbers between 1 and 100 using the randi () function
Line 3: generate a matrix for the sum of each of the row components
Line 4: Sum is a matrix that returns 1 if the sum is greater than 500 and 0 if the sum is less than 500 using
the operator (greater than: >)
Line 5: prints a message with the number of rows whose sum is greater than 500

The MATLAB code as well as the test runs performed and the corresponding results obtained are
summarized in Appendix 1, Section 1 below.

Problem 2

N: number of houses
O: number of occupied houses
U: number of unoccupied houses
OF: fraction of occupied houses
UF: fraction of occupied houses

Knowing that 2 houses can’t be occupied simultaneously and all acceptable houses must be filled the
following configurations can be obtained:

For N = 0, O = 0 and U = 0
For N = 1, O = 1 and U = 0
For N = 2, O = 1 and U = 1
For N = 3, O = 2 and U = 1
For N = 4, O = 2 and U = 2
For N = 5, O = 3 and U = 2

We can also see a binomial distribution where only U or O can be the status of a house such as a (U O U)
or (U O O U) configuration and many other combinations. This binomial function converges to Poisson
distribution as N goes to infinity.
For N > 1:
• If N is even:
1 1
𝑂𝐹 = 2
𝑤ℎ𝑒𝑟𝑒 ℎ𝑎𝑙𝑓 𝑜𝑓 𝑡ℎ𝑒 ℎ𝑜𝑢𝑠𝑒𝑠 𝑎𝑟𝑒 𝑜𝑐𝑐𝑢𝑝𝑖𝑒𝑑 𝑡ℎ𝑒𝑟𝑒𝑓𝑜𝑟𝑒 𝑈𝐹 = 1 − 𝑂𝐹 = 2
𝑁
• If N is odd: OF = 2
+ 1 𝑎𝑠 𝑐𝑎𝑛 𝑏𝑒 𝑠𝑒𝑒𝑛 𝑓𝑟𝑜𝑚 𝑡ℎ𝑒 𝑠𝑒𝑟𝑖𝑒𝑠 𝑑𝑖𝑠𝑝𝑙𝑎𝑦𝑒𝑑 𝑎𝑏𝑜𝑣𝑒
𝑁 𝑁
therefore 𝑈𝐹 = 𝑁 − ( 2 + 1) = 2
−1
𝑤ℎ𝑒𝑟𝑒 𝑂𝐹 𝑎𝑛𝑑 𝑈𝐹 𝑟𝑜𝑢𝑛𝑑𝑒𝑑 𝑑𝑜𝑤𝑛 𝑡𝑜 𝑐𝑙𝑜𝑠𝑒𝑠𝑡 𝑖𝑛𝑡𝑒𝑔𝑒𝑟
As N goes to infinity:
• If N is even: lim (𝑈𝐹) = 0.5
𝑁→∞
𝑁
• If N is odd: lim ( 2 − 1) = ∞
𝑁→∞
Appendix A

1. clear, clc
2. A= randi([1,100],10,10,’double’);
3. S=sum(A,2);
4. Sum=(S>500);
5. Rows=sum(Sum);
6. message= print(‘Nb of rows whose sum is greater than 500 = %d %d’,Rows);

Section 1

Run 1

Figure 1: Matrix A1

Figure 2: Matrix Sum1


Figure 3: Matrix S1

Nb of rows whose sum is greater than 500 = 6

Run 2

Figure 4: Matrix A2

Figure 5: Matrix S2
Figure 6: Matrix Sum2

Nb of rows whose sum is greater than 500 = 6

Run nb. 3

Figure 7: Matrix A3
Figure 8: Matrix S3

Figure 9: Matrix Sum3

Nb of rows whose sum is greater than 500 = 5

You might also like