{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":44477,"title":"Find left eigenvector of row stochastic matrix","description":"Find the left eigenvector of the given stochastic matrix P that has eigenvalue 1. \r\nNormalize the vector so the sum of the entries is 1 (called a probability vector). \r\nThe output vector should be a row vector.\r\n\r\n(This can be thought of as a stationary distribution for a Markov chain.\r\n\u003chttps://en.wikipedia.org/wiki/Markov_chain#Finite_state_space\u003e )\r\n\r\nE.g:\r\nFor P = [ .7 .3 ;\r\n          .6 .4 ]\r\nreturn [ .6666666 .3333333 ] (or any vector close to this would be accepted).\r\n\r\nThe left eigenvector v of a matrix P (with eigenvalue 1) is a row vector such that v=v*P. ","description_html":"\u003cp\u003eFind the left eigenvector of the given stochastic matrix P that has eigenvalue 1. \r\nNormalize the vector so the sum of the entries is 1 (called a probability vector). \r\nThe output vector should be a row vector.\u003c/p\u003e\u003cp\u003e(This can be thought of as a stationary distribution for a Markov chain. \u003ca href = \"https://en.wikipedia.org/wiki/Markov_chain#Finite_state_space\"\u003ehttps://en.wikipedia.org/wiki/Markov_chain#Finite_state_space\u003c/a\u003e )\u003c/p\u003e\u003cp\u003eE.g:\r\nFor P = [ .7 .3 ;\r\n          .6 .4 ]\r\nreturn [ .6666666 .3333333 ] (or any vector close to this would be accepted).\u003c/p\u003e\u003cp\u003eThe left eigenvector v of a matrix P (with eigenvalue 1) is a row vector such that v=v*P.\u003c/p\u003e","function_template":"function v = find_left_evector(P)\r\n  v = [ .2 .3 .5];\r\nend","test_suite":"%%\r\nP = [  0.536668396674091   0.463331603325909;\r\n   0.628171641615730   0.371828358384270]\r\npc = [  0.575510558055411   0.424489441944469]\r\nassert(  sum(abs(pc - find_left_evector(P))) \u003c .001 )\r\n\r\n%%\r\nP =[   0.490126287130221   0.063810857836059   0.446062855033720;\r\n   0.351100472099344   0.522156819868217   0.126742708032439;\r\n   0.016119408853126   0.459671543012232   0.524209048134642]\r\npc =  [0.270232959896393   0.376204159405191   0.353562880698251]\r\nassert(  sum(abs(pc - find_left_evector(P))) \u003c .001 )\r\n\r\n%%\r\nP= [   0.000295973934872   0.298979544879362   0.282216466268297   0.418508014917470;\r\n   0.305614143800419   0.169335098209289   0.318119927666875   0.206930830323418;\r\n   0.274040969162178   0.358495094643379   0.257083476284641   0.110380459909802;\r\n   0.362700492263105   0.083477678435433   0.309658548481881   0.244163280819581]\r\npc = [   0.237529575372038   0.234524560057871   0.289883972779590   0.238061891790800]\r\nassert(  sum(abs(pc - find_left_evector(P))) \u003c .001 )\r\n\r\n%%\r\nP =[   0.206900154678670   0.148378489932199   0.322150635982830   0.314216412936451   0.008354306469849;\r\n   0.260256141508665   0.099217372921749   0.160593109350477   0.261083704996893   0.218849671222215;\r\n   0.239143386227262   0.208748199654121   0.157570271848609   0.243411982213855   0.151126160056153;\r\n   0.278091600172443   0.098346886570860   0.258034757795764   0.264131640312126   0.101395115148807;\r\n   0.332707101127035   0.028439807716601   0.229818689497991   0.282967894831867   0.126066506826505]\r\npc = [  0.254374450013656   0.129637934241022   0.235068662146163   0.273627230656508   0.107291722942842]\r\nassert(  sum(abs(pc - find_left_evector(P))) \u003c .001 )\r\n\r\n%% \r\nP = [   0.132301071463971   0.118964494040826   0.133724887078453   0.164995061775188   0.040846954071962   0.145500258220330   0.063426378618235   0.129644361564668   0.066729252864125   0.003867280302243;\r\n   0.132078324816755   0.158842681592186   0.021345097287269   0.116096463338978   0.011399564178502   0.140138687399582   0.177066809582189   0.065776052252923   0.015539976826641   0.161716342724976;\r\n   0.017067043037843   0.083233444933711   0.084600955134299   0.150272784632142   0.123640429188190   0.137325974960960   0.036120936255903   0.135601262483591   0.103142500899762   0.128994668473599;\r\n   0.127071623799322   0.131013361691360   0.060749137485579   0.030485605165969   0.125140409826980   0.094272001681351   0.121644411243946   0.136891396463886   0.033674609302846   0.139057443338763;\r\n   0.084699633418611   0.028081492787019   0.099909358534447   0.168407595038166   0.130764931483391   0.116220306891560   0.110612661554048   0.104402758049448   0.008236859479167   0.148664402764143;\r\n   0.037733369184740   0.169572983103210   0.070941210905428   0.141330441010770   0.114190951485877   0.169117213270117   0.068871861233898   0.031453791309126   0.128616891142078   0.068171287354757;\r\n   0.021608820428507   0.118635979900457   0.091045405806744   0.126644005048004   0.091912863890716   0.097377838242980   0.031186928136198   0.209989895433764   0.076205987507149   0.135392275605482;\r\n   0.200801721742751   0.165730897943703   0.044066996479387   0.107288300031138   0.095274563967673   0.014633627838425   0.006128344875136   0.064690108023551   0.161069824250084   0.140315614848152;\r\n   0.037498791878979   0.007834244109932   0.054720922238198   0.055198093789809   0.174871800390143   0.185715803502670   0.090230412306462   0.198107071552124   0.082250330729007   0.113572529502674;\r\n   0.040849998758864   0.202090814652096   0.005128610576370   0.187791319910819   0.079274530709314   0.157633265466675   0.045977261982389   0.055884488572257   0.156673705328071   0.068696004043146]\r\npc = [ 0.088341588996646   0.125827616221029   0.062738581066497   0.123052908662097   0.095658900658645   0.125218780388122   0.080036509221240   0.105209734515629   0.082635110452906   0.111280269817457]\r\nassert(  sum(abs(pc - find_left_evector(P))) \u003c .001 )\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":65480,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":15,"test_suite_updated_at":"2018-01-03T20:26:54.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-03T20:25:00.000Z","updated_at":"2026-03-11T09:48:37.000Z","published_at":"2018-01-03T20:26:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the left eigenvector of the given stochastic matrix P that has eigenvalue 1. Normalize the vector so the sum of the entries is 1 (called a probability vector). The output vector should be a row vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(This can be thought of as a stationary distribution for a Markov chain.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Markov_chain#Finite_state_space\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://en.wikipedia.org/wiki/Markov_chain#Finite_state_space\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt; )\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eE.g: For P = [ .7 .3 ; .6 .4 ] return [ .6666666 .3333333 ] (or any vector close to this would be accepted).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe left eigenvector v of a matrix P (with eigenvalue 1) is a row vector such that v=v*P.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44315,"title":"Predicting life and death of a memory-less light bulb","description":"*\u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161* \r\n\r\nYou have a light bulb that can fail any moment according to the exponential probability distribution. \r\n\r\nAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant. \r\n\r\nNotice that this probability is very small if N is very large. \r\n\r\nNow suppose, the bulb has already survived N hours. \r\n\r\nPlease calculate the probability of its surviving M more hours.\r\n","description_html":"\u003cp\u003e\u003cb\u003e\u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161\u003c/b\u003e\u003c/p\u003e\u003cp\u003eYou have a light bulb that can fail any moment according to the exponential probability distribution.\u003c/p\u003e\u003cp\u003eAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant.\u003c/p\u003e\u003cp\u003eNotice that this probability is very small if N is very large.\u003c/p\u003e\u003cp\u003eNow suppose, the bulb has already survived N hours.\u003c/p\u003e\u003cp\u003ePlease calculate the probability of its surviving M more hours.\u003c/p\u003e","function_template":"function hope = fate(N,P,M)\r\n  hope=exp(-(N+M)*P);\r\nend","test_suite":"%%\r\nN = 1;\r\nP=1;\r\nM=0;\r\nhope_correct = 1;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN = 1;\r\nP=0;\r\nM=1;\r\nhope_correct = 1;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=1;\r\nP=1;\r\nM=1;\r\nhope_correct = 0.3679;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=2;\r\nP=1;\r\nM=1;\r\nhope_correct = 0.3679;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=2;\r\nP=1;\r\nM=2;\r\nhope_correct = 0.1353;\r\nassert(fate(N,P,M)\u003chope_correct*1.1)\r\n%%\r\nN=2;\r\nP=2;\r\nM=2;\r\nhope_correct = 0.0183;\r\nassert(fate(N,P,M)\u003chope_correct*1.1)\r\n%%","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":336,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-12T02:53:45.000Z","updated_at":"2026-03-25T02:55:11.000Z","published_at":"2017-10-16T01:45:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have a light bulb that can fail any moment according to the exponential probability distribution.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNotice that this probability is very small if N is very large.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNow suppose, the bulb has already survived N hours.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePlease calculate the probability of its surviving M more hours.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":44477,"title":"Find left eigenvector of row stochastic matrix","description":"Find the left eigenvector of the given stochastic matrix P that has eigenvalue 1. \r\nNormalize the vector so the sum of the entries is 1 (called a probability vector). \r\nThe output vector should be a row vector.\r\n\r\n(This can be thought of as a stationary distribution for a Markov chain.\r\n\u003chttps://en.wikipedia.org/wiki/Markov_chain#Finite_state_space\u003e )\r\n\r\nE.g:\r\nFor P = [ .7 .3 ;\r\n          .6 .4 ]\r\nreturn [ .6666666 .3333333 ] (or any vector close to this would be accepted).\r\n\r\nThe left eigenvector v of a matrix P (with eigenvalue 1) is a row vector such that v=v*P. ","description_html":"\u003cp\u003eFind the left eigenvector of the given stochastic matrix P that has eigenvalue 1. \r\nNormalize the vector so the sum of the entries is 1 (called a probability vector). \r\nThe output vector should be a row vector.\u003c/p\u003e\u003cp\u003e(This can be thought of as a stationary distribution for a Markov chain. \u003ca href = \"https://en.wikipedia.org/wiki/Markov_chain#Finite_state_space\"\u003ehttps://en.wikipedia.org/wiki/Markov_chain#Finite_state_space\u003c/a\u003e )\u003c/p\u003e\u003cp\u003eE.g:\r\nFor P = [ .7 .3 ;\r\n          .6 .4 ]\r\nreturn [ .6666666 .3333333 ] (or any vector close to this would be accepted).\u003c/p\u003e\u003cp\u003eThe left eigenvector v of a matrix P (with eigenvalue 1) is a row vector such that v=v*P.\u003c/p\u003e","function_template":"function v = find_left_evector(P)\r\n  v = [ .2 .3 .5];\r\nend","test_suite":"%%\r\nP = [  0.536668396674091   0.463331603325909;\r\n   0.628171641615730   0.371828358384270]\r\npc = [  0.575510558055411   0.424489441944469]\r\nassert(  sum(abs(pc - find_left_evector(P))) \u003c .001 )\r\n\r\n%%\r\nP =[   0.490126287130221   0.063810857836059   0.446062855033720;\r\n   0.351100472099344   0.522156819868217   0.126742708032439;\r\n   0.016119408853126   0.459671543012232   0.524209048134642]\r\npc =  [0.270232959896393   0.376204159405191   0.353562880698251]\r\nassert(  sum(abs(pc - find_left_evector(P))) \u003c .001 )\r\n\r\n%%\r\nP= [   0.000295973934872   0.298979544879362   0.282216466268297   0.418508014917470;\r\n   0.305614143800419   0.169335098209289   0.318119927666875   0.206930830323418;\r\n   0.274040969162178   0.358495094643379   0.257083476284641   0.110380459909802;\r\n   0.362700492263105   0.083477678435433   0.309658548481881   0.244163280819581]\r\npc = [   0.237529575372038   0.234524560057871   0.289883972779590   0.238061891790800]\r\nassert(  sum(abs(pc - find_left_evector(P))) \u003c .001 )\r\n\r\n%%\r\nP =[   0.206900154678670   0.148378489932199   0.322150635982830   0.314216412936451   0.008354306469849;\r\n   0.260256141508665   0.099217372921749   0.160593109350477   0.261083704996893   0.218849671222215;\r\n   0.239143386227262   0.208748199654121   0.157570271848609   0.243411982213855   0.151126160056153;\r\n   0.278091600172443   0.098346886570860   0.258034757795764   0.264131640312126   0.101395115148807;\r\n   0.332707101127035   0.028439807716601   0.229818689497991   0.282967894831867   0.126066506826505]\r\npc = [  0.254374450013656   0.129637934241022   0.235068662146163   0.273627230656508   0.107291722942842]\r\nassert(  sum(abs(pc - find_left_evector(P))) \u003c .001 )\r\n\r\n%% \r\nP = [   0.132301071463971   0.118964494040826   0.133724887078453   0.164995061775188   0.040846954071962   0.145500258220330   0.063426378618235   0.129644361564668   0.066729252864125   0.003867280302243;\r\n   0.132078324816755   0.158842681592186   0.021345097287269   0.116096463338978   0.011399564178502   0.140138687399582   0.177066809582189   0.065776052252923   0.015539976826641   0.161716342724976;\r\n   0.017067043037843   0.083233444933711   0.084600955134299   0.150272784632142   0.123640429188190   0.137325974960960   0.036120936255903   0.135601262483591   0.103142500899762   0.128994668473599;\r\n   0.127071623799322   0.131013361691360   0.060749137485579   0.030485605165969   0.125140409826980   0.094272001681351   0.121644411243946   0.136891396463886   0.033674609302846   0.139057443338763;\r\n   0.084699633418611   0.028081492787019   0.099909358534447   0.168407595038166   0.130764931483391   0.116220306891560   0.110612661554048   0.104402758049448   0.008236859479167   0.148664402764143;\r\n   0.037733369184740   0.169572983103210   0.070941210905428   0.141330441010770   0.114190951485877   0.169117213270117   0.068871861233898   0.031453791309126   0.128616891142078   0.068171287354757;\r\n   0.021608820428507   0.118635979900457   0.091045405806744   0.126644005048004   0.091912863890716   0.097377838242980   0.031186928136198   0.209989895433764   0.076205987507149   0.135392275605482;\r\n   0.200801721742751   0.165730897943703   0.044066996479387   0.107288300031138   0.095274563967673   0.014633627838425   0.006128344875136   0.064690108023551   0.161069824250084   0.140315614848152;\r\n   0.037498791878979   0.007834244109932   0.054720922238198   0.055198093789809   0.174871800390143   0.185715803502670   0.090230412306462   0.198107071552124   0.082250330729007   0.113572529502674;\r\n   0.040849998758864   0.202090814652096   0.005128610576370   0.187791319910819   0.079274530709314   0.157633265466675   0.045977261982389   0.055884488572257   0.156673705328071   0.068696004043146]\r\npc = [ 0.088341588996646   0.125827616221029   0.062738581066497   0.123052908662097   0.095658900658645   0.125218780388122   0.080036509221240   0.105209734515629   0.082635110452906   0.111280269817457]\r\nassert(  sum(abs(pc - find_left_evector(P))) \u003c .001 )\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":65480,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":15,"test_suite_updated_at":"2018-01-03T20:26:54.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-03T20:25:00.000Z","updated_at":"2026-03-11T09:48:37.000Z","published_at":"2018-01-03T20:26:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the left eigenvector of the given stochastic matrix P that has eigenvalue 1. Normalize the vector so the sum of the entries is 1 (called a probability vector). The output vector should be a row vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(This can be thought of as a stationary distribution for a Markov chain.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Markov_chain#Finite_state_space\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://en.wikipedia.org/wiki/Markov_chain#Finite_state_space\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt; )\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eE.g: For P = [ .7 .3 ; .6 .4 ] return [ .6666666 .3333333 ] (or any vector close to this would be accepted).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe left eigenvector v of a matrix P (with eigenvalue 1) is a row vector such that v=v*P.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44315,"title":"Predicting life and death of a memory-less light bulb","description":"*\u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161* \r\n\r\nYou have a light bulb that can fail any moment according to the exponential probability distribution. \r\n\r\nAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant. \r\n\r\nNotice that this probability is very small if N is very large. \r\n\r\nNow suppose, the bulb has already survived N hours. \r\n\r\nPlease calculate the probability of its surviving M more hours.\r\n","description_html":"\u003cp\u003e\u003cb\u003e\u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161\u003c/b\u003e\u003c/p\u003e\u003cp\u003eYou have a light bulb that can fail any moment according to the exponential probability distribution.\u003c/p\u003e\u003cp\u003eAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant.\u003c/p\u003e\u003cp\u003eNotice that this probability is very small if N is very large.\u003c/p\u003e\u003cp\u003eNow suppose, the bulb has already survived N hours.\u003c/p\u003e\u003cp\u003ePlease calculate the probability of its surviving M more hours.\u003c/p\u003e","function_template":"function hope = fate(N,P,M)\r\n  hope=exp(-(N+M)*P);\r\nend","test_suite":"%%\r\nN = 1;\r\nP=1;\r\nM=0;\r\nhope_correct = 1;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN = 1;\r\nP=0;\r\nM=1;\r\nhope_correct = 1;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=1;\r\nP=1;\r\nM=1;\r\nhope_correct = 0.3679;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=2;\r\nP=1;\r\nM=1;\r\nhope_correct = 0.3679;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=2;\r\nP=1;\r\nM=2;\r\nhope_correct = 0.1353;\r\nassert(fate(N,P,M)\u003chope_correct*1.1)\r\n%%\r\nN=2;\r\nP=2;\r\nM=2;\r\nhope_correct = 0.0183;\r\nassert(fate(N,P,M)\u003chope_correct*1.1)\r\n%%","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":336,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-12T02:53:45.000Z","updated_at":"2026-03-25T02:55:11.000Z","published_at":"2017-10-16T01:45:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have a light bulb that can fail any moment according to the exponential probability distribution.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNotice that this probability is very small if N is very large.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNow suppose, the bulb has already survived N hours.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePlease calculate the probability of its surviving M more hours.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"stochastic\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"stochastic\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"stochastic\"","","\"","stochastic","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f74d908d5e0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f74d908d540\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f74d908c780\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f74d908d860\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f74d908d7c0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f74d908d720\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f74d908d680\u003e":"tag:\"stochastic\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f74d908d680\u003e":"tag:\"stochastic\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"stochastic\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"stochastic\"","","\"","stochastic","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f74d908d5e0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f74d908d540\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f74d908c780\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f74d908d860\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f74d908d7c0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f74d908d720\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f74d908d680\u003e":"tag:\"stochastic\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f74d908d680\u003e":"tag:\"stochastic\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":44477,"difficulty_rating":"easy-medium"},{"id":44315,"difficulty_rating":"easy-medium"}]}}