Professional Documents
Culture Documents
Dipankar Pokhrel
Roll-No.- 236121017
November 10, 2023
24
25 decimal_number = 123.124
26 b i n a r y _ r e p r e sent ation = decimal_to_binary ( decimal_number )
27 print ( f " The binary representation of { decimal_number } is : { binar y_re prese ntat ion } " )
1
OUTPUT:
The binary representation of 123.124 is: 1111011.000111111011111001110110110010001011010000111
Q) Choose X values from 1 to 1000. Generate F(X) values. If it is even write it as H, and T if it is odd.
Listing 2: Python Code to generate 1000 random number using Pseudo-Random Number generator:
1 # Define LCG parameters
2 a = 1664525
3 b = 1013904223
4 c = 2**32
5
OUTPUT:
F(x) Random Number Sequence: [1015568748, 1017233273, 1018897798, 1020562323, 1022226848, 1023891373, 1025555898,
1027220423, 1028884948, 1030549473, 1032213998, 1033878523, 1035543048, 1037207573, 1038872098, 1040536623,
1042201148, 1043865673, 1045530198, 1047194723, 1048859248, 1050523773, 1052188298, 1053852823, 1055517348,
1057181873, 1058846398, 1060510923, 1062175448, 1063839973, 1065504498, 1067169023, 1068833548, 1070498073,
1072162598, 1073827123, 1075491648, 1077156173, 1078820698, 1080485223, 1082149748, 1083814273, 1085478798,
1087143323, 1088807848, 1090472373, 1092136898, 1093801423, 1095465948, 1097130473, 1098794998, 1100459523,
1102124048, 1103788573, 1105453098, 1107117623, 1108782148, 1110446673, 1112111198, 1113775723, 1115440248,
1117104773, 1118769298, 1120433823, 1122098348, 1123762873, 1125427398, 1127091923, 1128756448, 1130420973,
1132085498, 1133750023, 1135414548, 1137079073, 1138743598, 1140408123, 1142072648, 1143737173, 1145401698,
1147066223, 1148730748, 1150395273, 1152059798, 1153724323, 1155388848, 1157053373, 1158717898, 1160382423,
1162046948, 1163711473, 1165375998, 1167040523, 1168705048, 1170369573, 1172034098, 1173698623, 1175363148,
1177027673, 1178692198, 1180356723, 1182021248, 1183685773, 1185350298, 1187014823, 1188679348, 1190343873,
1192008398, 1193672923, 1195337448, 1197001973, 1198666498, 1200331023, 1201995548, 1203660073, 1205324598,
1206989123, 1208653648, 1210318173, 1211982698, 1213647223, 1215311748, 1216976273, 1218640798, 1220305323,
1221969848, 1223634373, 1225298898, 1226963423, 1228627948, 1230292473, 1231956998, 1233621523, 1235286048,
1236950573, 1238615098, 1240279623, 1241944148, 1243608673, 1245273198, 1246937723, 1248602248, 1250266773,
1251931298, 1253595823, 1255260348, 1256924873, 1258589398, 1260253923, 1261918448, 1263582973, 1265247498,
1266912023, 1268576548, 1270241073, 1271905598, 1273570123, 1275234648, 1276899173, 1278563698, 1280228223,
1281892748, 1283557273, 1285221798, 1286886323, 1288550848, 1290215373, 1291879898, 1293544423, 1295208948,
1296873473, 1298537998, 1300202523, 1301867048, 1303531573, 1305196098, 1306860623, 1308525148, 1310189673,
1311854198, 1313518723, 1315183248, 1316847773, 1318512298, 1320176823, 1321841348, 1323505873, 1325170398,
1326834923, 1328499448, 1330163973, 1331828498, 1333493023, 1335157548, 1336822073, 1338486598, 1340151123,
1341815648, 1343480173, 1345144698, 1346809223, 1348473748, 1350138273, 1351802798, 1353467323, 1355131848,
1356796373, 1358460898, 1360125423, 1361789948, 1363454473, 1365118998, 1366783523, 1368448048, 1370112573,
2
1371777098, 1373441623, 1375106148, 1376770673, 1378435198, 1380099723, 1381764248, 1383428773, 1385093298,
1386757823, 1388422348, 1390086873, 1391751398, 1393415923, 1395080448, 1396744973, 1398409498, 1400074023,
1401738548, 1403403073, 1405067598, 1406732123, 1408396648, 1410061173, 1411725698, 1413390223, 1415054748,
1416719273, 1418383798, 1420048323, 1421712848, 1423377373, 1425041898, 1426706423, 1428370948, 1430035473,
1431699998, 1433364523, 1435029048, 1436693573, 1438358098, 1440022623, 1441687148, 1443351673, 1445016198,
1446680723, 1448345248, 1450009773, 1451674298, 1453338823, 1455003348, 1456667873, 1458332398, 1459996923,
1461661448, 1463325973, 1464990498, 1466655023, 1468319548, 1469984073, 1471648598, 1473313123, 1474977648,
1476642173, 1478306698, 1479971223, 1481635748, 1483300273, 1484964798, 1486629323, 1488293848, 1489958373,
1491622898, 1493287423, 1494951948, 1496616473, 1498280998, 1499945523, 1501610048, 1503274573, 1504939098,
1506603623, 1508268148, 1509932673, 1511597198, 1513261723, 1514926248, 1516590773, 1518255298, 1519919823,
1521584348, 1523248873, 1524913398, 1526577923, 1528242448, 1529906973, 1531571498, 1533236023, 1534900548,
1536565073, 1538229598, 1539894123, 1541558648, 1543223173, 1544887698, 1546552223, 1548216748, 1549881273,
1551545798, 1553210323, 1554874848, 1556539373, 1558203898, 1559868423, 1561532948, 1563197473, 1564861998,
1566526523, 1568191048, 1569855573, 1571520098, 1573184623, 1574849148, 1576513673, 1578178198, 1579842723,
1581507248, 1583171773, 1584836298, 1586500823, 1588165348, 1589829873, 1591494398, 1593158923, 1594823448,
1596487973, 1598152498, 1599817023, 1601481548, 1603146073, 1604810598, 1606475123, 1608139648, 1609804173,
1611468698, 1613133223, 1614797748, 1616462273, 1618126798, 1619791323, 1621455848, 1623120373, 1624784898,
1626449423, 1628113948, 1629778473, 1631442998, 1633107523, 1634772048, 1636436573, 1638101098, 1639765623,
1641430148, 1643094673, 1644759198, 1646423723, 1648088248, 1649752773, 1651417298, 1653081823, 1654746348,
1656410873, 1658075398, 1659739923, 1661404448, 1663068973, 1664733498, 1666398023, 1668062548, 1669727073,
1671391598, 1673056123, 1674720648, 1676385173, 1678049698, 1679714223, 1681378748, 1683043273, 1684707798,
1686372323, 1688036848, 1689701373, 1691365898, 1693030423, 1694694948, 1696359473, 1698023998, 1699688523,
1701353048, 1703017573, 1704682098, 1706346623, 1708011148, 1709675673, 1711340198, 1713004723, 1714669248,
1716333773, 1717998298, 1719662823, 1721327348, 1722991873, 1724656398, 1726320923, 1727985448, 1729649973,
1731314498, 1732979023, 1734643548, 1736308073, 1737972598, 1739637123, 1741301648, 1742966173, 1744630698,
1746295223, 1747959748, 1749624273, 1751288798, 1752953323, 1754617848, 1756282373, 1757946898, 1759611423,
1761275948, 1762940473, 1764604998, 1766269523, 1767934048, 1769598573, 1771263098, 1772927623, 1774592148,
1776256673, 1777921198, 1779585723, 1781250248, 1782914773, 1784579298, 1786243823, 1787908348, 1789572873,
1791237398, 1792901923, 1794566448, 1796230973, 1797895498, 1799560023, 1801224548, 1802889073, 1804553598,
1806218123, 1807882648, 1809547173, 1811211698, 1812876223, 1814540748, 1816205273, 1817869798, 1819534323,
1821198848, 1822863373, 1824527898, 1826192423, 1827856948, 1829521473, 1831185998, 1832850523, 1834515048,
1836179573, 1837844098, 1839508623, 1841173148, 1842837673, 1844502198, 1846166723, 1847831248, 1849495773,
1851160298, 1852824823, 1854489348, 1856153873, 1857818398, 1859482923, 1861147448, 1862811973, 1864476498,
1866141023, 1867805548, 1869470073, 1871134598, 1872799123, 1874463648, 1876128173, 1877792698, 1879457223,
1881121748, 1882786273, 1884450798, 1886115323, 1887779848, 1889444373, 1891108898, 1892773423, 1894437948,
1896102473, 1897766998, 1899431523, 1901096048, 1902760573, 1904425098, 1906089623, 1907754148, 1909418673,
1911083198, 1912747723, 1914412248, 1916076773, 1917741298, 1919405823, 1921070348, 1922734873, 1924399398,
1926063923, 1927728448, 1929392973, 1931057498, 1932722023, 1934386548, 1936051073, 1937715598, 1939380123,
1941044648, 1942709173, 1944373698, 1946038223, 1947702748, 1949367273, 1951031798, 1952696323, 1954360848,
1956025373, 1957689898, 1959354423, 1961018948, 1962683473, 1964347998, 1966012523, 1967677048, 1969341573,
1971006098, 1972670623, 1974335148, 1975999673, 1977664198, 1979328723, 1980993248, 1982657773, 1984322298,
1985986823, 1987651348, 1989315873, 1990980398, 1992644923, 1994309448, 1995973973, 1997638498, 1999303023,
2000967548, 2002632073, 2004296598, 2005961123, 2007625648, 2009290173, 2010954698, 2012619223, 2014283748,
2015948273, 2017612798, 2019277323, 2020941848, 2022606373, 2024270898, 2025935423, 2027599948, 2029264473,
2030928998, 2032593523, 2034258048, 2035922573, 2037587098, 2039251623, 2040916148, 2042580673, 2044245198,
2045909723, 2047574248, 2049238773, 2050903298, 2052567823, 2054232348, 2055896873, 2057561398, 2059225923,
2060890448, 2062554973, 2064219498, 2065884023, 2067548548, 2069213073, 2070877598, 2072542123, 2074206648,
2075871173, 2077535698, 2079200223, 2080864748, 2082529273, 2084193798, 2085858323, 2087522848, 2089187373,
3
2090851898, 2092516423, 2094180948, 2095845473, 2097509998, 2099174523, 2100839048, 2102503573, 2104168098,
2105832623, 2107497148, 2109161673, 2110826198, 2112490723, 2114155248, 2115819773, 2117484298, 2119148823,
2120813348, 2122477873, 2124142398, 2125806923, 2127471448, 2129135973, 2130800498, 2132465023, 2134129548,
2135794073, 2137458598, 2139123123, 2140787648, 2142452173, 2144116698, 2145781223, 2147445748, 2149110273,
2150774798, 2152439323, 2154103848, 2155768373, 2157432898, 2159097423, 2160761948, 2162426473, 2164090998,
2165755523, 2167420048, 2169084573, 2170749098, 2172413623, 2174078148, 2175742673, 2177407198, 2179071723,
2180736248, 2182400773, 2184065298, 2185729823, 2187394348, 2189058873, 2190723398, 2192387923, 2194052448,
2195716973, 2197381498, 2199046023, 2200710548, 2202375073, 2204039598, 2205704123, 2207368648, 2209033173,
2210697698, 2212362223, 2214026748, 2215691273, 2217355798, 2219020323, 2220684848, 2222349373, 2224013898,
2225678423, 2227342948, 2229007473, 2230671998, 2232336523, 2234001048, 2235665573, 2237330098, 2238994623,
2240659148, 2242323673, 2243988198, 2245652723, 2247317248, 2248981773, 2250646298, 2252310823, 2253975348,
2255639873, 2257304398, 2258968923, 2260633448, 2262297973, 2263962498, 2265627023, 2267291548, 2268956073,
2270620598, 2272285123, 2273949648, 2275614173, 2277278698, 2278943223, 2280607748, 2282272273, 2283936798,
2285601323, 2287265848, 2288930373, 2290594898, 2292259423, 2293923948, 2295588473, 2297252998, 2298917523,
2300582048, 2302246573, 2303911098, 2305575623, 2307240148, 2308904673, 2310569198, 2312233723, 2313898248,
2315562773, 2317227298, 2318891823, 2320556348, 2322220873, 2323885398, 2325549923, 2327214448, 2328878973,
2330543498, 2332208023, 2333872548, 2335537073, 2337201598, 2338866123, 2340530648, 2342195173, 2343859698,
2345524223, 2347188748, 2348853273, 2350517798, 2352182323, 2353846848, 2355511373, 2357175898, 2358840423,
2360504948, 2362169473, 2363833998, 2365498523, 2367163048, 2368827573, 2370492098, 2372156623, 2373821148,
2375485673, 2377150198, 2378814723, 2380479248, 2382143773, 2383808298, 2385472823, 2387137348, 2388801873,
2390466398, 2392130923, 2393795448, 2395459973, 2397124498, 2398789023, 2400453548, 2402118073, 2403782598,
2405447123, 2407111648, 2408776173, 2410440698, 2412105223, 2413769748, 2415434273, 2417098798, 2418763323,
2420427848, 2422092373, 2423756898, 2425421423, 2427085948, 2428750473, 2430414998, 2432079523, 2433744048,
2435408573, 2437073098, 2438737623, 2440402148, 2442066673, 2443731198, 2445395723, 2447060248, 2448724773,
2450389298, 2452053823, 2453718348, 2455382873, 2457047398, 2458711923, 2460376448, 2462040973, 2463705498,
2465370023, 2467034548, 2468699073, 2470363598, 2472028123, 2473692648, 2475357173, 2477021698, 2478686223,
2480350748, 2482015273, 2483679798, 2485344323, 2487008848, 2488673373, 2490337898, 2492002423, 2493666948,
2495331473, 2496995998, 2498660523, 2500325048, 2501989573, 2503654098, 2505318623, 2506983148, 2508647673,
2510312198, 2511976723, 2513641248, 2515305773, 2516970298, 2518634823, 2520299348, 2521963873, 2523628398,
2525292923, 2526957448, 2528621973, 2530286498, 2531951023, 2533615548, 2535280073, 2536944598, 2538609123,
2540273648, 2541938173, 2543602698, 2545267223, 2546931748, 2548596273, 2550260798, 2551925323, 2553589848,
2555254373, 2556918898, 2558583423, 2560247948, 2561912473, 2563576998, 2565241523, 2566906048, 2568570573,
2570235098, 2571899623, 2573564148, 2575228673, 2576893198, 2578557723, 2580222248, 2581886773, 2583551298,
2585215823, 2586880348, 2588544873, 2590209398, 2591873923, 2593538448, 2595202973, 2596867498, 2598532023,
2600196548, 2601861073, 2603525598, 2605190123, 2606854648, 2608519173, 2610183698, 2611848223, 2613512748,
2615177273, 2616841798, 2618506323, 2620170848, 2621835373, 2623499898, 2625164423, 2626828948, 2628493473,
2630157998, 2631822523, 2633487048, 2635151573, 2636816098, 2638480623, 2640145148, 2641809673, 2643474198,
2645138723, 2646803248, 2648467773, 2650132298, 2651796823, 2653461348, 2655125873, 2656790398, 2658454923,
2660119448, 2661783973, 2663448498, 2665113023, 2666777548, 2668442073, 2670106598, 2671771123, 2673435648,
2675100173, 2676764698, 2678429223]
Coin toss: [’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
4
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’,
’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’, ’H’, ’T’]
Q) Run the decimal to binary first and test with 12.63 to binary.
5
17 bin ary_fr actional = " "
18 precision = 8 # Adjust precision as needed
19 while fractional_part > 0 and len ( binary_fractional ) < precision :
20 fractional_part *= 2
21 bit = int ( fractional_part )
22 bina ry_fractional += str ( bit )
23 fractional_part -= bit
24
OUTPUT :
The binary representation of 12.63 is: 1100.10100001
Q) Generate pairs of 10000 random real numbers using the Mod function inside a square of size 2 with center at the origin
corresponding to points on a plane. Count how many of these points fall inside the circle of radius 1 with center at the
same origin. From this find the value of pi.
15 # LCG initialization
16 X = seed
6
17
23 X = (a * X + b) % m
24 y = (X / m) * 2 - 1 # Scale to the range [ -1 , 1]
25
38 # Generate points and count those inside the circle using LCG
39 points_inside_circle , outside_x , outside_y = generate_points_lcg ( num_points )
40
46 # Plotting
47 plt . figure ( figsize =(8 , 8) )
48
58 # Add circle
59 circle = plt . Circle ((0 , 0) , 1 , edgecolor = ’ red ’ , facecolor = ’ none ’ , linestyle = ’ dashed ’ ,
linewidth =2)
60 plt . gca () . add_patch ( circle )
61
62 plt . title ( f ’ Monte Carlo Simulation for Estimating pi using LCG = { estimated_pi } ’)
63 plt . legend ()
64 plt . show ()
OUTPUT:
Estimated value of pi: 3.1184
7
8
Q) Write a robust code in some language to implement LU decomposition of an invertible square matrix. Write another
program that calls this to solve a linear system of equations.
9 for k in range ( n - 1) :
10 pivot_index = np . argmax ( np . abs ( U [ k : , k ]) ) + k
11 U [[ k , pivot_index ] , :] = U [[ pivot_index , k ] , :]
12 P [[ k , pivot_index ] , :] = P [[ pivot_index , k ] , :]
13
14 for i in range ( k + 1 , n ) :
15 factor = U [i , k ] / U [k , k ]
16 L [i , k ] = factor
17 U [i , k :] -= factor * U [k , k :]
18
19 return L , U , P
20
21 def print_matrices (L , U ) :
22 print ( " Lower Triangular Matrix ( L ) : " )
23 print ( L )
24 print ( " \ nUpper Triangular Matrix ( U ) : " )
25 print ( U )
26
27 def s ol v e _l i n ea r _system (A , b ) :
28 L , U , P = lu_decomposition ( A )
29
30 print_matrices (L , U )
31
35 return x
36
37 # Example usage :
38 A = np . array ([[2 , -1 , 1] ,
39 [ -3 , -1 , 4] ,
40 [ -1 , 1 , 3]])
41
44 solution = s o l ve _linear_system (A , b )
45 print ( " \ nSolution : " , solution )
9
OUTPUT :
Lower Triangular Matrix (L):
1 0 0
−0.66666667 1 0
0.33333333 −0.8 1
Upper Triangular Matrix (U):
−3 −1 4
0 −1.66666667 3.66666667
0 0 4.6
Solution: [ 3.52173913 -0.08695652 0.86956522]
8 D = np . diag ( np . diag ( M ) )
9 R = M - D
10
17 raise ValueError ( " Jacobi method did not converge within the specified number of
iterations . " )
18
31 raise ValueError ( " Gauss - Seidel method did not converge within the specified number of
iterations . " )
32
33 # Example usage :
10
34 M0 = np . diag ([2 , 3 , 4]) # Example diagonal matrix
35 V = np . array ([[1 , -1 , 0] , [ -1 , 2 , -1] , [0 , -1 , 3]]) # Example off - diagonal part
36 M = M0 + V # Construct M
37 b = np . array ([1 , 2 , 3]) # Example right - hand side vector
38
OUTPUT:
Solution using Jacobi method: [0.53684195 0.61052616 0.51578941]
Solution using Gauss-Seidel method: [0.53684207 0.61052631 0.51578947]
Listing 7: Python code for solving ODE using Runge-Kutta 4th order
1
16 k1 = h * f ( x0 , y0 )
17 k2 = h * f ( x0 + h /2 , y0 + k1 /2)
18 k3 = h * f ( x0 + h /2 , y0 + k2 /2)
19 k4 = h * f ( x0 + h , y0 + k3 )
20
21 k = ( k1 + 2*( k2 + k3 ) + k4 ) /6
22
23 y1 = y0 + k
24 x0 = x0 + h
25 y0 = y1
26 x_rk . append ( x0 )
27 y_rk . append ( y0 )
28
11
29 return y1
30 print ( f " The value of y at x = { x } is { round ( rk ( x0 , y0 ) ,4) } " )
OUTPUT
Q) Solve Laplace equation inside a square of side 1 by breaking it up into n2 small squares of equal size. Find a way to
write it as a linear system. Try it for n = 3,4,5 first to get an idea how to write it as a matrix equation. The boundary
condition is the top edge of the square is at potential equal to 1 volt and other edges are grounded.
10
16
24 # convergence criteria
25 max_iterations = 1000
12
26 tolerance = 1e -4
27
13
OUTPUT
The output shows a matrix with those calculated unknown values in place respectively
1 1 1
0 0.25 0
0 0 0
1 1 1 1
0 0.37493896 0.37493896 0
0 0.12493896 0.12493896 0
0 0 0 0
1. 1. 1. 1. 1.
0. 0.42847988 0.52666364 0.42847988 0.
0. 0.18737793 0.24981689 0.18737793 0.
0. 0.07133702 0.09809222 0.07133702 0.
0. 0. 0. 0. 0.
14
Figure 1: For 4×4 Figure 2: For 5×5
15
Q) In today’s lab, verify law of large numbers which says that if you add large (strictly speaking infinitely) many random
variables of the same type, the resulting random number will not be random but will take a value proportional to the mean.
Verify this for 100 fair dice. Even though x1, x2 etc. are random, x1+x2 +..... + x100 = 350 (nearly always)
2 import random as rn
3 import matplotlib . pyplot as plt
4
8 sample_mean = []
9 sum_of_dice = []
10 dice_rolls = [ rn . randint (1 ,6) for _ in range ( number_dice ) ]
11
12 single_roll_mean = (1 + 2 + 3 + 4 + 5 + 6) /6
13
43 plt . show ()
16
Output
Mean of single roll 3.5
Mean of the 100 roll = 3.58
Sum of 100 dice roll = 358
The standard deviation is 0.19551067598579988
17
Q) On the computer toss a fair six sided die 100 times. Find the chi2 value. Repeat the above process 1000 times and draw
a bar chart for the possible values of chi2 .
5 import numpy as np
6
7 import random
8
18
Output:
The Chi-squared value: 4.16
19
P100
Q) Try to simulate the 1D Ising model H = − i (si · si+1 + si ) for 100 spins on a circle. Calculate the average
magnetization at various temperatures T = 1.0, T = 0.01, T = 0.01, T = 2.0. Using Metropolis algorithm. s(j) = +1 or -1
P100
H = i (−si · si+1 - si · si−1 + si · si+2 + si · si−2 + h·si )
Here, J = −1 and h = −1
24 if debug :
25 print ( " Starting configuration : " , configuration )
26
20
39 average_spin = configuration . mean ()
40 if i % save_freq == 0:
41 average_spins . append ( average_spin )
42
43 if debug and i % 10 == 0:
44 print ( " % i : " % i , configuration , " Energy : " , current_energy , " Spin : " , average_spin )
45
48 # Parameters
49 num_spins = 100
50 num_steps = 1000
51 temperatures = [1.0 , 0.1 , 0.01 , 2.0]
52
71 plt . tight_layout ()
72 plt . show ()
OUTPUT
Temperature: 1.0
Final Average Spin: 1.0
Final Magnetization: 1.0
Temperature: 0.1
Final Average Spin: 1.0
Final Magnetization: 1.0
Temperature: 0.01
Final Average Spin: 1.0
Final Magnetization: 1.0
Temperature: 2.0
Final Average Spin: 0.76
Final Magnetization: 0.74
21
22
1.1.2 Hamiltonian of second kind
P100
H = i (−si · si+1 - si · si−1 + si · si+2 + si · si−2 + h·si )
Here, we take h = 1
30 if debug :
31 print ( " Starting configuration : " , configuration )
32
23
43 configuration [ spin_to_change ] *= -1
44
49 if debug and i % 10 == 0:
50 print ( " % i : " % i , configuration , " Energy : " , current_energy , " Spin : " , average_spin )
51
54 # Parameters
55 num_spins = 100
56 num_steps = 1000
57 temperatures = [1.0 , 0.1 , 0.01 , 2.0]
58
77 plt . tight_layout ()
78 plt . show ()
OUTPUT
Temperature: 1.0
Final Average Spin: 0.1
Final Magnetization: 0.1
Temperature: 0.1
Final Average Spin: 0.36
Final Magnetization: 0.36
Temperature: 0.01
Final Average Spin: 0.48
Final Magnetization: 0.48
Temperature: 2.0
Final Average Spin: 0.2
Final Magnetization: 0.18
24
25
Q) Make chatGPT write a program to draw a RC circuit diagram with R and C in series with a battery of 1 volt.
LaTeX Code
\{ d o c u m e n t c l a s s { s t a n d a l o n e }
\ usepackage { c i r c u i t i k z }
\ b e g i n { document }
\ begin { c i r c u i t i k z }
\draw ( 0 , 0 ) t o [ V, v=1V] ( 0 , 2 )
t o [ R, l =$R$ ] ( 2 , 2 )
t o [ C, l =$C$ ] ( 2 , 0 )
−− ( 0 ,0);
\end{ c i r c u i t i k z }
\end{ document }
RC Circuit Diagram
R
1V C
26
Q) Ask chatGPT to give you seismic yield of some underground nuclear explosion as a function of time. Then ask it to
write a program to do FFT on it. Then run it.
Python Code
Listing 13: Python Code for FFT of seismic yield of underground nuclear explosion:
1 import numpy as np
2 import matplotlib . pyplot as plt
3
28 # Perform FFT
29 frequencies , mag nitude_spectrum = perform_fft ( synthetic_data , 1 / dt )
30
34 plt . subplot (2 , 1 , 1)
35 plt . plot ( times , synthetic_data )
36 plt . title ( ’ Complex Synthetic Seismic Data ’)
37 plt . xlabel ( ’ Time ( s ) ’)
38 plt . ylabel ( ’ Amplitude ’)
39
40 plt . subplot (2 , 1 , 2)
41 plt . plot ( frequencies , magnitude_spectrum )
42 plt . title ( ’ FFT Result ’)
27
43 plt . xlabel ( ’ Frequency ( Hz ) ’)
44 plt . ylabel ( ’ Magnitude ’)
45
46 plt . tight_layout ()
47 plt . show ()
28
Q) Ask ChatGPT to solve some JEE Advanced Maths question. I think it will not succeed. Then ask it to write code to
answer that question. Run the code and see if the answer is correct.
Question 1
If θ is an acute angle such that tan θ = 34 , and ϕ is an acute angle such that cos ϕ = 5
13 , calculate the value of sin(θ + ϕ).
Python Code:
3 # Given values
4 tan_theta = 3/4
5 cos_phi = 5/13
6
Output:
sin(θ + ϕ) : 0.5088
Question 2
Find the roots of z 4 + 1 = 0.
Python Code:
29
Root: -0.7071 + 0.7071i
Root: -0.7071 - 0.7071i
Root: 0.7071 + 0.7071i
Root: 0.7071 - 0.7071i
Question 3
If sin θ = 53 and cos ϕ = 45 , find the value of tan(θ − ϕ).
Python Code:
3 # Given values
4 sin_theta = 3/5
5 cos_phi = 4/5
6
Output:
tan(θ − ϕ) : 0.8750
30