{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-06T14:01:22.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":"2026-04-06T00: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":2376,"title":"Find the Nth Root of a Given Number","description":"Find the Nth root of a given number x.\r\n\r\nExamples\r\n\r\n x = 4096\r\n n = 4\r\n y = 8\r\n\r\n x = 625\r\n n = 5\r\n y = 3.6239","description_html":"\u003cp\u003eFind the Nth root of a given number x.\u003c/p\u003e\u003cp\u003eExamples\u003c/p\u003e\u003cpre\u003e x = 4096\r\n n = 4\r\n y = 8\u003c/pre\u003e\u003cpre\u003e x = 625\r\n n = 5\r\n y = 3.6239\u003c/pre\u003e","function_template":"function y = nth_root(x,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 4096;n=4;\r\ny_correct = 8;\r\n\r\nassert(isequal(nth_root(x,n),y_correct))\r\n\r\n%%\r\nx = 256;n=4;\r\ny_correct = 4;\r\n\r\nassert(isequal(nth_root(x,n),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":22553,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":364,"test_suite_updated_at":"2014-08-26T16:11:50.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2014-06-18T15:50:59.000Z","updated_at":"2026-03-23T11:17:06.000Z","published_at":"2014-06-18T15:52:17.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 Nth root of a given number x.\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\u003eExamples\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = 4096\\n n = 4\\n y = 8\\n\\n x = 625\\n n = 5\\n y = 3.6239]]\u003e\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":43625,"title":"Calculate roots of polynomial given as vector array.","description":"Calculate roots of polynomial given as vector array.\r\n\r\nExample\r\n\r\nx=[1     2     0     5     0     3]\r\n\r\nresult=[-2.7267  ;        \r\n   0.4784 + 1.0983i;\r\n   0.4784 - 1.0983i;\r\n  -0.1150 + 0.8680i;\r\n  -0.1150 - 0.8680i]","description_html":"\u003cp\u003eCalculate roots of polynomial given as vector array.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cp\u003ex=[1     2     0     5     0     3]\u003c/p\u003e\u003cp\u003eresult=[-2.7267  ;        \r\n   0.4784 + 1.0983i;\r\n   0.4784 - 1.0983i;\r\n  -0.1150 + 0.8680i;\r\n  -0.1150 - 0.8680i]\u003c/p\u003e","function_template":"function y = PolRoot(x)\r\n   y=x\r\nend","test_suite":"%%\r\nx = [1     2     0     5     0     3];\r\ny_correct = [-2.7267 + 0.0000i ;0.4784 + 1.0983i ;0.4784 - 1.0983i ;-0.1150 + 0.8680i ;-0.1150 - 0.8680i];\r\ny=PolRoot(x)\r\nassert(abs(y(1)-y_correct(1))\u003c10^(-4))\r\nassert(abs(y(2)-y_correct(2))\u003c10^(-4))\r\nassert(abs(y(3)-y_correct(3))\u003c10^(-4))\r\nassert(abs(y(4)-y_correct(4))\u003c10^(-4))\r\n%%\r\nx = [3     2     5     1     0     2];\r\ny_correct = [-0.3205 + 1.2968i; -0.3205 - 1.2968i; -0.7915 + 0.0000i; 0.3829 + 0.5704i; 0.3829 - 0.5704i];\r\ny=PolRoot(x)\r\nassert(abs(y(1)-y_correct(1))\u003c10^(-4))\r\nassert(abs(y(2)-y_correct(2))\u003c10^(-4))\r\nassert(abs(y(3)-y_correct(3))\u003c10^(-4))\r\nassert(abs(y(4)-y_correct(4))\u003c10^(-4))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":90467,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":90,"test_suite_updated_at":"2016-10-25T18:15:54.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-25T18:11:06.000Z","updated_at":"2026-02-25T20:52:46.000Z","published_at":"2016-10-25T18:15: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eCalculate roots of polynomial given as vector array.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex=[1 2 0 5 0 3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eresult=[-2.7267 ; 0.4784 + 1.0983i; 0.4784 - 1.0983i; -0.1150 + 0.8680i; -0.1150 - 0.8680i]\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":43130,"title":"Nth root","description":"Nth root of a number x","description_html":"\u003cp\u003eNth root of a number x\u003c/p\u003e","function_template":"function y = nroot(n,x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\nn=1;\r\ny_correct = 1;\r\nassert((nroot(n,x)-y_correct)\u003c0.001)\r\n\r\n%%\r\nx = 1;\r\nn=2;\r\ny_correct = 1;\r\nassert((nroot(n,x)-y_correct)\u003c0.001)\r\n\r\n\r\n%%\r\nx = 1;\r\nn=2;\r\ny_correct = 1;\r\nassert((nroot(n,x)-y_correct)\u003c0.001)\r\n\r\n\r\n%%\r\nx = 10;\r\nn=2;\r\ny_correct = 3.1623;\r\nassert((nroot(n,x)-y_correct)\u003c0.001)\r\n\r\n%%\r\nx = 10;\r\nn=10;\r\ny_correct = 1.2589;\r\nassert((nroot(n,x)-y_correct)\u003c0.001)\r\n\r\n%%\r\nx = 100;\r\nn=100;\r\ny_correct = 1.0471;\r\nassert((nroot(n,x)-y_correct)\u003c0.001)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":91311,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":138,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-06T17:19:12.000Z","updated_at":"2026-02-17T09:14:29.000Z","published_at":"2016-10-06T17:19:12.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eNth root of a number x\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":43021,"title":"How many figures currently exist?","description":"Return the number of figures that exist at any given time.","description_html":"\u003cp\u003eReturn the number of figures that exist at any given time.\u003c/p\u003e","function_template":"function y = numfig()\r\n    y = 0;\r\nend","test_suite":"%%\r\nassert(isequal(numfig(),0))\r\n\r\n%%\r\nclose all;\r\nfigure;\r\nassert(isequal(numfig(),1))\r\n\r\n%%\r\nclose all;\r\nfigure;\r\nfigure;\r\nassert(isequal(numfig(),2))\r\n\r\n%%\r\nclose all;\r\nfigure;\r\nfigure; plot(1,1);\r\nfigure; imagesc(magic(5));\r\nassert(isequal(numfig(),3))\r\n\r\n%%\r\nclose all;\r\nn = randi(20);\r\nfor ii=1:n\r\n    figure;\r\nend\r\nassert(isequal(numfig(),n))\r\n\r\n%%\r\nclose all;\r\nassert(isequal(numfig(),0))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":37,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-04T14:56:58.000Z","updated_at":"2026-03-02T15:03:36.000Z","published_at":"2016-10-04T14:56:58.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eReturn the number of figures that exist at any given time.\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":44659,"title":"Nth root of a number","description":"Given an input and a number N, find the Nth root of the number(s)","description_html":"\u003cp\u003eGiven an input and a number N, find the Nth root of the number(s)\u003c/p\u003e","function_template":"function y = rootN(a,N)\r\n  y = x;\r\nend","test_suite":"%%\r\na = 1;\r\nN = 100\r\ny_correct = 1;\r\nassert(isequal(rootN(a,N),y_correct))\r\n\r\n%%\r\na = [1 64 216];\r\nN = 3\r\ny_correct = [1    4    6];\r\nassert(isequal(rootN(a,N),y_correct))\r\n\r\n%%\r\na = 1/100;\r\nN = 2\r\ny_correct = 1/10;\r\nassert(isequal(rootN(a,N),y_correct))\r\n\r\n%%\r\na = 826^10;\r\nN = 10\r\ny_correct = 826;\r\nassert(isequal(rootN(a,N),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":59,"test_suite_updated_at":"2018-05-29T13:54:08.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-29T13:48:03.000Z","updated_at":"2026-02-20T14:32:58.000Z","published_at":"2018-05-29T13:48:03.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eGiven an input and a number N, find the Nth root of the number(s)\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":549,"title":"root?","description":"* Given a function 'foo', and a position 'there', find the root near 'there'.\r\n* For example: If foo=@sin, and there=3.1, then rootof(foo, there) \u003e\u003e 3.1416","description_html":"\u003cul\u003e\u003cli\u003eGiven a function 'foo', and a position 'there', find the root near 'there'.\u003c/li\u003e\u003cli\u003eFor example: If foo=@sin, and there=3.1, then rootof(foo, there) \u003e\u003e 3.1416\u003c/li\u003e\u003c/ul\u003e","function_template":"function  root = rootof(foo, there)\r\n  root=pi;\r\nend","test_suite":"%%\r\nassert(abs(rootof(@sin,3)-pi)\u003c100*eps)\r\n\r\n%%\r\nassert(abs(rootof(@cos,1.5)-pi/2)\u003c100*eps)\r\n\r\n%%\r\nassert(abs(rootof(@tan,0.05)-0)\u003c100*eps)\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":108,"test_suite_updated_at":"2012-04-02T06:33:55.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-02T06:33:55.000Z","updated_at":"2026-03-24T11:47:08.000Z","published_at":"2012-04-02T06:33:55.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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a function 'foo', and a position 'there', find the root near 'there'.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example: If foo=@sin, and there=3.1, then rootof(foo, there) \u0026gt;\u0026gt; 3.1416\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":42917,"title":"Nth roots of unity","description":"First, find the n nth roots of unity.\r\neg if n = 6, find the n distinct (complex) numbers such that n^6 = 1.\r\n\r\n\u003chttps://en.wikipedia.org/wiki/Root_of_unity\u003e\r\n\r\nSecond, raise each root to the power pi (.^pi).\r\n\r\nThird, sum the resulting numbers and use that as the output. \r\n","description_html":"\u003cp\u003eFirst, find the n nth roots of unity.\r\neg if n = 6, find the n distinct (complex) numbers such that n^6 = 1.\u003c/p\u003e\u003cp\u003e\u003ca href = \"https://en.wikipedia.org/wiki/Root_of_unity\"\u003ehttps://en.wikipedia.org/wiki/Root_of_unity\u003c/a\u003e\u003c/p\u003e\u003cp\u003eSecond, raise each root to the power pi (.^pi).\u003c/p\u003e\u003cp\u003eThird, sum the resulting numbers and use that as the output.\u003c/p\u003e","function_template":"function y = your_fcn_name(n)\r\n  y = 0;\r\nend","test_suite":"%%\r\nn = 5;\r\ny_correct =  -0.467800202134647;\r\nassert( abs(your_fcn_name(n)-y_correct) \u003c .0001)\r\n\r\n%%\r\nn = 50;\r\ny_correct = -2.151544927902936 - 0.430301217000093i\r\nassert( abs(your_fcn_name(n)-y_correct) \u003c .0001)\r\n\r\n%%\r\nn = 7;\r\ny_correct =   -0.435928596902380\r\nassert( abs(your_fcn_name(n)-y_correct) \u003c .0001)\r\n\r\n\r\n%%\r\nn = 70;\r\ny_correct =   -3.031653804728051 - 0.430301217000095i\r\nassert( abs(your_fcn_name(n)-y_correct) \u003c .0001)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":65480,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":67,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-08-01T00:25:42.000Z","updated_at":"2026-02-24T14:03:00.000Z","published_at":"2016-08-01T00:25:42.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\u003eFirst, find the n nth roots of unity. eg if n = 6, find the n distinct (complex) numbers such that n^6 = 1.\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:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Root_of_unity\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://en.wikipedia.org/wiki/Root_of_unity\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\u003eSecond, raise each root to the power pi (.^pi).\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\u003eThird, sum the resulting numbers and use that as the output.\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":2055,"title":"Create numeric palindromes and their square roots","description":"Given a number n (1\u003c=n\u003c=9), return a left justified numeric matrix p with all the palindromes of the form 1 to n and back to 1. Use 0 for empty values. Similarly return the square root matrix in the same form.\r\n\r\nExample\r\n\r\n n=2;\r\n\r\n p=[1 0 0; 1 2 1];\r\n\r\n r=[1 0 0; 1 1 0];","description_html":"\u003cp\u003eGiven a number n (1\u0026lt;=n\u0026lt;=9), return a left justified numeric matrix p with all the palindromes of the form 1 to n and back to 1. Use 0 for empty values. Similarly return the square root matrix in the same form.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e n=2;\u003c/pre\u003e\u003cpre\u003e p=[1 0 0; 1 2 1];\u003c/pre\u003e\u003cpre\u003e r=[1 0 0; 1 1 0];\u003c/pre\u003e","function_template":"function [p,r] = palinroot(n)\r\np=[1 0 0; 1 2 1];\r\nr=sqrt(p);\r\nend","test_suite":"%%\r\nn=3;\r\n[p,r]=palinroot(n);\r\ny_correct=[1 0 0 0 0; 1 2 1 0 0; 1 2 3 2 1];\r\nz_correct=[1 0 0; 1 1 0; 1 1 1];\r\nassert(isequal(p,y_correct))\r\nassert(isequal(r,z_correct))\r\n\r\n\r\n%%\r\nn=9;\r\n[p,r]=palinroot(n);\r\n\r\nrr=1;\r\nfor s1=2:n\r\n    rr(s1)=rr(s1-1)*10+1;\r\nend\r\nrr=num2str(rr','%.0f');\r\nz_correct=tril(fliplr(rr)-'0');\r\n\r\npp=zeros(n,n*2-1);\r\nfor s=1:n\r\n    p1=1:s;\r\n    p2=fliplr(p1);\r\n    st=deal([p1,p2(2:end)]);\r\n    pp(s,1:numel(st))=st;\r\nend\r\ny_correct=pp;\r\n\r\nassert(isequal(p,y_correct))\r\nassert(isequal(r,z_correct))\r\n\r\n%%\r\nn=5;\r\n[p,r]=palinroot(n);\r\n\r\nrr=1;\r\nfor s1=2:n\r\n    rr(s1)=rr(s1-1)*10+1;\r\nend\r\nrr=num2str(rr','%.0f');\r\nz_correct=tril(fliplr(rr)-'0');\r\n\r\npp=zeros(n,n*2-1);\r\nfor s=1:n\r\n    p1=1:s;\r\n    p2=fliplr(p1);\r\n    st=deal([p1,p2(2:end)]);\r\n    pp(s,1:numel(st))=st;\r\nend\r\ny_correct=pp;\r\n\r\nassert(isequal(p,y_correct))\r\nassert(isequal(r,z_correct))\r\n\r\n%%\r\nn=7;\r\n[p,r]=palinroot(n);\r\n\r\nrr=1;\r\nfor s1=2:n\r\n    rr(s1)=rr(s1-1)*10+1;\r\nend\r\nrr=num2str(rr','%.0f');\r\nz_correct=tril(fliplr(rr)-'0');\r\n\r\npp=zeros(n,n*2-1);\r\nfor s=1:n\r\n    p1=1:s;\r\n    p2=fliplr(p1);\r\n    st=deal([p1,p2(2:end)]);\r\n    pp(s,1:numel(st))=st;\r\nend\r\ny_correct=pp;\r\n\r\nassert(isequal(p,y_correct))\r\nassert(isequal(r,z_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":17471,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":"2013-12-15T11:05:10.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-12-15T09:35:00.000Z","updated_at":"2026-01-02T17:16:23.000Z","published_at":"2013-12-15T10:36:26.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\u003eGiven a number n (1\u0026lt;=n\u0026lt;=9), return a left justified numeric matrix p with all the palindromes of the form 1 to n and back to 1. Use 0 for empty values. Similarly return the square root matrix in the same form.\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\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ n=2;\\n\\n p=[1 0 0; 1 2 1];\\n\\n r=[1 0 0; 1 1 0];]]\u003e\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":44344,"title":"The 5th Root","description":"Write a function to find the 5th root of a number.\r\n\r\nIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.","description_html":"\u003cp\u003eWrite a function to find the 5th root of a number.\u003c/p\u003e\u003cp\u003eIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.\u003c/p\u003e","function_template":"function f = fifth_root(n)\r\n f = n^(1/5)\r\nend","test_suite":"%%\r\nfiletext = fileread('fifth_root.m');\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'power')),'power() forbidden')\r\nassert(isempty(strfind(filetext, 'mpower')),'mpower() forbidden')\r\nassert(isempty(strfind(filetext, 'realpow')),'realpow() forbidden')\r\nassert(isempty(strfind(filetext, 'nthroot')),'nthroot() forbidden')\r\nassert(isempty(strfind(filetext, 'roots')),'roots() forbidden')\r\n\r\n%%\r\nn = 1/9765625;\r\nassert(abs(fifth_root(n)-1/25)\u003c1e-5)\r\n\r\n%%\r\nn = 1/5555;\r\nassert(abs(fifth_root(n)-0.178263811215444)\u003c1e-5)\r\n\r\n%%\r\nn = 1/3125;\r\nassert(abs(fifth_root(n)-1/5)\u003c1e-5)\r\n\r\n%%\r\nn = 1/125;\r\nassert(abs(fifth_root(n)-0.380730787743176)\u003c1e-5)\r\n\r\n%%\r\nn = 1/5;\r\nassert(abs(fifth_root(n)-0.724779663677696)\u003c1e-5)\r\n\r\n%%\r\nn = 1;\r\nassert(abs(fifth_root(n)-1)\u003c1e-5)\r\n\r\n%%\r\nn = 5;\r\nassert(abs(fifth_root(n)-1.37972966146121)\u003c1e-5)\r\n\r\n%%\r\nn = 25;\r\nassert(abs(fifth_root(n)-1.90365393871588)\u003c1e-5)\r\n\r\n%%\r\nn = 50;\r\nassert(abs(fifth_root(n)-2.18672414788656)\u003c1e-5)\r\n\r\n%%\r\nn = 500;\r\nassert(abs(fifth_root(n)-3.46572421577573)\u003c1e-5)\r\n\r\n%%\r\nn = 3125;\r\nassert(abs(fifth_root(n)-5)\u003c1e-5)\r\n\r\n%%\r\nn = 759375;\r\nassert(abs(fifth_root(n)-15)\u003c1e-5)\r\n\r\n%%\r\nn = 9765625;\r\nassert(abs(fifth_root(n)-25)\u003c1e-5)\r\n\r\n%%\r\nn = 312500000;\r\nassert(abs(fifth_root(n)-50)\u003c1e-5)\r\n\r\n%%\r\nn = 75937500000;\r\nassert(abs(fifth_root(n)-150)\u003c1e-5)\r\n\r\n%%\r\nn = 31250000000000;\r\nassert(abs(fifth_root(n)-500)\u003c1e-5)\r\n\r\n%%\r\nn = 52658067346875;\r\nassert(abs(fifth_root(n)-555)\u003c1e-5)","published":true,"deleted":false,"likes_count":13,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":559,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-22T16:03:40.000Z","updated_at":"2026-02-03T09:23:18.000Z","published_at":"2017-10-16T01:50:59.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eWrite a function to find the 5th root of a number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.\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":2376,"title":"Find the Nth Root of a Given Number","description":"Find the Nth root of a given number x.\r\n\r\nExamples\r\n\r\n x = 4096\r\n n = 4\r\n y = 8\r\n\r\n x = 625\r\n n = 5\r\n y = 3.6239","description_html":"\u003cp\u003eFind the Nth root of a given number x.\u003c/p\u003e\u003cp\u003eExamples\u003c/p\u003e\u003cpre\u003e x = 4096\r\n n = 4\r\n y = 8\u003c/pre\u003e\u003cpre\u003e x = 625\r\n n = 5\r\n y = 3.6239\u003c/pre\u003e","function_template":"function y = nth_root(x,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 4096;n=4;\r\ny_correct = 8;\r\n\r\nassert(isequal(nth_root(x,n),y_correct))\r\n\r\n%%\r\nx = 256;n=4;\r\ny_correct = 4;\r\n\r\nassert(isequal(nth_root(x,n),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":22553,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":364,"test_suite_updated_at":"2014-08-26T16:11:50.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2014-06-18T15:50:59.000Z","updated_at":"2026-03-23T11:17:06.000Z","published_at":"2014-06-18T15:52:17.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 Nth root of a given number x.\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\u003eExamples\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = 4096\\n n = 4\\n y = 8\\n\\n x = 625\\n n = 5\\n y = 3.6239]]\u003e\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":43625,"title":"Calculate roots of polynomial given as vector array.","description":"Calculate roots of polynomial given as vector array.\r\n\r\nExample\r\n\r\nx=[1     2     0     5     0     3]\r\n\r\nresult=[-2.7267  ;        \r\n   0.4784 + 1.0983i;\r\n   0.4784 - 1.0983i;\r\n  -0.1150 + 0.8680i;\r\n  -0.1150 - 0.8680i]","description_html":"\u003cp\u003eCalculate roots of polynomial given as vector array.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cp\u003ex=[1     2     0     5     0     3]\u003c/p\u003e\u003cp\u003eresult=[-2.7267  ;        \r\n   0.4784 + 1.0983i;\r\n   0.4784 - 1.0983i;\r\n  -0.1150 + 0.8680i;\r\n  -0.1150 - 0.8680i]\u003c/p\u003e","function_template":"function y = PolRoot(x)\r\n   y=x\r\nend","test_suite":"%%\r\nx = [1     2     0     5     0     3];\r\ny_correct = [-2.7267 + 0.0000i ;0.4784 + 1.0983i ;0.4784 - 1.0983i ;-0.1150 + 0.8680i ;-0.1150 - 0.8680i];\r\ny=PolRoot(x)\r\nassert(abs(y(1)-y_correct(1))\u003c10^(-4))\r\nassert(abs(y(2)-y_correct(2))\u003c10^(-4))\r\nassert(abs(y(3)-y_correct(3))\u003c10^(-4))\r\nassert(abs(y(4)-y_correct(4))\u003c10^(-4))\r\n%%\r\nx = [3     2     5     1     0     2];\r\ny_correct = [-0.3205 + 1.2968i; -0.3205 - 1.2968i; -0.7915 + 0.0000i; 0.3829 + 0.5704i; 0.3829 - 0.5704i];\r\ny=PolRoot(x)\r\nassert(abs(y(1)-y_correct(1))\u003c10^(-4))\r\nassert(abs(y(2)-y_correct(2))\u003c10^(-4))\r\nassert(abs(y(3)-y_correct(3))\u003c10^(-4))\r\nassert(abs(y(4)-y_correct(4))\u003c10^(-4))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":90467,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":90,"test_suite_updated_at":"2016-10-25T18:15:54.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-25T18:11:06.000Z","updated_at":"2026-02-25T20:52:46.000Z","published_at":"2016-10-25T18:15: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eCalculate roots of polynomial given as vector array.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex=[1 2 0 5 0 3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eresult=[-2.7267 ; 0.4784 + 1.0983i; 0.4784 - 1.0983i; -0.1150 + 0.8680i; -0.1150 - 0.8680i]\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":43130,"title":"Nth root","description":"Nth root of a number x","description_html":"\u003cp\u003eNth root of a number x\u003c/p\u003e","function_template":"function y = nroot(n,x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\nn=1;\r\ny_correct = 1;\r\nassert((nroot(n,x)-y_correct)\u003c0.001)\r\n\r\n%%\r\nx = 1;\r\nn=2;\r\ny_correct = 1;\r\nassert((nroot(n,x)-y_correct)\u003c0.001)\r\n\r\n\r\n%%\r\nx = 1;\r\nn=2;\r\ny_correct = 1;\r\nassert((nroot(n,x)-y_correct)\u003c0.001)\r\n\r\n\r\n%%\r\nx = 10;\r\nn=2;\r\ny_correct = 3.1623;\r\nassert((nroot(n,x)-y_correct)\u003c0.001)\r\n\r\n%%\r\nx = 10;\r\nn=10;\r\ny_correct = 1.2589;\r\nassert((nroot(n,x)-y_correct)\u003c0.001)\r\n\r\n%%\r\nx = 100;\r\nn=100;\r\ny_correct = 1.0471;\r\nassert((nroot(n,x)-y_correct)\u003c0.001)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":91311,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":138,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-06T17:19:12.000Z","updated_at":"2026-02-17T09:14:29.000Z","published_at":"2016-10-06T17:19:12.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eNth root of a number x\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":43021,"title":"How many figures currently exist?","description":"Return the number of figures that exist at any given time.","description_html":"\u003cp\u003eReturn the number of figures that exist at any given time.\u003c/p\u003e","function_template":"function y = numfig()\r\n    y = 0;\r\nend","test_suite":"%%\r\nassert(isequal(numfig(),0))\r\n\r\n%%\r\nclose all;\r\nfigure;\r\nassert(isequal(numfig(),1))\r\n\r\n%%\r\nclose all;\r\nfigure;\r\nfigure;\r\nassert(isequal(numfig(),2))\r\n\r\n%%\r\nclose all;\r\nfigure;\r\nfigure; plot(1,1);\r\nfigure; imagesc(magic(5));\r\nassert(isequal(numfig(),3))\r\n\r\n%%\r\nclose all;\r\nn = randi(20);\r\nfor ii=1:n\r\n    figure;\r\nend\r\nassert(isequal(numfig(),n))\r\n\r\n%%\r\nclose all;\r\nassert(isequal(numfig(),0))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":37,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-04T14:56:58.000Z","updated_at":"2026-03-02T15:03:36.000Z","published_at":"2016-10-04T14:56:58.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eReturn the number of figures that exist at any given time.\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":44659,"title":"Nth root of a number","description":"Given an input and a number N, find the Nth root of the number(s)","description_html":"\u003cp\u003eGiven an input and a number N, find the Nth root of the number(s)\u003c/p\u003e","function_template":"function y = rootN(a,N)\r\n  y = x;\r\nend","test_suite":"%%\r\na = 1;\r\nN = 100\r\ny_correct = 1;\r\nassert(isequal(rootN(a,N),y_correct))\r\n\r\n%%\r\na = [1 64 216];\r\nN = 3\r\ny_correct = [1    4    6];\r\nassert(isequal(rootN(a,N),y_correct))\r\n\r\n%%\r\na = 1/100;\r\nN = 2\r\ny_correct = 1/10;\r\nassert(isequal(rootN(a,N),y_correct))\r\n\r\n%%\r\na = 826^10;\r\nN = 10\r\ny_correct = 826;\r\nassert(isequal(rootN(a,N),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":59,"test_suite_updated_at":"2018-05-29T13:54:08.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-29T13:48:03.000Z","updated_at":"2026-02-20T14:32:58.000Z","published_at":"2018-05-29T13:48:03.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eGiven an input and a number N, find the Nth root of the number(s)\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":549,"title":"root?","description":"* Given a function 'foo', and a position 'there', find the root near 'there'.\r\n* For example: If foo=@sin, and there=3.1, then rootof(foo, there) \u003e\u003e 3.1416","description_html":"\u003cul\u003e\u003cli\u003eGiven a function 'foo', and a position 'there', find the root near 'there'.\u003c/li\u003e\u003cli\u003eFor example: If foo=@sin, and there=3.1, then rootof(foo, there) \u003e\u003e 3.1416\u003c/li\u003e\u003c/ul\u003e","function_template":"function  root = rootof(foo, there)\r\n  root=pi;\r\nend","test_suite":"%%\r\nassert(abs(rootof(@sin,3)-pi)\u003c100*eps)\r\n\r\n%%\r\nassert(abs(rootof(@cos,1.5)-pi/2)\u003c100*eps)\r\n\r\n%%\r\nassert(abs(rootof(@tan,0.05)-0)\u003c100*eps)\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":108,"test_suite_updated_at":"2012-04-02T06:33:55.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-02T06:33:55.000Z","updated_at":"2026-03-24T11:47:08.000Z","published_at":"2012-04-02T06:33:55.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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a function 'foo', and a position 'there', find the root near 'there'.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example: If foo=@sin, and there=3.1, then rootof(foo, there) \u0026gt;\u0026gt; 3.1416\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":42917,"title":"Nth roots of unity","description":"First, find the n nth roots of unity.\r\neg if n = 6, find the n distinct (complex) numbers such that n^6 = 1.\r\n\r\n\u003chttps://en.wikipedia.org/wiki/Root_of_unity\u003e\r\n\r\nSecond, raise each root to the power pi (.^pi).\r\n\r\nThird, sum the resulting numbers and use that as the output. \r\n","description_html":"\u003cp\u003eFirst, find the n nth roots of unity.\r\neg if n = 6, find the n distinct (complex) numbers such that n^6 = 1.\u003c/p\u003e\u003cp\u003e\u003ca href = \"https://en.wikipedia.org/wiki/Root_of_unity\"\u003ehttps://en.wikipedia.org/wiki/Root_of_unity\u003c/a\u003e\u003c/p\u003e\u003cp\u003eSecond, raise each root to the power pi (.^pi).\u003c/p\u003e\u003cp\u003eThird, sum the resulting numbers and use that as the output.\u003c/p\u003e","function_template":"function y = your_fcn_name(n)\r\n  y = 0;\r\nend","test_suite":"%%\r\nn = 5;\r\ny_correct =  -0.467800202134647;\r\nassert( abs(your_fcn_name(n)-y_correct) \u003c .0001)\r\n\r\n%%\r\nn = 50;\r\ny_correct = -2.151544927902936 - 0.430301217000093i\r\nassert( abs(your_fcn_name(n)-y_correct) \u003c .0001)\r\n\r\n%%\r\nn = 7;\r\ny_correct =   -0.435928596902380\r\nassert( abs(your_fcn_name(n)-y_correct) \u003c .0001)\r\n\r\n\r\n%%\r\nn = 70;\r\ny_correct =   -3.031653804728051 - 0.430301217000095i\r\nassert( abs(your_fcn_name(n)-y_correct) \u003c .0001)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":65480,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":67,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-08-01T00:25:42.000Z","updated_at":"2026-02-24T14:03:00.000Z","published_at":"2016-08-01T00:25:42.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\u003eFirst, find the n nth roots of unity. eg if n = 6, find the n distinct (complex) numbers such that n^6 = 1.\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:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Root_of_unity\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://en.wikipedia.org/wiki/Root_of_unity\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\u003eSecond, raise each root to the power pi (.^pi).\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\u003eThird, sum the resulting numbers and use that as the output.\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":2055,"title":"Create numeric palindromes and their square roots","description":"Given a number n (1\u003c=n\u003c=9), return a left justified numeric matrix p with all the palindromes of the form 1 to n and back to 1. Use 0 for empty values. Similarly return the square root matrix in the same form.\r\n\r\nExample\r\n\r\n n=2;\r\n\r\n p=[1 0 0; 1 2 1];\r\n\r\n r=[1 0 0; 1 1 0];","description_html":"\u003cp\u003eGiven a number n (1\u0026lt;=n\u0026lt;=9), return a left justified numeric matrix p with all the palindromes of the form 1 to n and back to 1. Use 0 for empty values. Similarly return the square root matrix in the same form.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e n=2;\u003c/pre\u003e\u003cpre\u003e p=[1 0 0; 1 2 1];\u003c/pre\u003e\u003cpre\u003e r=[1 0 0; 1 1 0];\u003c/pre\u003e","function_template":"function [p,r] = palinroot(n)\r\np=[1 0 0; 1 2 1];\r\nr=sqrt(p);\r\nend","test_suite":"%%\r\nn=3;\r\n[p,r]=palinroot(n);\r\ny_correct=[1 0 0 0 0; 1 2 1 0 0; 1 2 3 2 1];\r\nz_correct=[1 0 0; 1 1 0; 1 1 1];\r\nassert(isequal(p,y_correct))\r\nassert(isequal(r,z_correct))\r\n\r\n\r\n%%\r\nn=9;\r\n[p,r]=palinroot(n);\r\n\r\nrr=1;\r\nfor s1=2:n\r\n    rr(s1)=rr(s1-1)*10+1;\r\nend\r\nrr=num2str(rr','%.0f');\r\nz_correct=tril(fliplr(rr)-'0');\r\n\r\npp=zeros(n,n*2-1);\r\nfor s=1:n\r\n    p1=1:s;\r\n    p2=fliplr(p1);\r\n    st=deal([p1,p2(2:end)]);\r\n    pp(s,1:numel(st))=st;\r\nend\r\ny_correct=pp;\r\n\r\nassert(isequal(p,y_correct))\r\nassert(isequal(r,z_correct))\r\n\r\n%%\r\nn=5;\r\n[p,r]=palinroot(n);\r\n\r\nrr=1;\r\nfor s1=2:n\r\n    rr(s1)=rr(s1-1)*10+1;\r\nend\r\nrr=num2str(rr','%.0f');\r\nz_correct=tril(fliplr(rr)-'0');\r\n\r\npp=zeros(n,n*2-1);\r\nfor s=1:n\r\n    p1=1:s;\r\n    p2=fliplr(p1);\r\n    st=deal([p1,p2(2:end)]);\r\n    pp(s,1:numel(st))=st;\r\nend\r\ny_correct=pp;\r\n\r\nassert(isequal(p,y_correct))\r\nassert(isequal(r,z_correct))\r\n\r\n%%\r\nn=7;\r\n[p,r]=palinroot(n);\r\n\r\nrr=1;\r\nfor s1=2:n\r\n    rr(s1)=rr(s1-1)*10+1;\r\nend\r\nrr=num2str(rr','%.0f');\r\nz_correct=tril(fliplr(rr)-'0');\r\n\r\npp=zeros(n,n*2-1);\r\nfor s=1:n\r\n    p1=1:s;\r\n    p2=fliplr(p1);\r\n    st=deal([p1,p2(2:end)]);\r\n    pp(s,1:numel(st))=st;\r\nend\r\ny_correct=pp;\r\n\r\nassert(isequal(p,y_correct))\r\nassert(isequal(r,z_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":17471,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":"2013-12-15T11:05:10.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-12-15T09:35:00.000Z","updated_at":"2026-01-02T17:16:23.000Z","published_at":"2013-12-15T10:36:26.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\u003eGiven a number n (1\u0026lt;=n\u0026lt;=9), return a left justified numeric matrix p with all the palindromes of the form 1 to n and back to 1. Use 0 for empty values. Similarly return the square root matrix in the same form.\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\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ n=2;\\n\\n p=[1 0 0; 1 2 1];\\n\\n r=[1 0 0; 1 1 0];]]\u003e\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":44344,"title":"The 5th Root","description":"Write a function to find the 5th root of a number.\r\n\r\nIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.","description_html":"\u003cp\u003eWrite a function to find the 5th root of a number.\u003c/p\u003e\u003cp\u003eIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.\u003c/p\u003e","function_template":"function f = fifth_root(n)\r\n f = n^(1/5)\r\nend","test_suite":"%%\r\nfiletext = fileread('fifth_root.m');\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'power')),'power() forbidden')\r\nassert(isempty(strfind(filetext, 'mpower')),'mpower() forbidden')\r\nassert(isempty(strfind(filetext, 'realpow')),'realpow() forbidden')\r\nassert(isempty(strfind(filetext, 'nthroot')),'nthroot() forbidden')\r\nassert(isempty(strfind(filetext, 'roots')),'roots() forbidden')\r\n\r\n%%\r\nn = 1/9765625;\r\nassert(abs(fifth_root(n)-1/25)\u003c1e-5)\r\n\r\n%%\r\nn = 1/5555;\r\nassert(abs(fifth_root(n)-0.178263811215444)\u003c1e-5)\r\n\r\n%%\r\nn = 1/3125;\r\nassert(abs(fifth_root(n)-1/5)\u003c1e-5)\r\n\r\n%%\r\nn = 1/125;\r\nassert(abs(fifth_root(n)-0.380730787743176)\u003c1e-5)\r\n\r\n%%\r\nn = 1/5;\r\nassert(abs(fifth_root(n)-0.724779663677696)\u003c1e-5)\r\n\r\n%%\r\nn = 1;\r\nassert(abs(fifth_root(n)-1)\u003c1e-5)\r\n\r\n%%\r\nn = 5;\r\nassert(abs(fifth_root(n)-1.37972966146121)\u003c1e-5)\r\n\r\n%%\r\nn = 25;\r\nassert(abs(fifth_root(n)-1.90365393871588)\u003c1e-5)\r\n\r\n%%\r\nn = 50;\r\nassert(abs(fifth_root(n)-2.18672414788656)\u003c1e-5)\r\n\r\n%%\r\nn = 500;\r\nassert(abs(fifth_root(n)-3.46572421577573)\u003c1e-5)\r\n\r\n%%\r\nn = 3125;\r\nassert(abs(fifth_root(n)-5)\u003c1e-5)\r\n\r\n%%\r\nn = 759375;\r\nassert(abs(fifth_root(n)-15)\u003c1e-5)\r\n\r\n%%\r\nn = 9765625;\r\nassert(abs(fifth_root(n)-25)\u003c1e-5)\r\n\r\n%%\r\nn = 312500000;\r\nassert(abs(fifth_root(n)-50)\u003c1e-5)\r\n\r\n%%\r\nn = 75937500000;\r\nassert(abs(fifth_root(n)-150)\u003c1e-5)\r\n\r\n%%\r\nn = 31250000000000;\r\nassert(abs(fifth_root(n)-500)\u003c1e-5)\r\n\r\n%%\r\nn = 52658067346875;\r\nassert(abs(fifth_root(n)-555)\u003c1e-5)","published":true,"deleted":false,"likes_count":13,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":559,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-22T16:03:40.000Z","updated_at":"2026-02-03T09:23:18.000Z","published_at":"2017-10-16T01:50:59.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eWrite a function to find the 5th root of a number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.\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:\"root\"","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:\"root\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"root\"","","\"","root","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f69f4888b68\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f69f4888ac8\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f69f4885be8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f69f4888e88\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f69f4888de8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f69f4888d48\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f69f4888c08\u003e":"tag:\"root\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f69f4888c08\u003e":"tag:\"root\""},"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":"cody-search","password":"78X075ddcV44","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:\"root\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"root\"","","\"","root","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f69f4888b68\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f69f4888ac8\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f69f4885be8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f69f4888e88\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f69f4888de8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f69f4888d48\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f69f4888c08\u003e":"tag:\"root\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f69f4888c08\u003e":"tag:\"root\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":2376,"difficulty_rating":"easy"},{"id":43625,"difficulty_rating":"easy"},{"id":43130,"difficulty_rating":"easy"},{"id":43021,"difficulty_rating":"easy"},{"id":44659,"difficulty_rating":"easy"},{"id":549,"difficulty_rating":"easy"},{"id":42917,"difficulty_rating":"easy-medium"},{"id":2055,"difficulty_rating":"easy-medium"},{"id":44344,"difficulty_rating":"medium"}]}}