{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-06-25T00:23:38.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-06-25T00: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":44159,"title":"calculate PI without using pi function","description":"There are many methods to get the pi(Ratio of circumference to diameter). \r\nYou should get pi without using the pi function in MATLAB.\r\n\r\n\u003chttps://en.wikipedia.org/wiki/Pi\u003e The Chinese mathematician Zu Chongzhi, around 480 AD, calculated that π ≈ 355/113. With a correct value for its seven first decimal digits, this value of 3. 141592920 , remained the most accurate approximation of π available for the next 800 years.","description_html":"\u003cp\u003eThere are many methods to get the pi(Ratio of circumference to diameter). \r\nYou should get pi without using the pi function in MATLAB.\u003c/p\u003e\u003cp\u003e\u003ca href = \"https://en.wikipedia.org/wiki/Pi\"\u003ehttps://en.wikipedia.org/wiki/Pi\u003c/a\u003e The Chinese mathematician Zu Chongzhi, around 480 AD, calculated that π ≈ 355/113. With a correct value for its seven first decimal digits, this value of 3. 141592920 , remained the most accurate approximation of π available for the next 800 years.\u003c/p\u003e","function_template":"function PAI = calculate_PAI\r\n  PAI = ...;\r\nend","test_suite":"%%\r\nassert(abs(calculate_PAI-pi)\u003c1e-7);\r\n%%\r\nfiletext = fileread('calculate_PAI.m');\r\nassert(isempty(strfind(filetext, 'pi')),'pi forbidden');\r\nassert(isempty(strfind(filetext, '3.14159')),'3.14159 forbidden');\r\nassert(isempty(strfind(filetext, 'str')),'str function forbidden');","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":125749,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":108,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-05-14T04:46:10.000Z","updated_at":"2026-05-02T16:44:36.000Z","published_at":"2017-05-14T04:46:10.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\u003eThere are many methods to get the pi(Ratio of circumference to diameter). You should get pi without using the pi function in MATLAB.\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/Pi\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://en.wikipedia.org/wiki/Pi\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt; The Chinese mathematician Zu Chongzhi, around 480 AD, calculated that π ≈ 355/113. With a correct value for its seven first decimal digits, this value of 3. 141592920 , remained the most accurate approximation of π available for the next 800 years.\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":44156,"title":"Weighted average","description":"Compute the weighted average Y, of the vector A, given the weight vector W.\r\n\r\nThe weighted average is the sum of the dot product of A and W, normalized by the sum of W.\r\n\r\nExample 1:\r\n\r\n  A = [10 15 20 10];\r\n  W = [ 1  1  1  1];\r\n  Y = 13.75\r\n\r\nExample 2:\r\n\r\n  A = [  10    15   20   10];\r\n  W = [0.25  0.25 0.25 0.25];\r\n  Y = 13.75\r\n\r\nExample 3:\r\n\r\n  A = [10 15 20 10];\r\n  W = [ 2  4  4  2];\r\n  Y = 15","description_html":"\u003cp\u003eCompute the weighted average Y, of the vector A, given the weight vector W.\u003c/p\u003e\u003cp\u003eThe weighted average is the sum of the dot product of A and W, normalized by the sum of W.\u003c/p\u003e\u003cp\u003eExample 1:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [10 15 20 10];\r\nW = [ 1  1  1  1];\r\nY = 13.75\r\n\u003c/pre\u003e\u003cp\u003eExample 2:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [  10    15   20   10];\r\nW = [0.25  0.25 0.25 0.25];\r\nY = 13.75\r\n\u003c/pre\u003e\u003cp\u003eExample 3:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [10 15 20 10];\r\nW = [ 2  4  4  2];\r\nY = 15\r\n\u003c/pre\u003e","function_template":"function Y = weighted_average(A,W)\r\n  Y = A;\r\nend","test_suite":"%%\r\nA = [10 15 20 10];\r\nW = [ 1  1  1  1];\r\nY = 13.75\r\nassert(isequal(weighted_average(A,W),Y))\r\n\r\n%%\r\nA = [  10    15   20   10];\r\nW = [0.25  0.25 0.25 0.25];\r\nY = 13.75\r\nassert(isequal(weighted_average(A,W),Y))\r\n\r\n%%\r\nA = [10 15 20 10];\r\nW = [ 2  4  4  2];\r\nY = 15\r\nassert(isequal(weighted_average(A,W),Y))\r\n\r\n%%\r\nassert(~any(strfind(lower(fileread('weighted_average.m')),'regexp')))\r\n\r\n%%\r\nassert(~any(strfind(lower(fileread('weighted_average.m')),'feval')))\r\n\r\n%%\r\nassert(~any(strfind(lower(fileread('weighted_average.m')),'eval')))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":130819,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":119,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-05-04T14:38:26.000Z","updated_at":"2026-04-13T20:41:18.000Z","published_at":"2017-05-04T14:38: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\u003eCompute the weighted average Y, of the vector A, given the weight vector W.\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 weighted average is the sum of the dot product of A and W, normalized by the sum of W.\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 1:\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[A = [10 15 20 10];\\nW = [ 1  1  1  1];\\nY = 13.75]]\u003e\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 2:\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[A = [  10    15   20   10];\\nW = [0.25  0.25 0.25 0.25];\\nY = 13.75]]\u003e\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 3:\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[A = [10 15 20 10];\\nW = [ 2  4  4  2];\\nY = 15]]\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":43563,"title":"Calculate cosine without cos(x)","description":"Solve cos(x).\r\n\r\nThe use of the function cos() and sin() is not allowed.","description_html":"\u003cp\u003eSolve cos(x).\u003c/p\u003e\u003cp\u003eThe use of the function cos() and sin() is not allowed.\u003c/p\u003e","function_template":"function y = my_func(x)\r\n  y = cos(x);\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = 1;\r\nassert(abs(my_func(x)-y_correct)\u003c0.0001)\r\n\r\n%%\r\nx = pi/2;\r\ny_correct = 0;\r\nassert(abs(my_func(x)-y_correct)\u003c0.0001)\r\n\r\n%%\r\nx = rand(1)*2*pi;\r\ny_correct = cos(x);\r\nassert(abs(my_func(x)-y_correct)\u003c0.0001)\r\n\r\n%%\r\nassessFunctionAbsence({'sin','cos'}, 'FileName', 'my_func.m')\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":14644,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":127,"test_suite_updated_at":"2016-12-01T18:38:29.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-16T10:35:20.000Z","updated_at":"2026-05-24T16:48:13.000Z","published_at":"2016-10-16T10:42: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\u003eSolve cos(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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe use of the function cos() and sin() is not allowed.\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":2161,"title":"Let's get back to school, and create multiplication tables","description":"For a given range, create multiplication tables. (start is always \u003c endno)\r\n\r\nExample\r\n\r\n start = 17\r\n endno = 19\r\n\r\nThen, \r\n\r\n table = \r\n  [ 17    18    19\r\n    34    36    38\r\n    51    54    57\r\n    68    72    76\r\n    85    90    95\r\n   102   108   114\r\n   119   126   133\r\n   136   144   152\r\n   153   162   171\r\n   170   180   190 ]\r\n","description_html":"\u003cp\u003eFor a given range, create multiplication tables. (start is always \u0026lt; endno)\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e start = 17\r\n endno = 19\u003c/pre\u003e\u003cp\u003eThen,\u003c/p\u003e\u003cpre\u003e table = \r\n  [ 17    18    19\r\n    34    36    38\r\n    51    54    57\r\n    68    72    76\r\n    85    90    95\r\n   102   108   114\r\n   119   126   133\r\n   136   144   152\r\n   153   162   171\r\n   170   180   190 ]\u003c/pre\u003e","function_template":"function table= Tables(start, endno)\r\n  table = [start:endno];\r\nend","test_suite":"%%\r\nstart = 1;\r\nendno = 10;\r\ny_correct = [1     2     3     4     5     6     7     8     9    10;\r\n     2     4     6     8    10    12    14    16    18    20;\r\n     3     6     9    12    15    18    21    24    27    30;\r\n     4     8    12    16    20    24    28    32    36    40;\r\n     5    10    15    20    25    30    35    40    45    50;\r\n     6    12    18    24    30    36    42    48    54    60;\r\n     7    14    21    28    35    42    49    56    63    70;\r\n     8    16    24    32    40    48    56    64    72    80;\r\n     9    18    27    36    45    54    63    72    81    90;\r\n    10    20    30    40    50    60    70    80    90   100;];\r\nassert(isequal(Tables(start, endno),y_correct))\r\n\r\n%%\r\nstart = 17;\r\nendno = 19;\r\ny_correct = [17    18    19;\r\n    34    36    38;\r\n    51    54    57;\r\n    68    72    76;\r\n    85    90    95;\r\n   102   108   114;\r\n   119   126   133;\r\n   136   144   152;\r\n   153   162   171;\r\n   170   180   190;];\r\nassert(isequal(Tables(start, endno),y_correct))\r\n\r\n%%\r\nstart = 21;\r\nendno = 22;\r\n\r\ny_correct =[21    22;\r\n    42    44;\r\n    63    66;\r\n    84    88;\r\n   105   110;\r\n   126   132;\r\n   147   154;\r\n   168   176;\r\n   189   198;\r\n   210   220;]\r\nassert(isequal(Tables(start, endno),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":241,"test_suite_updated_at":"2014-02-06T17:58:19.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-02-06T17:45:15.000Z","updated_at":"2026-06-12T16:39:05.000Z","published_at":"2014-02-06T17:49: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\",\"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\u003eFor a given range, create multiplication tables. (start is always \u0026lt; endno)\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[ start = 17\\n endno = 19]]\u003e\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\u003eThen,\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[ table = \\n  [ 17    18    19\\n    34    36    38\\n    51    54    57\\n    68    72    76\\n    85    90    95\\n   102   108   114\\n   119   126   133\\n   136   144   152\\n   153   162   171\\n   170   180   190 ]]]\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":43283,"title":"Subtract integers and add doubles","description":"Create a function that subtracts a from b if a and b are integers and adds them if they are floats.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: normal; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; transform-origin: 332px 10.5px; vertical-align: baseline; perspective-origin: 332px 10.5px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 10.5px; white-space: pre-wrap; perspective-origin: 309px 10.5px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eCreate a function that subtracts b from a if a and b are integers and adds them if they are floats.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function c = intOrfloat(a, b)\r\n  if isinteger(a)\r\n      a = a + b;\r\n  else\r\n      a = a - b;\r\n  end\r\nend","test_suite":"%%\r\na = int8(1);\r\nb = int8(2);\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,-1))\r\n\r\n%%\r\na = 1;\r\nb = 2;\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,3))\r\n\r\n%%\r\na = uint8(1);\r\nb = uint8(2);\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,0))\r\n\r\n%%\r\na = int16(100);\r\nb = int16(200);\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,-100))\r\n\r\n%%\r\na = single(100);\r\nb = single(200);\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,300))","published":true,"deleted":false,"likes_count":4,"comments_count":4,"created_by":57323,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":132,"test_suite_updated_at":"2016-10-28T02:19:03.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-09T15:33:19.000Z","updated_at":"2026-05-24T16:46:16.000Z","published_at":"2016-10-09T15:33:19.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCreate a function that subtracts b from a if a and b are integers and adds them if they are floats.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1502,"title":"Perl 1: push","description":"_This is part of a series of perl function which were very helpful for many perl programmers. Could you implement it in Matlab?_\r\n \r\nPushes the values of list onto the end of the array and returns the number of elements in the new array. The output vector should be of the same type (column or row array) as the input vector x regardless of the list append type.\r\nExample:\r\n\r\n  x=[1 2 3 4 5]\r\n  [x, num]=push(x, [6 7 8])\r\n\r\nthen\r\n\r\n  x=[1 2 3 4 5 6 8]\r\n  [x, num]=8\r\n","description_html":"\u003cp\u003e\u003ci\u003eThis is part of a series of perl function which were very helpful for many perl programmers. Could you implement it in Matlab?\u003c/i\u003e\u003c/p\u003e\u003cp\u003ePushes the values of list onto the end of the array and returns the number of elements in the new array. The output vector should be of the same type (column or row array) as the input vector x regardless of the list append type.\r\nExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex=[1 2 3 4 5]\r\n[x, num]=push(x, [6 7 8])\r\n\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex=[1 2 3 4 5 6 8]\r\n[x, num]=8\r\n\u003c/pre\u003e","function_template":"function y=push(x, list)\r\n","test_suite":"%%\r\nx = [1 2 3 4 5];\r\ny = [6 7 8];\r\n[x, num] = push(x, y);\r\ny_correct = [1 2 3 4 5 6 7 8];\r\nnum_correct = 8;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));\r\n\r\n%%\r\nx = [1 2 3 4 5];\r\ny = 6;\r\n[x, num] = push(x, y);\r\ny_correct = [1 2 3 4 5 6];\r\nnum_correct = 6;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));\r\n\r\n%%\r\nx = [1 2 3 4 5]';\r\ny = [6 7 8];\r\n[x, num] = push(x, y);\r\ny_correct = [1 2 3 4 5 6 7 8]';\r\nnum_correct = 8;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));\r\n\r\n%%\r\nx = [];\r\ny = [1 2 3];\r\n[x, num] = push(x, y);\r\ny_correct = [1 2 3];\r\nnum_correct = 3;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));\r\n\r\n%%\r\nx = [0.5 8.4 9.6];\r\ny = [12.0 pi];\r\n[x, num] = push(x, y);\r\ny_correct = [0.5 8.4 9.6 12.0 pi];\r\nnum_correct = 5;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));","published":true,"deleted":false,"likes_count":0,"comments_count":4,"created_by":750,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":86,"test_suite_updated_at":"2013-05-13T15:04:49.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-05-12T13:28:10.000Z","updated_at":"2026-04-03T03:01:36.000Z","published_at":"2013-05-12T13:45:43.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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eThis is part of a series of perl function which were very helpful for many perl programmers. Could you implement it in Matlab?\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\u003ePushes the values of list onto the end of the array and returns the number of elements in the new array. The output vector should be of the same type (column or row array) as the input vector x regardless of the list append type. Example:\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=[1 2 3 4 5]\\n[x, num]=push(x, [6 7 8])]]\u003e\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\u003ethen\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=[1 2 3 4 5 6 8]\\n[x, num]=8]]\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":2499,"title":"Airline Ticket Mod7 Checksum ","description":"There are 13 digits in an airline ticket number. If an airline ticket number is valid, the 13th digit should be the remainder of division by seven of the first 12. \r\n\r\n\r\n\r\nWrite a function that returns true if a plane ticket number is valid and false otherwise.","description_html":"\u003cp\u003eThere are 13 digits in an airline ticket number. If an airline ticket number is valid, the 13th digit should be the remainder of division by seven of the first 12.\u003c/p\u003e\u003cp\u003eWrite a function that returns true if a plane ticket number is valid and false otherwise.\u003c/p\u003e","function_template":"function b = isTicketValid(T)\r\n\r\nend","test_suite":"%%\r\nT=1234567891011;\r\nb_correct=0;\r\nassert(isequal(isTicketValid(T),b_correct))\r\n%%\r\nT=2355211846932;\r\nb_correct=0;\r\nassert(isequal(isTicketValid(T),b_correct))\r\n%%\r\nT=2355211846934;\r\nb_correct=1;\r\nassert(isequal(isTicketValid(T),b_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":379,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":86,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-08-09T16:26:01.000Z","updated_at":"2026-04-03T02:48:52.000Z","published_at":"2014-08-09T16:26:01.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\u003eThere are 13 digits in an airline ticket number. If an airline ticket number is valid, the 13th digit should be the remainder of division by seven of the first 12.\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\u003eWrite a function that returns true if a plane ticket number is valid and false otherwise.\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":42775,"title":"Raise a polynomial to a power","description":"In Matlab, polynomials are represented by a vector of coefficients.  For example, the polynomial p=a*x^2 + b*x + c is represented by the vector p=[a, b, c].\r\n\r\nIn this problem, you will be given a polynomial p and a power N.  We would like you to return the vector q that represents the polynominal p^N, the Nth power of p.  If p = (x + 1), for instance, you will be returning the coefficients of (x+1)^N.  (N will be a positive integer greater than 0.)","description_html":"\u003cp\u003eIn Matlab, polynomials are represented by a vector of coefficients.  For example, the polynomial p=a*x^2 + b*x + c is represented by the vector p=[a, b, c].\u003c/p\u003e\u003cp\u003eIn this problem, you will be given a polynomial p and a power N.  We would like you to return the vector q that represents the polynominal p^N, the Nth power of p.  If p = (x + 1), for instance, you will be returning the coefficients of (x+1)^N.  (N will be a positive integer greater than 0.)\u003c/p\u003e","function_template":"function q = polypow(p,N)\r\n  q = p^N;   \r\nend","test_suite":"%%\r\np=[2];\r\nN=8;\r\ny_correct=256;\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=[1 1];\r\nN=1;\r\ny_correct=[1 1];\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=[1 1];\r\nN=5;\r\ny_correct=[1 5 10 10 5 1];\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=1:5;\r\nN=3;\r\ny_correct=[1 6 21 56 126 234 369 504 594 574 465 300 125];\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=5:-1:1;\r\nN=3;\r\ny_correct=[125 300 465 574 594 504 369 234 126 56 21 6 1];\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=5:-1:1;\r\nN=1;\r\ny_correct=[5 4 3 2 1];\r\nassert(isequal(polypow(p,N),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":8580,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":97,"test_suite_updated_at":"2016-03-16T17:46:50.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-03-16T17:30:45.000Z","updated_at":"2026-04-03T02:46:51.000Z","published_at":"2016-03-16T17:44: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\",\"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\u003eIn Matlab, polynomials are represented by a vector of coefficients. For example, the polynomial p=a*x^2 + b*x + c is represented by the vector p=[a, b, c].\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\u003eIn this problem, you will be given a polynomial p and a power N. We would like you to return the vector q that represents the polynominal p^N, the Nth power of p. If p = (x + 1), for instance, you will be returning the coefficients of (x+1)^N. (N will be a positive integer greater than 0.)\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":1344,"title":"Moving average (variable kernel length)","description":"Find the moving average in a vector. The kernel length is a variable.\r\nFor example \r\n\r\n x = 1:10\r\n kernel_length = 2 \r\n\r\nwould result in\r\n\r\n [ 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 ]\r\n\r\nand\r\n\r\n x = 1:10\r\n kernel_length = 3 \r\n\r\nwould result in\r\n\r\n [ 2 3 4 5 6 7 8 9 ]\r\n","description_html":"\u003cp\u003eFind the moving average in a vector. The kernel length is a variable.\r\nFor example\u003c/p\u003e\u003cpre\u003e x = 1:10\r\n kernel_length = 2 \u003c/pre\u003e\u003cp\u003ewould result in\u003c/p\u003e\u003cpre\u003e [ 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 ]\u003c/pre\u003e\u003cp\u003eand\u003c/p\u003e\u003cpre\u003e x = 1:10\r\n kernel_length = 3 \u003c/pre\u003e\u003cp\u003ewould result in\u003c/p\u003e\u003cpre\u003e [ 2 3 4 5 6 7 8 9 ]\u003c/pre\u003e","function_template":"function y = moving_avg(x,kernel_length)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1:10;\r\nkernel_length=4\r\ny_correct = [  2.5000    3.5000    4.5000    5.5000    6.5000    7.5000    8.5000];\r\nassert(isequal(moving_avg(x,kernel_length),y_correct))\r\n\r\n%%\r\n\r\nx = 10:20;\r\nkernel_length=5\r\ny_correct = [  12.0000   13.0000   14.0000   15.0000   16.0000   17.0000   18.0000];\r\nassert(isequal(moving_avg(x,kernel_length),y_correct))\r\n\r\n%%\r\nx = ones(1,10);\r\nkernel_length=5\r\ny_correct = ones(1,6);\r\nassert(isequal(moving_avg(x,kernel_length),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":1023,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":137,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-03-15T03:02:53.000Z","updated_at":"2026-04-03T03:14:22.000Z","published_at":"2013-03-15T03:02:52.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 moving average in a vector. The kernel length is a variable. For example\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 = 1:10\\n kernel_length = 2]]\u003e\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\u003ewould result in\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[ [ 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 ]]]\u003e\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\u003eand\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 = 1:10\\n kernel_length = 3]]\u003e\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\u003ewould result in\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[ [ 2 3 4 5 6 7 8 9 ]]]\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":2240,"title":"Sum the 'edge' values of a matrix","description":"Sum the 'edge' values of an input matrix (the values along the perimeter).\r\n\r\nExample\r\n\r\n [1 2 3\r\n  4 5 6\r\n  7 8 9]\r\n\r\nOutput = 1 + 2 + 3 + 6 + 9 + 8 + 7 + 4 = 40;\r\n\r\nAssumption: Input matrix equal or bigger than 3x3.","description_html":"\u003cp\u003eSum the 'edge' values of an input matrix (the values along the perimeter).\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e [1 2 3\r\n  4 5 6\r\n  7 8 9]\u003c/pre\u003e\u003cp\u003eOutput = 1 + 2 + 3 + 6 + 9 + 8 + 7 + 4 = 40;\u003c/p\u003e\u003cp\u003eAssumption: Input matrix equal or bigger than 3x3.\u003c/p\u003e","function_template":"function y = AddMatrixLim(x)\r\n %add code\r\nend","test_suite":"%%\r\nx = [1 2 3; 4 5 6;7 8 9];\r\ny_correct = 40;\r\nassert(isequal(AddMatrixLim(x),y_correct))\r\n\r\n%%\r\nx= [1 5 6 7; 4 9 4 7; 9 4 2 1; 0 1 2 8]\r\ny_correct = 51;\r\nassert(isequal(AddMatrixLim(x),y_correct))","published":true,"deleted":false,"likes_count":8,"comments_count":0,"created_by":24008,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":405,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-09T13:39:17.000Z","updated_at":"2026-07-02T12:24:46.000Z","published_at":"2014-03-09T13:39: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\u003eSum the 'edge' values of an input matrix (the values along the perimeter).\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[ [1 2 3\\n  4 5 6\\n  7 8 9]]]\u003e\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\u003eOutput = 1 + 2 + 3 + 6 + 9 + 8 + 7 + 4 = 40;\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\u003eAssumption: Input matrix equal or bigger than 3x3.\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":{"problems":[{"id":44159,"title":"calculate PI without using pi function","description":"There are many methods to get the pi(Ratio of circumference to diameter). \r\nYou should get pi without using the pi function in MATLAB.\r\n\r\n\u003chttps://en.wikipedia.org/wiki/Pi\u003e The Chinese mathematician Zu Chongzhi, around 480 AD, calculated that π ≈ 355/113. With a correct value for its seven first decimal digits, this value of 3. 141592920 , remained the most accurate approximation of π available for the next 800 years.","description_html":"\u003cp\u003eThere are many methods to get the pi(Ratio of circumference to diameter). \r\nYou should get pi without using the pi function in MATLAB.\u003c/p\u003e\u003cp\u003e\u003ca href = \"https://en.wikipedia.org/wiki/Pi\"\u003ehttps://en.wikipedia.org/wiki/Pi\u003c/a\u003e The Chinese mathematician Zu Chongzhi, around 480 AD, calculated that π ≈ 355/113. With a correct value for its seven first decimal digits, this value of 3. 141592920 , remained the most accurate approximation of π available for the next 800 years.\u003c/p\u003e","function_template":"function PAI = calculate_PAI\r\n  PAI = ...;\r\nend","test_suite":"%%\r\nassert(abs(calculate_PAI-pi)\u003c1e-7);\r\n%%\r\nfiletext = fileread('calculate_PAI.m');\r\nassert(isempty(strfind(filetext, 'pi')),'pi forbidden');\r\nassert(isempty(strfind(filetext, '3.14159')),'3.14159 forbidden');\r\nassert(isempty(strfind(filetext, 'str')),'str function forbidden');","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":125749,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":108,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-05-14T04:46:10.000Z","updated_at":"2026-05-02T16:44:36.000Z","published_at":"2017-05-14T04:46:10.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\u003eThere are many methods to get the pi(Ratio of circumference to diameter). You should get pi without using the pi function in MATLAB.\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/Pi\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://en.wikipedia.org/wiki/Pi\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt; The Chinese mathematician Zu Chongzhi, around 480 AD, calculated that π ≈ 355/113. With a correct value for its seven first decimal digits, this value of 3. 141592920 , remained the most accurate approximation of π available for the next 800 years.\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":44156,"title":"Weighted average","description":"Compute the weighted average Y, of the vector A, given the weight vector W.\r\n\r\nThe weighted average is the sum of the dot product of A and W, normalized by the sum of W.\r\n\r\nExample 1:\r\n\r\n  A = [10 15 20 10];\r\n  W = [ 1  1  1  1];\r\n  Y = 13.75\r\n\r\nExample 2:\r\n\r\n  A = [  10    15   20   10];\r\n  W = [0.25  0.25 0.25 0.25];\r\n  Y = 13.75\r\n\r\nExample 3:\r\n\r\n  A = [10 15 20 10];\r\n  W = [ 2  4  4  2];\r\n  Y = 15","description_html":"\u003cp\u003eCompute the weighted average Y, of the vector A, given the weight vector W.\u003c/p\u003e\u003cp\u003eThe weighted average is the sum of the dot product of A and W, normalized by the sum of W.\u003c/p\u003e\u003cp\u003eExample 1:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [10 15 20 10];\r\nW = [ 1  1  1  1];\r\nY = 13.75\r\n\u003c/pre\u003e\u003cp\u003eExample 2:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [  10    15   20   10];\r\nW = [0.25  0.25 0.25 0.25];\r\nY = 13.75\r\n\u003c/pre\u003e\u003cp\u003eExample 3:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [10 15 20 10];\r\nW = [ 2  4  4  2];\r\nY = 15\r\n\u003c/pre\u003e","function_template":"function Y = weighted_average(A,W)\r\n  Y = A;\r\nend","test_suite":"%%\r\nA = [10 15 20 10];\r\nW = [ 1  1  1  1];\r\nY = 13.75\r\nassert(isequal(weighted_average(A,W),Y))\r\n\r\n%%\r\nA = [  10    15   20   10];\r\nW = [0.25  0.25 0.25 0.25];\r\nY = 13.75\r\nassert(isequal(weighted_average(A,W),Y))\r\n\r\n%%\r\nA = [10 15 20 10];\r\nW = [ 2  4  4  2];\r\nY = 15\r\nassert(isequal(weighted_average(A,W),Y))\r\n\r\n%%\r\nassert(~any(strfind(lower(fileread('weighted_average.m')),'regexp')))\r\n\r\n%%\r\nassert(~any(strfind(lower(fileread('weighted_average.m')),'feval')))\r\n\r\n%%\r\nassert(~any(strfind(lower(fileread('weighted_average.m')),'eval')))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":130819,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":119,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-05-04T14:38:26.000Z","updated_at":"2026-04-13T20:41:18.000Z","published_at":"2017-05-04T14:38: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\u003eCompute the weighted average Y, of the vector A, given the weight vector W.\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 weighted average is the sum of the dot product of A and W, normalized by the sum of W.\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 1:\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[A = [10 15 20 10];\\nW = [ 1  1  1  1];\\nY = 13.75]]\u003e\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 2:\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[A = [  10    15   20   10];\\nW = [0.25  0.25 0.25 0.25];\\nY = 13.75]]\u003e\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 3:\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[A = [10 15 20 10];\\nW = [ 2  4  4  2];\\nY = 15]]\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":43563,"title":"Calculate cosine without cos(x)","description":"Solve cos(x).\r\n\r\nThe use of the function cos() and sin() is not allowed.","description_html":"\u003cp\u003eSolve cos(x).\u003c/p\u003e\u003cp\u003eThe use of the function cos() and sin() is not allowed.\u003c/p\u003e","function_template":"function y = my_func(x)\r\n  y = cos(x);\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = 1;\r\nassert(abs(my_func(x)-y_correct)\u003c0.0001)\r\n\r\n%%\r\nx = pi/2;\r\ny_correct = 0;\r\nassert(abs(my_func(x)-y_correct)\u003c0.0001)\r\n\r\n%%\r\nx = rand(1)*2*pi;\r\ny_correct = cos(x);\r\nassert(abs(my_func(x)-y_correct)\u003c0.0001)\r\n\r\n%%\r\nassessFunctionAbsence({'sin','cos'}, 'FileName', 'my_func.m')\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":14644,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":127,"test_suite_updated_at":"2016-12-01T18:38:29.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-16T10:35:20.000Z","updated_at":"2026-05-24T16:48:13.000Z","published_at":"2016-10-16T10:42: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\u003eSolve cos(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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe use of the function cos() and sin() is not allowed.\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":2161,"title":"Let's get back to school, and create multiplication tables","description":"For a given range, create multiplication tables. (start is always \u003c endno)\r\n\r\nExample\r\n\r\n start = 17\r\n endno = 19\r\n\r\nThen, \r\n\r\n table = \r\n  [ 17    18    19\r\n    34    36    38\r\n    51    54    57\r\n    68    72    76\r\n    85    90    95\r\n   102   108   114\r\n   119   126   133\r\n   136   144   152\r\n   153   162   171\r\n   170   180   190 ]\r\n","description_html":"\u003cp\u003eFor a given range, create multiplication tables. (start is always \u0026lt; endno)\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e start = 17\r\n endno = 19\u003c/pre\u003e\u003cp\u003eThen,\u003c/p\u003e\u003cpre\u003e table = \r\n  [ 17    18    19\r\n    34    36    38\r\n    51    54    57\r\n    68    72    76\r\n    85    90    95\r\n   102   108   114\r\n   119   126   133\r\n   136   144   152\r\n   153   162   171\r\n   170   180   190 ]\u003c/pre\u003e","function_template":"function table= Tables(start, endno)\r\n  table = [start:endno];\r\nend","test_suite":"%%\r\nstart = 1;\r\nendno = 10;\r\ny_correct = [1     2     3     4     5     6     7     8     9    10;\r\n     2     4     6     8    10    12    14    16    18    20;\r\n     3     6     9    12    15    18    21    24    27    30;\r\n     4     8    12    16    20    24    28    32    36    40;\r\n     5    10    15    20    25    30    35    40    45    50;\r\n     6    12    18    24    30    36    42    48    54    60;\r\n     7    14    21    28    35    42    49    56    63    70;\r\n     8    16    24    32    40    48    56    64    72    80;\r\n     9    18    27    36    45    54    63    72    81    90;\r\n    10    20    30    40    50    60    70    80    90   100;];\r\nassert(isequal(Tables(start, endno),y_correct))\r\n\r\n%%\r\nstart = 17;\r\nendno = 19;\r\ny_correct = [17    18    19;\r\n    34    36    38;\r\n    51    54    57;\r\n    68    72    76;\r\n    85    90    95;\r\n   102   108   114;\r\n   119   126   133;\r\n   136   144   152;\r\n   153   162   171;\r\n   170   180   190;];\r\nassert(isequal(Tables(start, endno),y_correct))\r\n\r\n%%\r\nstart = 21;\r\nendno = 22;\r\n\r\ny_correct =[21    22;\r\n    42    44;\r\n    63    66;\r\n    84    88;\r\n   105   110;\r\n   126   132;\r\n   147   154;\r\n   168   176;\r\n   189   198;\r\n   210   220;]\r\nassert(isequal(Tables(start, endno),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":241,"test_suite_updated_at":"2014-02-06T17:58:19.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-02-06T17:45:15.000Z","updated_at":"2026-06-12T16:39:05.000Z","published_at":"2014-02-06T17:49: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\",\"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\u003eFor a given range, create multiplication tables. (start is always \u0026lt; endno)\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[ start = 17\\n endno = 19]]\u003e\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\u003eThen,\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[ table = \\n  [ 17    18    19\\n    34    36    38\\n    51    54    57\\n    68    72    76\\n    85    90    95\\n   102   108   114\\n   119   126   133\\n   136   144   152\\n   153   162   171\\n   170   180   190 ]]]\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":43283,"title":"Subtract integers and add doubles","description":"Create a function that subtracts a from b if a and b are integers and adds them if they are floats.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: normal; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; transform-origin: 332px 10.5px; vertical-align: baseline; perspective-origin: 332px 10.5px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 10.5px; white-space: pre-wrap; perspective-origin: 309px 10.5px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eCreate a function that subtracts b from a if a and b are integers and adds them if they are floats.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function c = intOrfloat(a, b)\r\n  if isinteger(a)\r\n      a = a + b;\r\n  else\r\n      a = a - b;\r\n  end\r\nend","test_suite":"%%\r\na = int8(1);\r\nb = int8(2);\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,-1))\r\n\r\n%%\r\na = 1;\r\nb = 2;\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,3))\r\n\r\n%%\r\na = uint8(1);\r\nb = uint8(2);\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,0))\r\n\r\n%%\r\na = int16(100);\r\nb = int16(200);\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,-100))\r\n\r\n%%\r\na = single(100);\r\nb = single(200);\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,300))","published":true,"deleted":false,"likes_count":4,"comments_count":4,"created_by":57323,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":132,"test_suite_updated_at":"2016-10-28T02:19:03.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-09T15:33:19.000Z","updated_at":"2026-05-24T16:46:16.000Z","published_at":"2016-10-09T15:33:19.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCreate a function that subtracts b from a if a and b are integers and adds them if they are floats.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1502,"title":"Perl 1: push","description":"_This is part of a series of perl function which were very helpful for many perl programmers. Could you implement it in Matlab?_\r\n \r\nPushes the values of list onto the end of the array and returns the number of elements in the new array. The output vector should be of the same type (column or row array) as the input vector x regardless of the list append type.\r\nExample:\r\n\r\n  x=[1 2 3 4 5]\r\n  [x, num]=push(x, [6 7 8])\r\n\r\nthen\r\n\r\n  x=[1 2 3 4 5 6 8]\r\n  [x, num]=8\r\n","description_html":"\u003cp\u003e\u003ci\u003eThis is part of a series of perl function which were very helpful for many perl programmers. Could you implement it in Matlab?\u003c/i\u003e\u003c/p\u003e\u003cp\u003ePushes the values of list onto the end of the array and returns the number of elements in the new array. The output vector should be of the same type (column or row array) as the input vector x regardless of the list append type.\r\nExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex=[1 2 3 4 5]\r\n[x, num]=push(x, [6 7 8])\r\n\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex=[1 2 3 4 5 6 8]\r\n[x, num]=8\r\n\u003c/pre\u003e","function_template":"function y=push(x, list)\r\n","test_suite":"%%\r\nx = [1 2 3 4 5];\r\ny = [6 7 8];\r\n[x, num] = push(x, y);\r\ny_correct = [1 2 3 4 5 6 7 8];\r\nnum_correct = 8;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));\r\n\r\n%%\r\nx = [1 2 3 4 5];\r\ny = 6;\r\n[x, num] = push(x, y);\r\ny_correct = [1 2 3 4 5 6];\r\nnum_correct = 6;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));\r\n\r\n%%\r\nx = [1 2 3 4 5]';\r\ny = [6 7 8];\r\n[x, num] = push(x, y);\r\ny_correct = [1 2 3 4 5 6 7 8]';\r\nnum_correct = 8;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));\r\n\r\n%%\r\nx = [];\r\ny = [1 2 3];\r\n[x, num] = push(x, y);\r\ny_correct = [1 2 3];\r\nnum_correct = 3;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));\r\n\r\n%%\r\nx = [0.5 8.4 9.6];\r\ny = [12.0 pi];\r\n[x, num] = push(x, y);\r\ny_correct = [0.5 8.4 9.6 12.0 pi];\r\nnum_correct = 5;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));","published":true,"deleted":false,"likes_count":0,"comments_count":4,"created_by":750,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":86,"test_suite_updated_at":"2013-05-13T15:04:49.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-05-12T13:28:10.000Z","updated_at":"2026-04-03T03:01:36.000Z","published_at":"2013-05-12T13:45:43.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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eThis is part of a series of perl function which were very helpful for many perl programmers. Could you implement it in Matlab?\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\u003ePushes the values of list onto the end of the array and returns the number of elements in the new array. The output vector should be of the same type (column or row array) as the input vector x regardless of the list append type. Example:\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=[1 2 3 4 5]\\n[x, num]=push(x, [6 7 8])]]\u003e\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\u003ethen\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=[1 2 3 4 5 6 8]\\n[x, num]=8]]\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":2499,"title":"Airline Ticket Mod7 Checksum ","description":"There are 13 digits in an airline ticket number. If an airline ticket number is valid, the 13th digit should be the remainder of division by seven of the first 12. \r\n\r\n\r\n\r\nWrite a function that returns true if a plane ticket number is valid and false otherwise.","description_html":"\u003cp\u003eThere are 13 digits in an airline ticket number. If an airline ticket number is valid, the 13th digit should be the remainder of division by seven of the first 12.\u003c/p\u003e\u003cp\u003eWrite a function that returns true if a plane ticket number is valid and false otherwise.\u003c/p\u003e","function_template":"function b = isTicketValid(T)\r\n\r\nend","test_suite":"%%\r\nT=1234567891011;\r\nb_correct=0;\r\nassert(isequal(isTicketValid(T),b_correct))\r\n%%\r\nT=2355211846932;\r\nb_correct=0;\r\nassert(isequal(isTicketValid(T),b_correct))\r\n%%\r\nT=2355211846934;\r\nb_correct=1;\r\nassert(isequal(isTicketValid(T),b_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":379,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":86,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-08-09T16:26:01.000Z","updated_at":"2026-04-03T02:48:52.000Z","published_at":"2014-08-09T16:26:01.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\u003eThere are 13 digits in an airline ticket number. If an airline ticket number is valid, the 13th digit should be the remainder of division by seven of the first 12.\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\u003eWrite a function that returns true if a plane ticket number is valid and false otherwise.\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":42775,"title":"Raise a polynomial to a power","description":"In Matlab, polynomials are represented by a vector of coefficients.  For example, the polynomial p=a*x^2 + b*x + c is represented by the vector p=[a, b, c].\r\n\r\nIn this problem, you will be given a polynomial p and a power N.  We would like you to return the vector q that represents the polynominal p^N, the Nth power of p.  If p = (x + 1), for instance, you will be returning the coefficients of (x+1)^N.  (N will be a positive integer greater than 0.)","description_html":"\u003cp\u003eIn Matlab, polynomials are represented by a vector of coefficients.  For example, the polynomial p=a*x^2 + b*x + c is represented by the vector p=[a, b, c].\u003c/p\u003e\u003cp\u003eIn this problem, you will be given a polynomial p and a power N.  We would like you to return the vector q that represents the polynominal p^N, the Nth power of p.  If p = (x + 1), for instance, you will be returning the coefficients of (x+1)^N.  (N will be a positive integer greater than 0.)\u003c/p\u003e","function_template":"function q = polypow(p,N)\r\n  q = p^N;   \r\nend","test_suite":"%%\r\np=[2];\r\nN=8;\r\ny_correct=256;\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=[1 1];\r\nN=1;\r\ny_correct=[1 1];\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=[1 1];\r\nN=5;\r\ny_correct=[1 5 10 10 5 1];\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=1:5;\r\nN=3;\r\ny_correct=[1 6 21 56 126 234 369 504 594 574 465 300 125];\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=5:-1:1;\r\nN=3;\r\ny_correct=[125 300 465 574 594 504 369 234 126 56 21 6 1];\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=5:-1:1;\r\nN=1;\r\ny_correct=[5 4 3 2 1];\r\nassert(isequal(polypow(p,N),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":8580,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":97,"test_suite_updated_at":"2016-03-16T17:46:50.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-03-16T17:30:45.000Z","updated_at":"2026-04-03T02:46:51.000Z","published_at":"2016-03-16T17:44: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\",\"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\u003eIn Matlab, polynomials are represented by a vector of coefficients. For example, the polynomial p=a*x^2 + b*x + c is represented by the vector p=[a, b, c].\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\u003eIn this problem, you will be given a polynomial p and a power N. We would like you to return the vector q that represents the polynominal p^N, the Nth power of p. If p = (x + 1), for instance, you will be returning the coefficients of (x+1)^N. (N will be a positive integer greater than 0.)\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":1344,"title":"Moving average (variable kernel length)","description":"Find the moving average in a vector. The kernel length is a variable.\r\nFor example \r\n\r\n x = 1:10\r\n kernel_length = 2 \r\n\r\nwould result in\r\n\r\n [ 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 ]\r\n\r\nand\r\n\r\n x = 1:10\r\n kernel_length = 3 \r\n\r\nwould result in\r\n\r\n [ 2 3 4 5 6 7 8 9 ]\r\n","description_html":"\u003cp\u003eFind the moving average in a vector. The kernel length is a variable.\r\nFor example\u003c/p\u003e\u003cpre\u003e x = 1:10\r\n kernel_length = 2 \u003c/pre\u003e\u003cp\u003ewould result in\u003c/p\u003e\u003cpre\u003e [ 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 ]\u003c/pre\u003e\u003cp\u003eand\u003c/p\u003e\u003cpre\u003e x = 1:10\r\n kernel_length = 3 \u003c/pre\u003e\u003cp\u003ewould result in\u003c/p\u003e\u003cpre\u003e [ 2 3 4 5 6 7 8 9 ]\u003c/pre\u003e","function_template":"function y = moving_avg(x,kernel_length)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1:10;\r\nkernel_length=4\r\ny_correct = [  2.5000    3.5000    4.5000    5.5000    6.5000    7.5000    8.5000];\r\nassert(isequal(moving_avg(x,kernel_length),y_correct))\r\n\r\n%%\r\n\r\nx = 10:20;\r\nkernel_length=5\r\ny_correct = [  12.0000   13.0000   14.0000   15.0000   16.0000   17.0000   18.0000];\r\nassert(isequal(moving_avg(x,kernel_length),y_correct))\r\n\r\n%%\r\nx = ones(1,10);\r\nkernel_length=5\r\ny_correct = ones(1,6);\r\nassert(isequal(moving_avg(x,kernel_length),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":1023,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":137,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-03-15T03:02:53.000Z","updated_at":"2026-04-03T03:14:22.000Z","published_at":"2013-03-15T03:02:52.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 moving average in a vector. The kernel length is a variable. For example\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 = 1:10\\n kernel_length = 2]]\u003e\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\u003ewould result in\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[ [ 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 ]]]\u003e\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\u003eand\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 = 1:10\\n kernel_length = 3]]\u003e\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\u003ewould result in\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[ [ 2 3 4 5 6 7 8 9 ]]]\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":2240,"title":"Sum the 'edge' values of a matrix","description":"Sum the 'edge' values of an input matrix (the values along the perimeter).\r\n\r\nExample\r\n\r\n [1 2 3\r\n  4 5 6\r\n  7 8 9]\r\n\r\nOutput = 1 + 2 + 3 + 6 + 9 + 8 + 7 + 4 = 40;\r\n\r\nAssumption: Input matrix equal or bigger than 3x3.","description_html":"\u003cp\u003eSum the 'edge' values of an input matrix (the values along the perimeter).\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e [1 2 3\r\n  4 5 6\r\n  7 8 9]\u003c/pre\u003e\u003cp\u003eOutput = 1 + 2 + 3 + 6 + 9 + 8 + 7 + 4 = 40;\u003c/p\u003e\u003cp\u003eAssumption: Input matrix equal or bigger than 3x3.\u003c/p\u003e","function_template":"function y = AddMatrixLim(x)\r\n %add code\r\nend","test_suite":"%%\r\nx = [1 2 3; 4 5 6;7 8 9];\r\ny_correct = 40;\r\nassert(isequal(AddMatrixLim(x),y_correct))\r\n\r\n%%\r\nx= [1 5 6 7; 4 9 4 7; 9 4 2 1; 0 1 2 8]\r\ny_correct = 51;\r\nassert(isequal(AddMatrixLim(x),y_correct))","published":true,"deleted":false,"likes_count":8,"comments_count":0,"created_by":24008,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":405,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-09T13:39:17.000Z","updated_at":"2026-07-02T12:24:46.000Z","published_at":"2014-03-09T13:39: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\u003eSum the 'edge' values of an input matrix (the values along the perimeter).\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[ [1 2 3\\n  4 5 6\\n  7 8 9]]]\u003e\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\u003eOutput = 1 + 2 + 3 + 6 + 9 + 8 + 7 + 4 = 40;\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\u003eAssumption: Input matrix equal or bigger than 3x3.\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\"}]}"}],"errors":[],"facets":[[{"value":"Operations","count":10,"selected":true},{"value":"Magic Numbers IV","count":1,"selected":false}],[{"value":"easy","count":10,"selected":true}]],"term":"difficulty_rating_bin:easy group:Operations","page":1,"per_page":50,"sort":"map(difficulty_value,0,0,999) asc"}}