Question

In: Math

(a) Write an R function rnormmax that has three arguments, n, mu, and sigm, # and...

(a) Write an R function rnormmax that has three arguments, n, mu, and sigm,
# and returns the maximum of a vector of n random numbers from the normal distribution
# with mean mu and standard deviation sigm. Make the arguments mu and sigm optional
# with default values of 0 and 1, respectively.


# (b) Write an R code that replicates rnormmax(n=1000) hundred thousand times and creates
# a histogram of the resulting vector via standard hist function.

Solutions

Expert Solution

> t=rnorm(1000,0,1)
> t
   [1] -0.2025522364 -0.5628747394 0.3008293670 -0.0109936054 -1.3858062077
   [6] -1.0962769079 -0.4107434903 -0.9213600548 1.0035003042 -0.2287652089
[11] -0.1893576987 -0.3368195312 1.1492968266 0.2464101887 0.1275073552
[16] 0.0212622805 -1.1876985396 1.1493823781 -0.5495349805 1.2107117707
[21] 0.1476249844 -0.5137755952 0.7154159488 -0.9079026442 0.9561299448
[26] 0.9152880058 0.0531798150 0.7805725446 -0.4689627635 1.2295162792
[31] -1.5463529114 1.3277500555 -0.6857960485 0.5753645844 1.2946730943
[36] 1.5413879495 2.4402947504 0.8391489027 -0.4098228396 0.5674069851
[41] 1.0035146891 -0.0486254537 0.0215929972 -0.1105703858 0.4394433651
[46] 1.2026577962 -0.8336760830 -0.5495587990 0.1331179584 0.6856567892
[51] -0.3440381303 0.1631663831 -0.0949072779 1.1075549157 0.4194171146
[56] 0.6229146401 0.0716801413 -0.7113681939 -0.3922119388 0.3187030466
[61] -0.1981484884 0.1527989123 -0.2197427597 -0.3125554996 -0.0058168765
[66] -0.3333864452 0.8002497373 -0.9048584392 0.6686276084 -0.3769060917
[71] 0.3714546746 1.0371545897 0.6211163640 1.0348307519 0.9547224732
[76] 0.5280907971 -1.8446492578 1.3593743376 -0.8847838502 -1.6531572284
[81] -0.4015734208 0.2643377498 -0.5787477472 1.4719815707 0.3594939962
[86] 0.3282870768 -0.5745701271 -0.1798735695 -0.4119014426 1.2932262841
[91] 0.7229004919 -0.4589662382 -0.3662283877 -0.5225528414 -0.1378938617
[96] -0.1145632847 0.3932730051 -2.0932515616 0.3966931100 0.8927617739
[101] -1.6354471324 -0.1093359641 0.2675152310 0.5453859298 0.5501264148
[106] 0.5293513730 -0.1408506042 -1.6892246992 0.7675472476 -0.2610344597
[111] -0.0378232906 -1.3798153285 0.3157370288 -0.3803098311 -0.2124364966
[116] -0.2849530665 -1.7276265139 -0.3046483811 -0.7738003718 -0.2248115092
[121] -0.2748815879 0.0361064430 0.6220237545 0.5596878638 0.2614530359
[126] -0.4972331978 1.2920001635 -0.4705439438 -0.1166023995 -1.4252332256
[131] 0.7089964238 1.0474221429 0.6067528331 -0.9403456063 1.3385762767
[136] 0.5771250379 0.6278930018 1.0876027066 0.4944085221 0.2091250630
[141] -1.0352714293 -1.4980403551 -0.3706285436 1.7335901319 0.6673666077
[146] -2.2803426750 -0.0056788980 0.2184565331 -1.2256772101 0.4720021056
[151] -1.8838095431 -0.4832002909 -0.3460169051 -1.3122355349 -2.3052494413
[156] 0.2385604711 1.8094952747 0.4648103488 0.5727124343 0.4854108249
[161] 0.0909614677 0.9241014109 0.5492545344 -1.7165811306 -1.4557613700
[166] -0.1546512044 -0.2759981970 1.0201058149 -0.2776869610 -0.8527108929
[171] -0.3418175450 -0.0693307020 -0.3225739425 1.6739460969 -0.2265769340
[176] -0.2802373394 0.0673886795 -0.2604722815 -0.7654919623 0.0497559056
[181] 0.0387649155 1.5625207710 -0.4624629431 -0.3799278336 -0.9715111231
[186] 1.2477611681 0.3748317460 0.2773003468 0.8189999985 -0.2405951842
[191] -2.9023942032 0.4289912594 0.8790687109 -0.1225902032 1.0734815627
[196] -0.8889225905 1.1138304904 0.4893193643 -0.3519402895 -0.0532397498
[201] 0.0681823932 1.9106881252 0.5303131066 -1.0482230633 -1.5455368745
[206] 0.3927506928 -0.5973904842 0.4607816957 -0.1184833355 0.5013185369
[211] -0.9257726257 0.4036309429 -0.1048784607 0.0962906019 1.3508240386
[216] -0.5284700256 1.2251854935 -0.4524261686 -0.6877876995 1.8435222891
[221] -0.8981120073 -0.5329528079 -0.1199703087 -0.6945806316 0.0173226127
[226] -0.5252919367 0.1690543594 -0.9733771358 -0.4381525474 -0.0534270074
[231] -0.1298956717 1.6721701851 0.7005755692 1.2566961939 -0.7486124099
[236] -0.0347105508 -0.7074079574 2.3355110143 -0.2456218950 -0.2290159140
[241] -1.2461296948 1.9902288020 1.2248503730 0.2903711810 -0.7355894686
[246] 0.5261391475 1.3923401939 -0.6358666526 1.4424399936 1.8306958836
[251] 2.4213035383 0.0837812302 1.6425769993 0.7746677664 -0.0497985577
[256] -1.9570295902 -0.6319616357 -1.1310456029 0.1066941146 -1.5054429991
[261] 0.4696454255 0.2263526487 0.3905677629 -0.7445831666 0.2253111180
[266] 0.0860805830 0.0985692203 -1.6823983828 1.3297486793 -0.5502847221
[271] 0.5549378471 -1.3025372254 0.1165715299 1.8348790169 0.6559939187
[276] 0.0442428148 -1.6504688524 0.2468442698 0.4567844533 -0.3169586269
[281] -0.2252031159 0.5519666751 0.6579709070 -1.5195197139 0.7018229172
[286] 1.8976091251 -0.4675660837 -0.9865530451 0.5673402079 -1.3704862272
[291] -0.2130310577 -0.4034004471 -1.3799468390 -0.3694589173 -0.1462071054
[296] -0.6069931918 0.7261927725 1.3081854450 -0.3746482453 1.2451163625
[301] -0.9125328761 0.9289978665 2.6891318928 -0.2586707326 -1.0070125502
[306] 0.3603336147 -1.0583139642 -0.0841236383 1.0215098273 1.0337456989
[311] -0.3266162307 -0.6234850822 -0.1517971175 -0.1126043581 1.0096082536
[316] -1.6520311288 -0.5499717296 0.0429793409 -0.0752242226 0.6688033515
[321] -0.6885596083 0.4653900893 -1.5244869072 -1.1171355401 -0.4199355616
[326] 0.3631389084 0.1591553201 0.0237735846 2.1823580672 2.3367839389
[331] -0.6562386040 0.1430467205 -0.8611223386 0.5803456594 0.1968340588
[336] -0.3482853396 0.3955895806 0.6257726279 -0.1638736557 1.3918778205
[341] 0.2918034860 -1.5905217299 1.1631371069 0.4759245338 0.5751176725
[346] 0.0150661102 -0.8906693662 0.0972057298 0.4037993881 1.6068118375
[351] -1.6004795492 0.1882771921 0.1848302009 0.4150622129 -2.1537787052
[356] 0.6673806943 -0.2541352003 -0.2179916424 0.9195637575 -0.3308583099
[361] -0.2258694649 0.6257730583 0.2785488052 0.7635807053 1.3227192226
[366] 0.9739855938 -0.4870525713 1.6225563758 -0.1462025782 -1.2628124613
[371] 1.8895307356 0.7691235818 -0.5476250834 0.4645921413 -0.5464979680
[376] 0.8736952160 -1.5829098206 -0.9482162218 -0.2228455835 -0.3880619261
[381] -0.2141438067 0.6949777714 2.0830916173 1.2848939381 1.2794629002
[386] -0.2910378892 1.0768057444 -0.2026091824 -1.0908672330 0.0179094787
[391] -0.2383015052 0.6060615429 1.1884873587 0.2443356144 1.5881090284
[396] 1.4540601009 0.3311912352 1.0291899196 0.2412533253 0.9193650717
[401] -0.0654841823 -0.4741903806 0.8555858843 0.0280003309 0.8169500141
[406] 1.3549886007 -0.2478626954 2.1208050706 1.2261948898 1.0929750617
[411] -0.6289900900 -1.1932378657 -0.5214520393 -0.8655393555 1.4502974787
[416] 2.2923100172 -0.5582308091 1.2484139100 0.2590657379 -2.5241867219
[421] -0.1910783869 -0.9446639654 0.1428637860 -0.2725308100 -0.5627612462
[426] -0.6580382764 -1.5773343426 1.3906270799 0.1131595136 -0.8602791459
[431] -1.1302796253 -0.1047571987 0.4879611412 1.3701551546 0.3098070859
[436] -0.0831686569 0.9222211151 -1.4407204861 0.5284084718 0.0597960994
[441] 0.9036362772 -2.2536380053 -0.2113691496 0.9187724246 0.4670220266
[446] 0.1646240428 0.7597226237 -1.7588754831 -0.7403506108 -1.9511788069
[451] -0.4880138273 -0.3048329160 -0.7225816599 0.8481880727 -0.7530278870
[456] 0.7321343650 -1.1482381580 1.2271838361 -1.2004626373 0.5813847374
[461] 1.5033792898 0.2589796849 -1.2329232751 1.5764566921 -0.0483379271
[466] 0.1054956620 -0.3600173275 -0.1897516109 0.0220610662 0.0513737103
[471] -0.7213467797 0.5429561532 -0.2664934972 2.1995922957 0.5423069511
[476] 0.6465778025 1.0694886605 0.4745449712 -0.1184987694 -0.4964397429
[481] 0.0241505338 -1.8137380461 -0.4413217248 1.7276270519 -2.1521126447
[486] -0.8045814682 0.7782749523 -0.3821389208 0.4123923539 0.2372050732
[491] 0.2847092770 -0.8125047101 -0.3177382266 0.1286939771 -1.3705712406
[496] 0.1290176206 2.2511802661 -1.0565634905 0.2979908197 -0.8519048973
[501] -0.9583495140 -0.0839868743 0.3570596725 0.2738153128 0.8235904047
[506] -0.8192518817 0.2003253370 -0.4759068901 -1.1490941684 -0.2271246907
[511] 0.1477184440 1.8149550172 0.1338182546 0.9225289409 -0.2288736627
[516] 0.0281198056 -0.0015688186 0.1176072514 -0.5216006271 1.3486204248
[521] 0.0042147465 0.4077771608 1.3180463568 1.8686562111 -0.8830259975
[526] -1.5558168267 0.2243064102 -1.0240114130 0.4061856272 0.6450547696
[531] -1.1244732146 -0.4089068168 0.2702221483 1.1043985537 0.3833591805
[536] 0.5023906351 -0.2782964847 1.5553542498 -0.1581569029 1.7999941434
[541] -0.4562172867 -0.9735227507 -2.7918661272 -0.4885742379 -0.1442111559
[546] 0.9306161431 0.8262168593 -0.8675169697 0.3549181138 0.0383216395
[551] -0.6539441697 0.3533190190 -0.9888945504 -0.7273937994 -1.0018624035
[556] 0.9959127661 0.1796787852 0.2794359836 0.0337487391 0.2169360497
[561] 0.9233530205 -0.9706109671 -0.9142521953 1.4310574974 -1.2025934468
[566] 0.4539987524 -0.3313439667 0.5474132001 2.4584080514 -1.5734152526
[571] 0.1585364028 -0.2031045472 -1.0694911271 -0.3413409296 -1.5404381972
[576] 0.2115576330 -0.0400667516 1.5467148524 -0.4010646259 -0.2109143404
[581] -1.2043219696 0.0889806338 0.4012528597 -0.4995257052 0.0721152257
[586] 1.0809195779 0.8674474489 1.5079709555 0.1058030966 0.0617148380
[591] 0.0376292328 -0.3930555385 -0.3343346127 -1.5732488985 -0.0717255239
[596] -0.6015760461 1.3603736137 -0.0752886720 -0.1292807843 2.6279209830
[601] 0.0455296615 -0.6212435238 -0.0762190283 0.8643313243 0.6478249188
[606] 1.6862427578 -0.2336247048 -0.1492314386 -0.2947612216 -1.3469762447
[611] 0.2095358956 -0.5998770223 1.0366479537 -2.2634089492 -0.3300725712
[616] -0.7656621677 1.0260070282 -1.2892935698 1.2343083247 0.4095433685
[621] 0.3151639688 1.4063281845 -0.0664833564 0.8597618308 0.3636957891
[626] -0.5314789145 -0.0490763935 1.7584796002 -1.5137473584 0.2244716755
[631] -1.4208371968 -0.9032490317 -1.0064585233 -0.7739049383 -0.1230299392
[636] -0.5369971828 0.7763913215 0.0725337998 1.3420969707 0.7506599384
[641] 0.8081633562 1.2949831000 1.1543429506 -1.0579547168 0.1469428261
[646] 1.2041718894 -0.5031059892 -1.4370073518 -0.2961384980 0.5866857532
[651] 1.7237128395 0.1289828167 -0.3974472810 -0.1717501963 0.1840754202
[656] -2.0488973975 -0.9040558378 -0.1887247464 0.4189533910 -0.2940189003
[661] -1.0647253813 1.0675945396 -1.7001960251 -0.8213046659 -0.4292963576
[666] -0.1419867395 -0.2523163861 -0.5034848517 1.6205813577 -0.9198642984
[671] -2.2815878561 2.0069212673 1.2851827738 -0.1081651585 -0.7888897090
[676] -0.3422770624 0.6009313369 0.6179863375 0.5917973490 1.0805804145
[681] 0.4802099041 -1.3927499953 0.0881291867 0.1024914542 -0.0069081810
[686] -0.3319110002 1.7474602145 1.1213831376 -0.4850091102 -0.2482988401
[691] 0.1500464637 -1.0566799940 0.4437819984 0.7410912345 -0.3446143199
[696] -1.1766983534 1.4314953740 -0.0906640444 1.6160234295 1.4126012670
[701] 0.0526620907 -0.6238274618 1.5513567481 -0.0499453835 -0.0877633596
[706] -0.2822211892 0.0126528912 0.9566042125 -0.6480352312 1.0753458010
[711] -1.5353609706 -0.4527125954 -0.0226842697 0.2180156363 0.3941926967
[716] 0.3355424995 0.8620386665 -0.7008064992 -1.5239781204 0.6605754957
[721] 1.3320421496 -0.4581911619 -0.7530934936 0.8089266495 0.1833977991
[726] 0.2518361672 -0.0208305644 -0.7743529255 -0.5470275968 0.5608024360
[731] -1.2927490080 -1.2592401084 -1.1216186043 1.8744969681 -0.4662144739
[736] -0.7799670090 0.2853911069 -0.5874754601 0.8596082195 0.6941070214
[741] 1.1444028021 1.2941795739 0.2763331015 1.3732324786 0.7858863137
[746] 2.4819165409 -0.6049604536 -0.4760087252 0.4645846561 -0.1285365344
[751] 1.6112714903 -0.0822862867 -1.0177379158 -1.0645297566 -1.0664905562
[756] -1.3192808108 -0.4403430908 1.6494052300 0.2163710859 -1.0256137403
[761] 1.1043271903 0.3895521134 0.8210252534 0.2403786529 1.6833057021
[766] -0.6368842652 -0.3532137735 0.3141642029 -0.1807452018 0.1304195619
[771] -0.0321070307 -0.0279149320 -2.4968672451 0.3869069960 -0.8412269233
[776] 0.3934260423 0.8613270625 0.9782614554 -0.5025541329 0.5605497685
[781] -1.1820689627 -0.2925104982 -0.7302979023 -2.1881624439 -0.7831335319
[786] 0.1325351214 1.4387742089 1.0893274658 -0.2681151926 -1.2653356247
[791] 2.0591460915 0.8660551336 -0.2414855172 1.2341549536 0.9787053748
[796] 0.1676958877 0.0002627212 -0.3436245738 0.3355070821 -1.0961507503
[801] 0.9096701387 0.9343824669 -0.7292963676 0.0935680795 -0.9214714620
[806] -1.2169640097 -0.0004269139 3.3232361257 0.4565090582 -0.9933600850
[811] 2.2115017111 0.3296333965 0.9121033943 0.4605937155 -1.5097314232
[816] -0.2792864031 -0.0780261053 0.9293770198 1.9793188106 0.7946419635
[821] 0.9964196650 0.4683186098 -0.6405469838 0.3390313210 0.5907919632
[826] 0.5591667108 -0.8367462055 0.7166699362 -0.4601088877 -1.1374632502
[831] 1.5140403839 1.4578163137 -0.9691587517 -1.2967940816 -1.2730160568
[836] -0.2348633234 0.3372999748 2.3536463206 -0.2579395111 1.1694337793
[841] 0.9689264477 -1.4074859837 2.0076428301 0.6059970961 0.4454152741
[846] 0.6601473190 1.1852762469 1.0476314751 -2.0052641658 -0.4152799083
[851] 0.6768107811 0.7883943984 -0.2534256709 -1.2713486914 -0.9016666693
[856] -0.9094724290 0.9472326735 -0.7657601596 0.6621015323 0.8837176282
[861] 0.6160946025 0.9724531843 -0.3947072440 0.0911752472 0.1538235362
[866] -0.0760096639 0.7894791585 0.1982334740 -1.5294479106 1.4653507324
[871] -1.0511147531 1.5074226763 0.5124224372 0.6815433922 0.5351481503
[876] 0.8984217141 1.1756350304 0.2563228332 0.4182695243 -0.4856156007
[881] 0.6138598060 2.0438838161 -0.0553659216 0.7085852343 -0.6921416458
[886] -0.0031843341 0.2757759790 1.3061246018 1.8925396249 -1.0233122247
[891] 0.9226713096 -0.1431867236 0.4176144558 0.9641666005 0.3126338809
[896] -0.1602993676 0.5592487129 -0.8712203120 1.7828855604 0.9580406423
[901] 1.7787747426 0.5622376974 -0.0546073628 -0.3298531806 0.7126948071
[906] -0.1904715929 -0.0304130447 0.4859526168 0.2183964166 -2.8138725719
[911] -0.5146259790 -0.0028629758 -2.2429701506 -1.0343403313 -0.1726532944
[916] 0.9382250427 2.0023552270 1.4577895139 1.6551450583 -0.4303598034
[921] -0.5970542750 -1.0989064725 -0.4677631386 0.2887607673 -1.2022388250
[926] -0.9089280343 0.0297518274 -0.4937845154 1.7398197302 0.0933517932
[931] -0.2314156103 0.4891114180 0.5352807415 0.7056495389 -1.2987299152
[936] 0.0377396263 0.8930964965 0.9749332113 0.6498870308 -0.1425854823
[941] -0.5512767320 1.3404459214 -0.5178598029 -0.1221323915 0.2635844005
[946] 1.5303607934 1.4323874394 -0.0285541637 -0.3224577745 0.0426622302
[951] 1.0010185024 0.3349582252 1.4395941896 0.6995824455 -0.7403406882
[956] -0.2560683186 0.1363601997 -0.1498333014 -0.4572043915 -0.3165032880
[961] -0.8590543665 0.9892851110 -0.1196541699 0.8411344036 0.0138365932
[966] 0.0485593163 -0.3081305927 -1.0641868817 -0.3778310990 0.5628966410
[971] -0.8917892261 -0.1487478563 -0.0228908345 1.1538592605 0.9726759817
[976] -1.3952401339 0.1609346410 -0.2248287568 1.8758701039 0.6716424041
[981] -0.4542886703 0.9908003553 0.5669183114 -1.5805776525 1.1266489295
[986] -1.0703544398 -0.6409674196 -0.6764726007 -1.4095410834 -0.8150808612
[991] 0.7511286628 2.2711968103 0.6441377107 -0.2725438063 2.4297589286
[996] 0.4252838814 1.2545811617 -0.0469414671 0.6087547070 0.7241390714
>

> max(t)
[1] 3.018436

# (b)

t=rnorm(1000,0,1)
t
hist(t)


Related Solutions

Write code to define a function named mymath. The function has three arguments in the following...
Write code to define a function named mymath. The function has three arguments in the following order: Boolean, Integer, and Integer. It returns an Integer. The function will return a value as follows: 1. If the Boolean variable is True, the function returns the sum of the two integers. 2. If the Boolean is False, then the function returns the value of the first integer - the value of the second Integer.
In a program, write a function that accepts two arguments: a list, and a number n....
In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all of the numbers in the list that are greater than the number n. The program should ask for a list of numbers from the user as well as a value (a, b, c)--> inputs from user. After that, each number in that list should be compared to that value (a or b or...
Write a program that contains a function that takes in three arguments and then calculates the...
Write a program that contains a function that takes in three arguments and then calculates the cost of an order. The output can be either returned to the program or as a side effect. 1. Ask the user via prompt for the products name, price, and quantity that you want to order. 2. Send these values into the function. 3. Check the input to make sure the user entered all of the values. If they did not, or they used...
Write a function named hasNValues which takes an array and an integer n as arguments. It...
Write a function named hasNValues which takes an array and an integer n as arguments. It returns true if all the elements of the array are one of n different values. If you are writing in Java or C#, the function signature is int hasNValues(int[ ] a, int n) If you are writing in C or C++, the function signature is int hasNValues(int a[ ], int n, int len) where len is the length of a Note that an array...
Write a Python function that accepts three arguments: an array, the size of the array, and...
Write a Python function that accepts three arguments: an array, the size of the array, and a number n. Assume that array contains integers. The function should display all integers in the array that are greater than the number n. Test your function.
a splitting function, split_by Write a splitting function named split_by that takes three arguments an equality...
a splitting function, split_by Write a splitting function named split_by that takes three arguments an equality checking function that takes two values and returns a value of type bool, a list of values that are to be separated, and a list of separators values. This function will split the second list into a list of lists. If the checking function indicates that an element of the first list (the second argument) is an element of the second list (the third...
In R: write a function that inputs a vector x and a number n and returns...
In R: write a function that inputs a vector x and a number n and returns the first n elements of x. When n is greater than length(x), your function should just return x. We are not allowed to use any control flow statements
Write a function called alternate that takes two positive integers, n and m, as input arguments...
Write a function called alternate that takes two positive integers, n and m, as input arguments (the function does not have to check the format of the input) and returns one matrix as an output argument. Each element of the n-by-m output matrix for which the sum of its indices is even is 1. All other elements are zero. For example, here is an example run: >> alternate(4,5) ans = 1 0 1 0 1 0 1 0 1 0...
Write python 3 code to define a function that uses three arguments, and returns a result....
Write python 3 code to define a function that uses three arguments, and returns a result. The function returns True if the first argument is more than or equal to the second argument and less than or equal to the third argument, otherwise it returns False. Write a python 3 code for function main, that does the following: creates a variable and assign it the value True. uses a while loop which runs as long as the variable of the...
1) a) Write a MATLAB function called Area1 having two inputs, r and N, and an...
1) a) Write a MATLAB function called Area1 having two inputs, r and N, and an output, A1. The output A1 should be the area under a curve, f(x), for x starting at x_start and ending at x_end. The input r should be a vector (array) having x_start and x_end as its two elements. The input N should be an integer equal to the number of equallength sub-intervals in which the interval from x_start to x_end should be divided. Here,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT