Professional Documents
Culture Documents
Assignment 01 Full Solution by Sabbir Hossen (AE-017)
Assignment 01 Full Solution by Sabbir Hossen (AE-017)
Assignment 01 Full Solution by Sabbir Hossen (AE-017)
Submitted To :
Dr. S.M. Chapal Hossain (CH)
Md. Shorif Hossan (MSH)
(*Answer to the Question No : 1*)
10
O u t [ ] =
19
{1, 2, 5, 10}
I n [ ] : = {1, 2, 6, 24, 120, 720, 5040, 40 320, 362 880, 3 628 800}
n!
O u t [ ] =
{1, 2, 6, 24, 120, 720, 5040, 40 320, 362 880, 3 628 800}
O u t [ ] =
3 628 800
I n [ ] : = Clear[fact]
fact = 1
(*This is the initialization step*)
Do[fact = fact n, {n, 1, 10}]
Print[fact]
O u t [ ] =
3 628 800
I n [ ] : = (*Similarly :*)
Clear[fact]
fact = 2
(*This is the initialization step*)
Do[fact = fact n, {n, 1, 10}]
Print[fact]
O u t [ ] =
7 257 600
2 1. (b) Assignment 01 Full Ques Solution by Sabbir Hossen (AE-1977).nb
I n [ ] : = (*Similarly: *)
Clear[fact]
For[fact = 2; i = 1, i < 11, i ++, fact = fact * i]
Print[fact]
7 257 600
I n [ ] : = (*Similarly*)
Clear[fact]
i = 2; fact = 2; While[i < 11, fact = fact * i; i ++]
Print[fact]
7 257 600
I n [ ] : =
{1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765}
n = 1;
While[isPrime[2 ^ (2 n) + 1], n ++];
Print[n]
3
I n [ ] : =
100
101
result
O u t [ ] =
210
0.999855
1.
4 1. (b) Assignment 01 Full Ques Solution by Sabbir Hossen (AE-1977).nb
I n [ ] : =
(*2.b(i) : Input an integer n. Compute the sum and the product of the terms 1,
1+1/3,1+1/3+1/5,......... 1+1/3+1/5+.........+nth term using Do loop*)
n = Input["Enter the value of n: "];
sum = 0;
product = 1;
12 054 763
Sum:
692 835
2 139 206 887 586 802 656 551 105 230 340 096
Product:
10 598 898 402 009 350 930 602 965 234 375
I n [ ] : =
(*2.b(ii) : Input an integer n. Compute the sum and the product of the terms 1,
1+1/3,1+1/3+1/5,......... 1+1/3+1/5+.........+nth term using For loop *)
n = Input["Enter the value of n: "];
sum = 0;
product = 1;
12 054 763
Sum:
692 835
2 139 206 887 586 802 656 551 105 230 340 096
Product:
10 598 898 402 009 350 930 602 965 234 375
1. (b) Assignment 01 Full Ques Solution by Sabbir Hossen (AE-1977).nb 5
{8, 18, - 2, 13, - 11, - 11, 14, 7, - 13, 11, - 3, 14, 9, - 20, - 7}
(*Arithmetic Mean*)
arithmeticMean = Mean[numbers]
(*Geometric Mean*)
geometricMean = N[GeometricMean[numbers]]
(*Harmonic Mean*)
harmonicMean = N[HarmonicMean[numbers]]
O u t [ ] =
{8, 18, - 2, 13, - 11, - 11, 14, 7, - 13, 11, - 3, 14, 9, - 20, - 7}
O u t [ ] =
9
5
O u t [ ] =
9.09546 + 1.9333
O u t [ ] =
- 27.7923
6 1. (b) Assignment 01 Full Ques Solution by Sabbir Hossen (AE-1977).nb
randomIntegers
O u t [ ] =
{- 3, - 15, - 11, 2, 19, - 19, - 5, - 10, 6, 1, - 14, 4, 13, - 19, 12, - 13}
{- 3, - 15, - 11, 2, 19, - 19, - 5, - 10, 6, 1, - 14, 4, 13, - 19, 12, - 13}
I n [ ] : = (*3(d) Create a list contating the square of the elements of the list obtained in a*)
originalList = {8, 18, - 2, 13, - 11, - 11, 14, 7, - 13, 11, - 3, 14, 9, - 20, - 7};
squaredList = # ^ 2 & /@ originalList;
squaredList
O u t [ ] =
{64, 324, 4, 169, 121, 121, 196, 49, 169, 121, 9, 196, 81, 400, 49}
originalList = {8, 18, - 2, 13, - 11, - 11, 14, 7, - 13, 11, - 3, 14, 9, - 20, - 7};
{512, 5832, - 8, 2197, - 1331, - 1331, 2744, 343, - 2197, 1331, - 27, 2744, 729, - 8000, - 343}
(*(d) Create a list containing the square of the elements from (a)*)
squaredList = originalList ^ 2;
(*(e) Create another list containing the cube of the elements from (a)*)
cubedlist = originalList ^ 3;
O u t [ ] =
Transpose: "Permutation
{{-3, -15, -11, 2, 19, -19, -5, -10, 6, 1, 6}, {64, 324, 4, 169, 121, 121, 196, 49, 169, 121, 5}, {512, 5832, -8, 2197, -1331, -1
331, 2744, 343, -2197, 1331, 5}} is longer than the dimensions {3} of the expression."
{1}
{1, 1}
{1, 2, 1}
{1, 3, 3, 1}
{1, 4, 6, 4, 1}
{1, 5, 10, 10, 5, 1}
O u t [ ] / / T a b l e F o r m =
p q p∨q ¬p (p∨q)∧(¬p) (p∨q)∧(¬p)q
True True True False False True
True False True False False True
False True True True True True
False False False True False True
(*Given data*)
totalStudents = 75;
newspaperStudents = 29;
televisionStudents = 43;
bothStudents = 7;
(*Step 6(a): Calculate the number of students who got news from only newspaper*)
onlyNewspaperStudents = newspaperStudents - bothStudents;
(*Step 6(b): Calculate the number of students who got news from only television*)
onlyTelevisionStudents = televisionStudents - bothStudents;
(*Step 6(c):
Calculate the number of students who got news from either newspaper or television*)
eitherOrStudents = onlyNewspaperStudents + onlyTelevisionStudents + bothStudents;
O u t [ ] =
22
O u t [ ] =
36
O u t [ ] =
65
O u t [ ] =
10
10 1. (b) Assignment 01 Full Ques Solution by Sabbir Hossen (AE-1977).nb
O u t [ ] =
{{B, 78 000 000}, {A, 76 000 000}, {D, 54 000 000}, {C, 28 000 000}}
O u t [ ] =
O u t [ ] =
{{A, 14 000 000}, {B, 8 000 000}, {D, 4 000 000}, {C, 0}}
(*Determine the total votes for each candidate in the current round*)
totalVotes = Total /@ Transpose[votes];
(*Update the total votes for the remaining candidates in the current round*)
totalVotes = Total /@ Transpose[votes];
O u t [ ] / / T a b l e F o r m =
Candidate Total Votes
A 26 000 000
B 26 000 000
C 22 000 000
D 18 000 000
{A, B, C, D}〚First[{}]〛
standardDivisor2022
standardDivisor2023
O u t [ ] =
1
18
O u t [ ] =
50
909
lowerQuota2022 = Floor[standardQuota2022];
lowerQuota2023 = Floor[standardQuota2023];
upperQuota2022 = Ceiling[standardQuota2022];
upperQuota2023 = Ceiling[standardQuota2023];
O u t [ ] =
1475 340 865 250 130
, , , , , {163, 113, 96, 83, 43}, {164, 114, 97, 84, 44}
9 3 9 3 3
O u t [ ] =
148 000 34 000 90 500 25 000 13 000
, , , , , {162, 112, 99, 82, 42}, {163, 113, 100, 83, 43}
909 303 909 303 303
1. (b) Assignment 01 Full Ques Solution by Sabbir Hossen (AE-1977).nb 15
hamiltonApportionment2022
hamiltonApportionment2023
O u t [ ] =
sortedDepartments2022 = SortBy[
Transpose[{Range[Length[fractionalParts2022]], fractionalParts2022}], Last]〚All, 1〛;
sortedDepartments2023 = SortBy[
Transpose[{Range[Length[fractionalParts2023]], fractionalParts2023}], Last]〚All, 1〛;
jeffersonApportionment2022
jeffersonApportionment2023
O u t [ ] =
adamsApportionment2022
adamsApportionment2023
O u t [ ] =
websterApportionment2022
websterApportionment2023
O u t [ ] =