CHE 492 HW 2 Mohammed Alajmi

You might also like

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

CHE 492 HW 2

Mohammed Alajmi

EX 1

The following MATLAB algorithm was created to solve the proposed problem.

1) clear calculated data in previous run


2) clear text from the command window
3) create a 10x10 matrix with random numbers between 1 and 100 using the randi() function
4) calculate the sum of each of the rows using the sum() function
5) check if a row sums up to a number greater than 500
6) sum and return the number of rows that sum up to a number greater than 500 using the greater
than operator
7) display the value of rows that sum up to a number greater than 500

Appendix A below has several simulations with the corresponding code.

Ex 2

Let x be the fraction of occupied houses and y fraction of unoccupied houses.


• For N = 0, N = 1, y = 0 since no or only one house is occupied
• For N > 1:
▪ If N is even: x = 0.5, thus 𝑦 = 0.5
𝑁 𝑁 𝑁
▪ If N is odd: x = 2
+ 1, thus 𝑦 = 𝑁 − ( 2 + 1) = 2
−1
𝑤ℎ𝑒𝑟𝑒 𝑦 𝑖𝑠 𝑟𝑜𝑢𝑛𝑑𝑒𝑑 𝑑𝑜𝑤𝑛 𝑡𝑜 𝑡ℎ𝑒 𝑛𝑒𝑥𝑡 𝑖𝑛𝑡𝑒𝑔𝑒𝑟
• As N goes to infinity:
▪ If N is even: lim (0.5) = 0.5
𝑁→∞
𝑁
▪ If N is odd: lim ( 2 − 1) = ∞ − 1 = ∞
𝑁→∞
Appendix A

1) clear all
2) clc
3) Mat= randi([1,100],10,10);
4) S=sum(A,2);
5) Check=(S>500);
6) Nb=sum(Check);
7) display=sprintf('Number of rows whose sum is greater than 500 = %d
%d',Nb);

Table 1: Simulation 1

10x10 Matrix S Check


75 17 23 94 30 40 75 97 62 16 529 true
90 84 94 77 41 60 76 9 27 24 582 true
25 17 69 83 87 81 39 51 45 71 568 true
13 51 97 58 62 11 43 53 85 38 511 true
23 100 44 80 100 83 96 10 20 98 654 true
36 36 95 33 21 85 58 91 31 98 584 true
29 5 1 23 83 36 85 89 49 65 465 false
93 22 62 32 68 44 28 44 34 87 514 true
6 40 81 59 25 58 63 79 80 41 532 true
60 34 24 83 48 71 59 15 99 64 557 true

Number of rows whose sum is greater than 500 = 9

Table 2: Simulation 2

10x10 Matrix S Check


99 41 75 90 89 33 11 96 76 88 698 true
56 66 67 34 45 64 46 80 37 2 497 false
94 91 53 23 76 24 46 46 95 30 578 true
73 100 26 12 61 58 56 34 2 18 440 false
49 66 97 32 79 61 81 6 83 93 647 true
64 11 55 23 12 60 71 75 63 7 441 false
89 4 4 66 98 45 88 51 54 59 558 true
20 62 70 7 85 4 6 20 66 64 404 false
40 57 52 28 6 52 22 43 73 66 439 false
100 97 6 29 47 41 46 17 10 87 480 false

Number of rows whose sum is greater than 500 = 4


Table 3: Simulation 3

10x10 Matrix S Check


6 6 78 83 28 15 29 34 34 12 325 false
82 63 92 83 68 59 98 90 85 80 800 true
53 80 79 58 91 8 4 50 25 62 510 true
70 70 30 58 91 83 33 62 59 8 564 true
22 35 16 29 75 73 98 59 94 7 508 true
55 95 85 70 27 93 37 70 5 14 551 true
71 53 79 80 69 50 31 3 6 79 521 true
96 96 28 45 14 66 13 53 3 10 424 false
45 8 23 45 13 90 92 4 69 24 413 false
9 21 33 47 20 54 14 83 60 25 366 false

Number of rows whose sum is greater than 500 = 6

You might also like