{"group":{"group":{"id":63,"name":"Linear Algebra","lockable":false,"created_at":"2019-11-19T20:33:44.000Z","updated_at":"2026-04-06T14:01:22.000Z","description":"Something at which MATLAB excels.","is_default":false,"created_by":26769,"badge_id":62,"featured":false,"trending":false,"solution_count_in_trending_period":24,"trending_last_calculated":"2026-04-06T00:00:00.000Z","image_id":563,"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":"{\"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\u003eSomething at which MATLAB excels.\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\"}]}","description_html":"\u003cdiv style = \"text-align: start; line-height: 16px; 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; perspective-origin: 289.5px 10.5px; transform-origin: 289.5px 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; perspective-origin: 266.5px 10.5px; text-align: left; transform-origin: 266.5px 10.5px; white-space: pre-wrap; 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; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eSomething at which MATLAB excels.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","published_at":"2019-11-20T18:46:26.000Z"},"current_player":null},"problems":[{"id":389,"title":"Column norms of a matrix","description":"Given a matrix M, return a vector y such that for each k\r\n\r\n    y(k)=norm(M(:,k))\r\n\r\n(y(k) is the Euclidean norm of the k-th column of M)\r\n\r\nEDIT: changed the test case so that proper handling of complex values is required.","description_html":"\u003cp\u003eGiven a matrix M, return a vector y such that for each k\u003c/p\u003e\u003cpre\u003e    y(k)=norm(M(:,k))\u003c/pre\u003e\u003cp\u003e(y(k) is the Euclidean norm of the k-th column of M)\u003c/p\u003e\u003cp\u003eEDIT: changed the test case so that proper handling of complex values is required.\u003c/p\u003e","function_template":"function y = your_fcn_name(M)\r\n  y = M;\r\nend","test_suite":"%%\r\nM = [1 2 3; 4 5 6; 7 8 9+2i];\r\nfor k=1:size(M,2)\r\n  y_correct(k)=norm(M(:,k));\r\nend\r\nassert(isequal(your_fcn_name(M),y_correct))\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":1,"created_by":1258,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":569,"test_suite_updated_at":"2012-02-24T14:50:55.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-02-23T09:33:39.000Z","updated_at":"2026-03-29T18:47:57.000Z","published_at":"2012-02-24T14:50: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=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix M, return a vector y such that for each k\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[    y(k)=norm(M(:,k))]]\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\u003e(y(k) is the Euclidean norm of the k-th column of M)\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\u003eEDIT: changed the test case so that proper handling of complex values is required.\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":258,"title":"linear least squares fitting","description":"Inputs:\r\n\r\n* |f|: cell-array of function handles\r\n* |x|: column vector of |x| values\r\n* |y|: column vector of |y| values, same length as |x|\r\n\r\nOutput:\r\n\r\n* |a|: column vector of coefficients, same length as |f|\r\n\r\nIn a correct answer the coefficients |a| take values such that the function\r\n\r\n   fit = @(x) a(1)*f{1}(x) + a(2)*f{2}(x) + a(3)*f{3}(x) +...+ a(end)*f{end}(x)\r\n\r\nminimizes the sum of the squared deviations between |fit(x)| and |y|, i.e.\r\n    sum((fit(x)-y).^2)\r\nis minimal. \r\n\r\nRemarks:\r\n\r\n* The functions will all be vectorized, so e.g. |f{1}(x)| will return results for the whole vector x\r\n* The absolute errors of |a| must be smaller than 1e-6 to pass the tests","description_html":"\u003cp\u003eInputs:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ef\u003c/tt\u003e: cell-array of function handles\u003c/li\u003e\u003cli\u003e\u003ctt\u003ex\u003c/tt\u003e: column vector of \u003ctt\u003ex\u003c/tt\u003e values\u003c/li\u003e\u003cli\u003e\u003ctt\u003ey\u003c/tt\u003e: column vector of \u003ctt\u003ey\u003c/tt\u003e values, same length as \u003ctt\u003ex\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eOutput:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ea\u003c/tt\u003e: column vector of coefficients, same length as \u003ctt\u003ef\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIn a correct answer the coefficients \u003ctt\u003ea\u003c/tt\u003e take values such that the function\u003c/p\u003e\u003cpre\u003e   fit = @(x) a(1)*f{1}(x) + a(2)*f{2}(x) + a(3)*f{3}(x) +...+ a(end)*f{end}(x)\u003c/pre\u003e\u003cp\u003eminimizes the sum of the squared deviations between \u003ctt\u003efit(x)\u003c/tt\u003e and \u003ctt\u003ey\u003c/tt\u003e, i.e.\r\n    sum((fit(x)-y).^2)\r\nis minimal.\u003c/p\u003e\u003cp\u003eRemarks:\u003c/p\u003e\u003cul\u003e\u003cli\u003eThe functions will all be vectorized, so e.g. \u003ctt\u003ef{1}(x)\u003c/tt\u003e will return results for the whole vector x\u003c/li\u003e\u003cli\u003eThe absolute errors of \u003ctt\u003ea\u003c/tt\u003e must be smaller than 1e-6 to pass the tests\u003c/li\u003e\u003c/ul\u003e","function_template":"function a = fit_coefficients(f,x,y)\r\n  a = zeros(length(f),1);\r\nend","test_suite":"%%% first test: fit to a constant\r\nx = [1,2,3,4]';\r\ny = rand(4,1);\r\nf{1} = @(x) ones(size(x));\r\naref=mean(y);\r\nassert(norm(fit_coefficients(f,x,y)-aref)\u003c1e-6)\r\n\r\n%%% second test: fit to a straight line (linear regression)\r\nx = [1,2,3,4,5]' + randn(5,1);\r\ny = [1,2,3,4,5]' + randn(5,1);\r\nf{1} = @(x) ones(size(x));\r\nf{2} = @(x) x;\r\naref(2) = sum((x-mean(x)).*(y-mean(y)))/sum((x-mean(x)).^2);\r\naref(1) = mean(y)-aref(2)*mean(x);\r\nassert(norm(fit_coefficients(f,x,y)-aref')\u003c1e-6)\r\n\r\n%%% third test: polynomial fit\r\nx = [1:15]' + randn(15,1);\r\ny = -10+0.2*x-0.5*x.^2+0.4*x.^3+0.001*log(abs(x)) + 0.2*randn(15,1);\r\nf{1} = @(x) ones(size(x));\r\nf{2} = @(x) x;\r\nf{3} = @(x) x.^2;\r\nf{4} = @(x) x.^3;\r\naref = fliplr(polyfit(x,y,3));\r\nassert(norm(fit_coefficients(f,x,y)-aref')\u003c1e-6)\r\n\r\n%%% fourth test: non-polynomial fit (yes, we are that crazy)\r\nx = [0:0.1:2*pi]';\r\ny = 0.123 + 0.456*sin(x).*exp(0.1*x);\r\nf{1} = @(x) ones(size(x));\r\nf{2} = @(x) sin(x).*exp(0.1*x);\r\naref=[0.123 0.456]';\r\nassert(norm(fit_coefficients(f,x,y)-aref)\u003c1e-6)","published":true,"deleted":false,"likes_count":5,"comments_count":6,"created_by":203,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":164,"test_suite_updated_at":"2013-01-10T10:23:17.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-02-04T19:59:00.000Z","updated_at":"2026-04-09T07:07:16.000Z","published_at":"2013-01-09T22:29:23.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\u003eInputs:\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: cell-array of function handles\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: column vector of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e values\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: column vector of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e values, same length as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\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:\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: column vector of coefficients, same length as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef\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\u003eIn a correct answer the coefficients\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e take values such that the function\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[   fit = @(x) a(1)*f{1}(x) + a(2)*f{2}(x) + a(3)*f{3}(x) +...+ a(end)*f{end}(x)]]\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\u003eminimizes the sum of the squared deviations between\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003efit(x)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, i.e. sum((fit(x)-y).^2) is minimal.\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\u003eRemarks:\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\u003eThe functions will all be vectorized, so e.g.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef{1}(x)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e will return results for the whole vector x\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\u003eThe absolute errors of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e must be smaller than 1e-6 to pass the tests\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":423,"title":"System of equations","description":"Find a solution to a system of equations represented by a |n| by |n+1| matrix. For instance,\r\n\r\n  \r\n [ 2 0 4;   =\u003e   2*x = 4 \r\n   2 4 8 ]       2*x + 4*y = 8\r\n\r\n\r\nTherefore, when given a=[2 0 4; 2 4 8] you should return a vector of solutions, v = [ 2 1 ]. Assume the system will always have a solution.","description_html":"\u003cp\u003eFind a solution to a system of equations represented by a \u003ctt\u003en\u003c/tt\u003e by \u003ctt\u003en+1\u003c/tt\u003e matrix. For instance,\u003c/p\u003e\u003cpre\u003e [ 2 0 4;   =\u003e   2*x = 4 \r\n   2 4 8 ]       2*x + 4*y = 8\u003c/pre\u003e\u003cp\u003eTherefore, when given a=[2 0 4; 2 4 8] you should return a vector of solutions, v = [ 2 1 ]. Assume the system will always have a solution.\u003c/p\u003e","function_template":"function v = system_eq(a)\r\n  v=a;\r\nend","test_suite":"%%\r\na=[2 0 4; 2 4 8];\r\ny_correct = [ 2   1 ];\r\nassert(isequal(system_eq(a),y_correct))\r\n\r\n%%\r\na=[1 -1 2 21; 0 2 5 21; 4 0 -3 21];\r\ny_correct =  [ 9 -2 5 ];\r\nassert(isequal(system_eq(a),y_correct))\r\n\r\n%%\r\na=[ 3 3 0 6; 5 -7 1 -9; 9 3 -2 26];\r\ny_correct = [1 1 -7];\r\nassert(isequal(system_eq(a),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":3,"created_by":658,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":414,"test_suite_updated_at":"2012-02-29T02:24:12.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-02-28T21:03:20.000Z","updated_at":"2026-03-29T20:45:46.000Z","published_at":"2012-02-29T21:27:45.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 a solution to a system of equations represented by a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e by\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en+1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix. For instance,\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 0 4;   =\u003e   2*x = 4 \\n   2 4 8 ]       2*x + 4*y = 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\u003eTherefore, when given a=[2 0 4; 2 4 8] you should return a vector of solutions, v = [ 2 1 ]. Assume the system will always have a solution.\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":42988,"title":"Linear system of equations","description":"Solve the system of equations in three variables.","description_html":"\u003cp\u003eSolve the system of equations in three variables.\u003c/p\u003e","function_template":"function y = lin_eqns(A,b)\r\n  y = b;\r\nend","test_suite":"%%\r\nA=[1 1 1;2 4 8;3 9 27];\r\nb=[1;2;3];\r\ny_correct = [1;0;0];\r\ntol = 1e-14;\r\nassert(norm(lin_eqns(A,b)-y_correct) \u003c tol)\r\n\r\n%%\r\nA=[2 1 -2;1 -1 -1;1 1 3];\r\nb=[3;0;12];\r\ny_correct = [3.5;1;2.5];\r\ntol = 1e-14;\r\nassert(norm(lin_eqns(A,b)-y_correct) \u003c tol)\r\n\r\n%%\r\nA=[1 0 0;0 1 0;0 0 1];\r\nb=[1e6;1e7;1e8];\r\ny_correct = [1e6;1e7;1e8];\r\ntol = 1e-9;\r\nassert(norm(lin_eqns(A,b)-y_correct) \u003c tol)\r\n\r\n%%\r\nA=[1 0 1;0 -3 1;2 1 3];\r\nb=[6;7;15];\r\ny_correct = [2;-1;4];\r\ntol = 1e-14;\r\nassert(norm(lin_eqns(A,b)-y_correct) \u003c tol)\r\n","published":true,"deleted":false,"likes_count":13,"comments_count":1,"created_by":91311,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":468,"test_suite_updated_at":"2016-10-02T01:16:37.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2016-09-19T10:00:24.000Z","updated_at":"2026-03-29T20:48:31.000Z","published_at":"2016-09-19T10:00:24.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 the system of equations in three variables.\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":446,"title":"Solve the set of simultaneous linear equations ","description":"Given this pair of simultaneous linear equations:\r\n\r\n2x + 3y = 23\r\n\r\n3x + 4y = 32\r\n\r\nFind the solution set (x,y)","description_html":"\u003cp\u003eGiven this pair of simultaneous linear equations:\u003c/p\u003e\u003cp\u003e2x + 3y = 23\u003c/p\u003e\u003cp\u003e3x + 4y = 32\u003c/p\u003e\u003cp\u003eFind the solution set (x,y)\u003c/p\u003e","function_template":"function x = solveSimul(A,b)\r\n  x = A + b;\r\nend","test_suite":"%% test 1\r\nA = [2 3; 3 4]; b = [23; 32];\r\nx_correct = [4;5];\r\nassert(isequal(solveSimul(A,b),x_correct))\r\n\r\n%% test 2\r\nA = [2 3; 3 4]; b = [23; 36];\r\nx_correct = [16;-3];\r\nassert(isequal(solveSimul(A,b),x_correct))\r\n\r\n%% test 3\r\nA = [2 3; 3 4]; b = [23; 43];\r\nx_correct = [37;-17];\r\nassert(isequal(solveSimul(A,b),x_correct))\r\n\r\n%% test 4\r\nA = [2 3; 3 4]; b = [23; 49];\r\nx_correct = [55;-29];\r\nassert(isequal(solveSimul(A,b),x_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":1103,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":504,"test_suite_updated_at":"2012-03-17T22:41:43.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-03-04T08:34:50.000Z","updated_at":"2026-03-29T20:51:21.000Z","published_at":"2012-03-17T22:42: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\u003eGiven this pair of simultaneous linear equations:\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\u003e2x + 3y = 23\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\u003e3x + 4y = 32\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\u003eFind the solution set (x,y)\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":42382,"title":"Combined Ages 1 - Symmetric, n = 3","description":"You have probably seen the common riddle wherein combined ages are provided and you must determine the individual ages. For example: If the ages of Alex and Barry sum to 43, the ages of Alex and Chris sum to 55, and the ages of Barry and Chris sum to 66, what are their individual ages?\r\n\r\nFor this problem, we'll assume that the three individuals are represented by A, B, and C, whereas the sums are AB, AC, and BC:\r\n\r\n* A+B = AB (= 43)\r\n* A+C = AC (= 55)\r\n* B+C = BC (= 66)\r\n\r\nAs you might have noticed, this is a simple matrix algebra problem. Write a function to return the individuals' ages [A;B;C] based on the supplied sums [AB AC BC].","description_html":"\u003cp\u003eYou have probably seen the common riddle wherein combined ages are provided and you must determine the individual ages. For example: If the ages of Alex and Barry sum to 43, the ages of Alex and Chris sum to 55, and the ages of Barry and Chris sum to 66, what are their individual ages?\u003c/p\u003e\u003cp\u003eFor this problem, we'll assume that the three individuals are represented by A, B, and C, whereas the sums are AB, AC, and BC:\u003c/p\u003e\u003cul\u003e\u003cli\u003eA+B = AB (= 43)\u003c/li\u003e\u003cli\u003eA+C = AC (= 55)\u003c/li\u003e\u003cli\u003eB+C = BC (= 66)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eAs you might have noticed, this is a simple matrix algebra problem. Write a function to return the individuals' ages [A;B;C] based on the supplied sums [AB AC BC].\u003c/p\u003e","function_template":"function y = combined_ages(AB,BC,AC)\r\n y = [1;1;1];\r\nend","test_suite":"%%\r\nAB = 43;\r\nBC = 55;\r\nAC = 66;\r\ny = combined_ages(AB,BC,AC);\r\ny_correct = [27 16 39];\r\nfor i = 1:3\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nAB = 30;\r\nBC = 50;\r\nAC = 40;\r\ny = combined_ages(AB,BC,AC);\r\ny_correct = [10 20 30];\r\nfor i = 1:3\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nAB = 20;\r\nBC = 70;\r\nAC = 60;\r\ny = combined_ages(AB,BC,AC);\r\ny_correct = [5 15 55];\r\nfor i = 1:3\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nAB = 34;\r\nBC = 84;\r\nAC = 56;\r\ny = combined_ages(AB,BC,AC);\r\ny_correct = [3 31 53];\r\nfor i = 1:3\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\ny_correct = [2 11 21];\r\nAB = y_correct(1) + y_correct(2);\r\nBC = y_correct(2) + y_correct(3);\r\nAC = y_correct(1) + y_correct(3);\r\ny = combined_ages(AB,BC,AC);\r\nfor i = 1:3\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\ny_correct = [11 17 21];\r\nAB = y_correct(1) + y_correct(2);\r\nBC = y_correct(2) + y_correct(3);\r\nAC = y_correct(1) + y_correct(3);\r\ny = combined_ages(AB,BC,AC);\r\nfor i = 1:3\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\ny_correct = [15 35 55];\r\nAB = y_correct(1) + y_correct(2);\r\nBC = y_correct(2) + y_correct(3);\r\nAC = y_correct(1) + y_correct(3);\r\ny = combined_ages(AB,BC,AC);\r\nfor i = 1:3\r\n assert(isequal(y(i),y_correct(i)))\r\nend","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":326,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-06-16T17:30:16.000Z","updated_at":"2026-03-29T20:59:40.000Z","published_at":"2015-06-16T17:30:16.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\u003eYou have probably seen the common riddle wherein combined ages are provided and you must determine the individual ages. For example: If the ages of Alex and Barry sum to 43, the ages of Alex and Chris sum to 55, and the ages of Barry and Chris sum to 66, what are their individual ages?\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\u003eFor this problem, we'll assume that the three individuals are represented by A, B, and C, whereas the sums are AB, AC, and BC:\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\u003eA+B = AB (= 43)\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\u003eA+C = AC (= 55)\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\u003eB+C = BC (= 66)\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\u003eAs you might have noticed, this is a simple matrix algebra problem. Write a function to return the individuals' ages [A;B;C] based on the supplied sums [AB AC BC].\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":42384,"title":"Combined Ages 2 - Symmetric, n ≥ 3","description":"Following on \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42382-combined-ages-1-symmetric-n-3 Combined Ages 2\u003e, you will now be provided with age sums for _n_ individuals where _n_ ≥ 3. The sums will be provided in sorted order and will be for _n–1_ individuals (e.g., A+B+C, A+B+D, A+C+D, B+C+D). See the previous problem for an explanation, the test suite for examples, and the problem tags for hints.","description_html":"\u003cp\u003eFollowing on \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42382-combined-ages-1-symmetric-n-3\"\u003eCombined Ages 2\u003c/a\u003e, you will now be provided with age sums for \u003ci\u003en\u003c/i\u003e individuals where \u003ci\u003en\u003c/i\u003e ≥ 3. The sums will be provided in sorted order and will be for \u003ci\u003en–1\u003c/i\u003e individuals (e.g., A+B+C, A+B+D, A+C+D, B+C+D). See the previous problem for an explanation, the test suite for examples, and the problem tags for hints.\u003c/p\u003e","function_template":"function y = combined_ages2(varargin)\r\n y = ones(nargin,1);\r\nend","test_suite":"%%\r\nAB = 43;\r\nAC = 66;\r\nBC = 55;\r\ny = combined_ages2(AB,AC,BC);\r\ny_correct = [27 16 39];\r\nfor i = 1:numel(y_correct)\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nAB = 30;\r\nAC = 40;\r\nBC = 50;\r\ny = combined_ages2(AB,AC,BC);\r\ny_correct = [10 20 30];\r\nfor i = 1:numel(y_correct)\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABC = 72;\r\nABD = 66;\r\nACD = 70;\r\nBCD = 77;\r\ny = combined_ages2(ABC,ABD,ACD,BCD);\r\ny_correct = [18 25 29 23];\r\nfor i = 1:numel(y_correct)\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABC = 66;\r\nABD = 67;\r\nACD = 68;\r\nBCD = 69;\r\ny = combined_ages2(ABC,ABD,ACD,BCD);\r\ny_correct = [21 22 23 24];\r\nfor i = 1:numel(y_correct)\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABC = 60;\r\nABD = 65;\r\nACD = 70;\r\nBCD = 75;\r\ny = combined_ages2(ABC,ABD,ACD,BCD);\r\ny_correct = [15 20 25 30];\r\nfor i = 1:numel(y_correct)\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABCD = 90;\r\nABCE = 115;\r\nABDE = 100;\r\nACDE = 110;\r\nBCDE = 105;\r\ny = combined_ages2(ABCD,ABCE,ABDE,ACDE,BCDE);\r\ny_correct = [25 20 30 15 40];\r\nfor i = 1:numel(y_correct)\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABCD = 44;\r\nABCE = 37;\r\nABDE = 47;\r\nACDE = 51;\r\nBCDE = 53;\r\ny = combined_ages2(ABCD,ABCE,ABDE,ACDE,BCDE);\r\ny_correct = [5 7 11 21 14];\r\nfor i = 1:numel(y_correct)\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABCDEF = 133;\r\nABCDEG = 186;\r\nABCDFG = 172;\r\nABCEFG = 163;\r\nABDEFG = 192;\r\nACDEFG = 200;\r\nBCDEFG = 184;\r\ny = combined_ages2(ABCDEF,ABCDEG,ABCDFG,ABCEFG,ABDEFG,ACDEFG,BCDEFG);\r\ny_correct = [21 5 13 42 33 19 72];\r\nfor i = 1:numel(y_correct)\r\n assert(isequal(y(i),y_correct(i)))\r\nend\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":183,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-06-16T19:13:14.000Z","updated_at":"2026-03-29T21:29:20.000Z","published_at":"2015-06-16T19:13:14.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\u003eFollowing on\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42382-combined-ages-1-symmetric-n-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCombined Ages 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, you will now be provided with age sums for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e individuals where\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ≥ 3. The sums will be provided in sorted order and will be for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en–1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e individuals (e.g., A+B+C, A+B+D, A+C+D, B+C+D). See the previous problem for an explanation, the test suite for examples, and the problem tags for hints.\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":42383,"title":"Combined Ages 3 - Non-symmetric, n ≥ 3","description":"Pursuant to the previous two problems ( \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42382-combined-ages-1-symmetric-n-3 Symmetric, n = 3\u003e and \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42384-combined-ages-2-symmetric-n-3 Symmetric, n ≥ 3\u003e ), this problem will provide _n_ combined ages where _n_ is the number of individuals, though the age sums will not form a symmetric matrix. As an example: If the ages of all four individuals sum to 70; the ages of Alex, Barry, and Chris sum to 65; the ages of Alex and Barry sum to 40; and the ages of Barry and Chris sum to 52, what are their individual ages?\r\n\r\nThe individuals will be represented by the first _n_ capital letters of the alphabet and the sums will be represented by variables whose string names contain each associated individual (capital letter). In this example problem, the equations would be represented as:\r\n\r\n* A+B+C+D = ABCD (= 70)\r\n* A+B+C = ABC (= 65)\r\n* A+B = AB (= 40)\r\n* B+C = BC (= 52)\r\n\r\nWrite a function to return the individuals' ages based on the supplied sums. See the test suite for examples and the tags for some hints.","description_html":"\u003cp\u003ePursuant to the previous two problems ( \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42382-combined-ages-1-symmetric-n-3\"\u003eSymmetric, n = 3\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42384-combined-ages-2-symmetric-n-3\"\u003eSymmetric, n ≥ 3\u003c/a\u003e ), this problem will provide \u003ci\u003en\u003c/i\u003e combined ages where \u003ci\u003en\u003c/i\u003e is the number of individuals, though the age sums will not form a symmetric matrix. As an example: If the ages of all four individuals sum to 70; the ages of Alex, Barry, and Chris sum to 65; the ages of Alex and Barry sum to 40; and the ages of Barry and Chris sum to 52, what are their individual ages?\u003c/p\u003e\u003cp\u003eThe individuals will be represented by the first \u003ci\u003en\u003c/i\u003e capital letters of the alphabet and the sums will be represented by variables whose string names contain each associated individual (capital letter). In this example problem, the equations would be represented as:\u003c/p\u003e\u003cul\u003e\u003cli\u003eA+B+C+D = ABCD (= 70)\u003c/li\u003e\u003cli\u003eA+B+C = ABC (= 65)\u003c/li\u003e\u003cli\u003eA+B = AB (= 40)\u003c/li\u003e\u003cli\u003eB+C = BC (= 52)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eWrite a function to return the individuals' ages based on the supplied sums. See the test suite for examples and the tags for some hints.\u003c/p\u003e","function_template":"function y = combined_ages_nonsymmetric(varargin)\r\n y = ones(nargin,1);\r\nend","test_suite":"%%\r\nABCD = 70;\r\nABC = 65;\r\nAB = 40;\r\nBC = 52;\r\ny = combined_ages_nonsymmetric(ABCD,ABC,AB,BC);\r\ny_correct = [13;27;25;5];\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABC = 70;\r\nBC = 50;\r\nAC = 40;\r\ny = combined_ages_nonsymmetric(ABC,BC,AC);\r\ny_correct = [20;30;20];\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABCD = 100;\r\nABC = 80;\r\nBCD = 70;\r\nABD = 60;\r\ny = combined_ages_nonsymmetric(ABCD,ABC,BCD,ABD);\r\ny_correct = [30;10;40;20];\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nAB = 34;\r\nBC = 54;\r\nABC = 86;\r\ny = combined_ages_nonsymmetric(AB,BC,ABC);\r\ny_correct = [32;2;52];\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABCDE = 120;\r\nABCD = 78;\r\nABC = 45;\r\nAB = 24;\r\nAC = 31;\r\ny = combined_ages_nonsymmetric(ABCDE,ABCD,ABC,AB,AC);\r\ny_correct = [10,14,21,33,42];\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\ny_correct = [37 33 31 38];\r\nABC = y_correct(1) + y_correct(2) + y_correct(3);\r\nBCD = y_correct(2) + y_correct(3) + y_correct(4);\r\nACD = y_correct(1) + y_correct(3) + y_correct(4);\r\nABD = y_correct(1) + y_correct(2) + y_correct(4);\r\ny = combined_ages_nonsymmetric(ABC,BCD,ACD,ABD);\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\ny_correct = [5 15 30 62 100];\r\nAB = y_correct(1) + y_correct(2);\r\nBC = y_correct(2) + y_correct(3);\r\nAC = y_correct(1) + y_correct(3);\r\nACE = y_correct(1) + y_correct(3) + y_correct(5);\r\nABDE = y_correct(1) + y_correct(2) + y_correct(4) + y_correct(5);\r\ny = combined_ages_nonsymmetric(AB,BC,AC,ACE,ABDE);\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\ny_correct = [2 3 5 7 11 17 23 31 42 55];\r\nAB = y_correct(1) + y_correct(2);\r\nBC = y_correct(2) + y_correct(3);\r\nAC = y_correct(1) + y_correct(3);\r\nABCD = y_correct(1) + y_correct(2) + y_correct(3) + y_correct(4);\r\nCDEG = y_correct(3) + y_correct(4) + y_correct(5) + y_correct(7);\r\nBFH = y_correct(2) + y_correct(6) + y_correct(8);\r\nFGIJ = y_correct(6) + y_correct(7) + y_correct(9) + y_correct(10);\r\nACEGH = y_correct(1) + y_correct(3) + y_correct(5) + y_correct(7) + y_correct(8);\r\nBEJ = y_correct(2) + y_correct(5) + y_correct(10);\r\nABDIJ = y_correct(1) + y_correct(2) + y_correct(4) + y_correct(9) + y_correct(10);\r\ny = combined_ages_nonsymmetric(AB,BC,AC,ABCD,CDEG,BFH,FGIJ,ACEGH,BEJ,ABDIJ);\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tABCD = 70;\r\n\t\tABC = 65;\r\n\t\tAB = 40;\r\n\t\tBC = 52;\r\n\t\ty = combined_ages_nonsymmetric(ABCD,ABC,AB,BC);\r\n\t\ty_correct = [13;27;25;5];\r\n\tcase 2\r\n\t\tABCD = 100;\r\n\t\tABC = 80;\r\n\t\tBCD = 70;\r\n\t\tABD = 60;\r\n\t\ty = combined_ages_nonsymmetric(ABCD,ABC,BCD,ABD);\r\n\t\ty_correct = [30;10;40;20];\r\n\tcase 3\r\n\t\tAB = 34;\r\n\t\tBC = 54;\r\n\t\tABC = 86;\r\n\t\ty = combined_ages_nonsymmetric(AB,BC,ABC);\r\n\t\ty_correct = [32;2;52];\r\n\tcase 4\r\n\t\tABC = 70;\r\n\t\tBC = 50;\r\n\t\tAC = 40;\r\n\t\ty = combined_ages_nonsymmetric(ABC,BC,AC);\r\n\t\ty_correct = [20;30;20];\r\nend\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tABC = 70;\r\n\t\tBC = 50;\r\n\t\tAC = 40;\r\n\t\ty = combined_ages_nonsymmetric(ABC,BC,AC);\r\n\t\ty_correct = [20;30;20];\r\n\tcase 2\r\n\t\tAB = 34;\r\n\t\tBC = 54;\r\n\t\tABC = 86;\r\n\t\ty = combined_ages_nonsymmetric(AB,BC,ABC);\r\n\t\ty_correct = [32;2;52];\r\n\tcase 3\r\n\t\tABCD = 70;\r\n\t\tABC = 65;\r\n\t\tAB = 40;\r\n\t\tBC = 52;\r\n\t\ty = combined_ages_nonsymmetric(ABCD,ABC,AB,BC);\r\n\t\ty_correct = [13;27;25;5];\r\n\tcase 4\r\n\t\tABCD = 100;\r\n\t\tABC = 80;\r\n\t\tBCD = 70;\r\n\t\tABD = 60;\r\n\t\ty = combined_ages_nonsymmetric(ABCD,ABC,BCD,ABD);\r\n\t\ty_correct = [30;10;40;20];\r\nend\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tAB = 34;\r\n\t\tBC = 54;\r\n\t\tABC = 86;\r\n\t\ty = combined_ages_nonsymmetric(AB,BC,ABC);\r\n\t\ty_correct = [32;2;52];\r\n\tcase 2\r\n\t\tABCD = 100;\r\n\t\tABC = 80;\r\n\t\tBCD = 70;\r\n\t\tABD = 60;\r\n\t\ty = combined_ages_nonsymmetric(ABCD,ABC,BCD,ABD);\r\n\t\ty_correct = [30;10;40;20];\r\n\tcase 3\r\n\t\tABCD = 70;\r\n\t\tABC = 65;\r\n\t\tAB = 40;\r\n\t\tBC = 52;\r\n\t\ty = combined_ages_nonsymmetric(ABCD,ABC,AB,BC);\r\n\t\ty_correct = [13;27;25;5];\r\n\tcase 4\r\n\t\tABC = 70;\r\n\t\tBC = 50;\r\n\t\tAC = 40;\r\n\t\ty = combined_ages_nonsymmetric(ABC,BC,AC);\r\n\t\ty_correct = [20;30;20];\r\nend\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":144,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-06-16T18:34:18.000Z","updated_at":"2026-03-29T22:25:18.000Z","published_at":"2015-06-16T18:34:18.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\u003ePursuant to the previous two problems (\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42382-combined-ages-1-symmetric-n-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSymmetric, n = 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42384-combined-ages-2-symmetric-n-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSymmetric, n ≥ 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e ), this problem will provide\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e combined ages where\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is the number of individuals, though the age sums will not form a symmetric matrix. As an example: If the ages of all four individuals sum to 70; the ages of Alex, Barry, and Chris sum to 65; the ages of Alex and Barry sum to 40; and the ages of Barry and Chris sum to 52, what are their individual ages?\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 individuals will be represented by the first\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e capital letters of the alphabet and the sums will be represented by variables whose string names contain each associated individual (capital letter). In this example problem, the equations would be represented as:\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\u003eA+B+C+D = ABCD (= 70)\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\u003eA+B+C = ABC (= 65)\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\u003eA+B = AB (= 40)\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\u003eB+C = BC (= 52)\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\u003eWrite a function to return the individuals' ages based on the supplied sums. See the test suite for examples and the tags for some hints.\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":42385,"title":"Combined Ages 4 - Non-symmetric with multiples, n ≥ 3","description":"This problem is slightly more difficult than \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42383-combined-ages-3-non-symmetric-n-3 Combined Ages 3\u003e. In this case, some of the sums may include multiples of some individuals' ages. As an example: If the ages of all three individuals with Chris's age added again sum to 98, the ages of Barry (twice) and Chris sum to 84, and the ages of Alex (twice) and Barry sum to 70, what are their individual ages?\r\n\r\nThe individuals will be represented by the first n capital letters of the alphabet and the sums will be represented by variables whose string names contain each associated individual (capital letter). In this example problem, the equations would be represented as:\r\n\r\n* A+B+C+C = ABCC (= 98)\r\n* B+B+C = BBC (= 84)\r\n* A+A+B = AAB (= 70)\r\n\r\nThough the variables are ordered above, they will not always be in the test cases. Write a function to return the individuals' ages based on the supplied sums. See the test suite for examples and the tags for some hints.","description_html":"\u003cp\u003eThis problem is slightly more difficult than \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42383-combined-ages-3-non-symmetric-n-3\"\u003eCombined Ages 3\u003c/a\u003e. In this case, some of the sums may include multiples of some individuals' ages. As an example: If the ages of all three individuals with Chris's age added again sum to 98, the ages of Barry (twice) and Chris sum to 84, and the ages of Alex (twice) and Barry sum to 70, what are their individual ages?\u003c/p\u003e\u003cp\u003eThe individuals will be represented by the first n capital letters of the alphabet and the sums will be represented by variables whose string names contain each associated individual (capital letter). In this example problem, the equations would be represented as:\u003c/p\u003e\u003cul\u003e\u003cli\u003eA+B+C+C = ABCC (= 98)\u003c/li\u003e\u003cli\u003eB+B+C = BBC (= 84)\u003c/li\u003e\u003cli\u003eA+A+B = AAB (= 70)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThough the variables are ordered above, they will not always be in the test cases. Write a function to return the individuals' ages based on the supplied sums. See the test suite for examples and the tags for some hints.\u003c/p\u003e","function_template":"function y = combined_ages_nonsymmetric_w_mult(varargin)\r\n y = ones(nargin,1);\r\nend","test_suite":"%%\r\nABCD = 70;\r\nABC = 65;\r\nAB = 40;\r\nBC = 52;\r\ny = combined_ages_nonsymmetric_w_mult(ABCD,ABC,AB,BC);\r\ny_correct = [13;27;25;5];\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABCC = 98;\r\nBBC = 84;\r\nAAB = 70;\r\ny = combined_ages_nonsymmetric_w_mult(ABCC,BBC,AAB);\r\ny_correct = [20;30;24];\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABCDA = 150;\r\nABCB = 99;\r\nBCDB = 91;\r\nABDAD = 135;\r\ny = combined_ages_nonsymmetric_w_mult(ABCDA,ABCB,BCDB,ABDAD);\r\ny_correct = [35;11;42;27];\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABBA = 90;\r\nBCC = 113;\r\nABCBA = 141;\r\ny = combined_ages_nonsymmetric_w_mult(ABBA,BCC,ABCBA);\r\ny_correct = [34;11;51];\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABCDE = 120;\r\nABCDD = 111;\r\nABCCC = 87;\r\nABBBB = 66;\r\nAAAAA = 50;\r\ny = combined_ages_nonsymmetric_w_mult(ABCDE,ABCDD,ABCCC,ABBBB,AAAAA);\r\ny_correct = [10,14,21,33,42];\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABC = 45;\r\nBEA = 66;\r\nCAE = 73;\r\nDAB = 57;\r\nAAD = 53;\r\ny = combined_ages_nonsymmetric_w_mult(ABC,BEA,CAE,DAB,AAD);\r\ny_correct = [10,14,21,33,42];\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%%\r\nABCABC = 144;\r\nBEAB = 107;\r\nCAEAD = 147;\r\nDABB = 73;\r\nAADAA = 133;\r\ny = combined_ages_nonsymmetric_w_mult(ABCABC,BEAB,CAEAD,DABB,AADAA);\r\ny_correct = [30,15,27,13,47];\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tABCC = 98;\r\n\t\tBBC = 84;\r\n\t\tAAB = 70;\r\n\t\ty = combined_ages_nonsymmetric_w_mult(ABCC,BBC,AAB);\r\n\t\ty_correct = [20;30;24];\r\n\tcase 2\r\n\t\tABCDA = 150;\r\n\t\tABCB = 99;\r\n\t\tBCDB = 91;\r\n\t\tABDAD = 135;\r\n\t\ty = combined_ages_nonsymmetric_w_mult(ABCDA,ABCB,BCDB,ABDAD);\r\n\t\ty_correct = [35;11;42;27];\r\n\tcase 3\r\n\t\tABCABC = 144;\r\n\t\tBEAB = 107;\r\n\t\tCAEAD = 147;\r\n\t\tDABB = 73;\r\n\t\tAADAA = 133;\r\n\t\ty = combined_ages_nonsymmetric_w_mult(ABCABC,BEAB,CAEAD,DABB,AADAA);\r\n\t\ty_correct = [30,15,27,13,47];\r\n\tcase 4\r\n\t\tABCD = 70;\r\n\t\tABC = 65;\r\n\t\tAB = 40;\r\n\t\tBC = 52;\r\n\t\ty = combined_ages_nonsymmetric_w_mult(ABCD,ABC,AB,BC);\r\n\t\ty_correct = [13;27;25;5];\r\nend\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tABCC = 98;\r\n\t\tBBC = 84;\r\n\t\tAAB = 70;\r\n\t\ty = combined_ages_nonsymmetric_w_mult(ABCC,BBC,AAB);\r\n\t\ty_correct = [20;30;24];\r\n\tcase 2\r\n\t\tABCABC = 144;\r\n\t\tBEAB = 107;\r\n\t\tCAEAD = 147;\r\n\t\tDABB = 73;\r\n\t\tAADAA = 133;\r\n\t\ty = combined_ages_nonsymmetric_w_mult(ABCABC,BEAB,CAEAD,DABB,AADAA);\r\n\t\ty_correct = [30,15,27,13,47];\r\n\tcase 3\r\n\t\tABCD = 70;\r\n\t\tABC = 65;\r\n\t\tAB = 40;\r\n\t\tBC = 52;\r\n\t\ty = combined_ages_nonsymmetric_w_mult(ABCD,ABC,AB,BC);\r\n\t\ty_correct = [13;27;25;5];\r\n\tcase 4\r\n\t\tABC = 45;\r\n\t\tBEA = 66;\r\n\t\tCAE = 73;\r\n\t\tDAB = 57;\r\n\t\tAAD = 53;\r\n\t\ty = combined_ages_nonsymmetric_w_mult(ABC,BEA,CAE,DAB,AAD);\r\n\t\ty_correct = [10,14,21,33,42];\r\nend\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tABBA = 90;\r\n\t\tBCC = 113;\r\n\t\tABCBA = 141;\r\n\t\ty = combined_ages_nonsymmetric_w_mult(ABBA,BCC,ABCBA);\r\n\t\ty_correct = [34;11;51];\r\n\tcase 2\r\n\t\tABCD = 70;\r\n\t\tABC = 65;\r\n\t\tAB = 40;\r\n\t\tBC = 52;\r\n\t\ty = combined_ages_nonsymmetric_w_mult(ABCD,ABC,AB,BC);\r\n\t\ty_correct = [13;27;25;5];\r\n\tcase 3\r\n\t\tABCDA = 150;\r\n\t\tABCB = 99;\r\n\t\tBCDB = 91;\r\n\t\tABDAD = 135;\r\n\t\ty = combined_ages_nonsymmetric_w_mult(ABCDA,ABCB,BCDB,ABDAD);\r\n\t\ty_correct = [35;11;42;27];\r\n\tcase 4\r\n\t\tABCC = 98;\r\n\t\tBBC = 84;\r\n\t\tAAB = 70;\r\n\t\ty = combined_ages_nonsymmetric_w_mult(ABCC,BBC,AAB);\r\n\t\ty_correct = [20;30;24];\r\nend\r\nfor i = 1:numel(y_correct)\r\n\tassert(isequal(y(i),y_correct(i)))\r\nend\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":122,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-06-16T20:03:26.000Z","updated_at":"2026-03-24T04:49:54.000Z","published_at":"2015-06-16T20:03: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\u003eThis problem is slightly more difficult than\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42383-combined-ages-3-non-symmetric-n-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCombined Ages 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. In this case, some of the sums may include multiples of some individuals' ages. As an example: If the ages of all three individuals with Chris's age added again sum to 98, the ages of Barry (twice) and Chris sum to 84, and the ages of Alex (twice) and Barry sum to 70, what are their individual ages?\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 individuals will be represented by the first n capital letters of the alphabet and the sums will be represented by variables whose string names contain each associated individual (capital letter). In this example problem, the equations would be represented as:\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\u003eA+B+C+C = ABCC (= 98)\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\u003eB+B+C = BBC (= 84)\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\u003eA+A+B = AAB (= 70)\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\u003eThough the variables are ordered above, they will not always be in the test cases. Write a function to return the individuals' ages based on the supplied sums. See the test suite for examples and the tags for some hints.\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":44258,"title":"Outer product of multiple vectors","description":"In tensor algebra, it is often useful to define a tensor as a product of lower order tensors. Similarly, a multidimensional array T might be defined as an outer product of vectors, where a given element is defined by\r\n\r\n  T(i,j,k) = A(i)*B(j)*C(k);\r\n\r\nCreate a function |outerProduct| that accepts any number of row or column vectors and calculates their outer product. For the above example,\r\n\r\n  T = outerProduct(A,B,C);\r\n","description_html":"\u003cp\u003eIn tensor algebra, it is often useful to define a tensor as a product of lower order tensors. Similarly, a multidimensional array T might be defined as an outer product of vectors, where a given element is defined by\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eT(i,j,k) = A(i)*B(j)*C(k);\r\n\u003c/pre\u003e\u003cp\u003eCreate a function \u003ctt\u003eouterProduct\u003c/tt\u003e that accepts any number of row or column vectors and calculates their outer product. For the above example,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eT = outerProduct(A,B,C);\r\n\u003c/pre\u003e","function_template":"function y = outerProduct(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('outerProduct.m');\r\nassert(~contains(filetext,'regexp'))\r\n\r\n%%\r\ny = outerProduct([],[]);\r\nassert(isempty(y))\r\n\r\n%%\r\nx = randi(100);\r\ny = randi(100);\r\nassert(isequal(outerProduct(x,y),x*y))\r\n\r\n%%\r\nx = randi(100,[1 100]);\r\ny = randi(100,[1 90]);\r\nassert(isequal(outerProduct(x,y),x.'*y))\r\nassert(isequal(outerProduct(x.',y),x.'*y))\r\nassert(isequal(outerProduct(x,y.'),x.'*y))\r\n\r\n%%\r\nx = randi(100,[1 1000]);\r\nxc = num2cell(x);\r\nassert(isequal(outerProduct(xc{:}),prod(x)))","published":true,"deleted":false,"likes_count":3,"comments_count":1,"created_by":1011,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":117,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-07-10T05:32:47.000Z","updated_at":"2026-03-24T05:17:10.000Z","published_at":"2017-07-10T05:33:24.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\u003eIn tensor algebra, it is often useful to define a tensor as a product of lower order tensors. Similarly, a multidimensional array T might be defined as an outer product of vectors, where a given element is defined by\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[T(i,j,k) = A(i)*B(j)*C(k);]]\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\u003eCreate a function\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eouterProduct\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that accepts any number of row or column vectors and calculates their outer product. For the above 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[T = outerProduct(A,B,C);]]\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":44509,"title":"Determine if input is a valid AHP evaluation matrix","description":"Input is a matrix. Output is a true or false statement (1 or 0). Return true if input is a valid Analytic Hierarchy Process evaluation matrix. \r\n\r\nIn a valid AHP matrix;\r\n\r\n* All diagonal elements should be 1\r\n* Lower triangular part should be element-wise reciprocals of upper triangular part\r\n* Square matrix\r\n\r\nFor example\r\n\r\n   [ 1   2\r\n    1/2  1]  -  \u003e True\r\n\r\n   [1 5\r\n    2 1 ]   -  \u003e False\r\n\r\n   [1 5 \r\n   1/5 2]   -  \u003e False\r\n\r\nNote: See test suite 19 for what is asked about rounding","description_html":"\u003cp\u003eInput is a matrix. Output is a true or false statement (1 or 0). Return true if input is a valid Analytic Hierarchy Process evaluation matrix.\u003c/p\u003e\u003cp\u003eIn a valid AHP matrix;\u003c/p\u003e\u003cul\u003e\u003cli\u003eAll diagonal elements should be 1\u003c/li\u003e\u003cli\u003eLower triangular part should be element-wise reciprocals of upper triangular part\u003c/li\u003e\u003cli\u003eSquare matrix\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eFor example\u003c/p\u003e\u003cpre\u003e   [ 1   2\r\n    1/2  1]  -  \u0026gt; True\u003c/pre\u003e\u003cpre\u003e   [1 5\r\n    2 1 ]   -  \u0026gt; False\u003c/pre\u003e\u003cpre\u003e   [1 5 \r\n   1/5 2]   -  \u0026gt; False\u003c/pre\u003e\u003cp\u003eNote: See test suite 19 for what is asked about rounding\u003c/p\u003e","function_template":"function y = isValidAHP(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 1\r\n    1 1];\r\ny_correct = 1;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n%%\r\nx = [1 2\r\n    1/2 1];\r\ny_correct = 1;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n\r\n%%\r\nk = randi([2 9]);\r\nx = [1 k\r\n    1/k 1];\r\ny_correct = 1;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n%%\r\nk = randi([2 9]);\r\nx = [1 k\r\n    1/k k];\r\ny_correct = 0;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n%%\r\nx = [1 5\r\n    1/5 1];\r\ny_correct = 1;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n%%\r\nx = [1 4\r\n    1/4 2];\r\ny_correct = 0;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n%%\r\nx = [1 1 1\r\n    1 1 1\r\n    1 1 1];\r\ny_correct = 1;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3\r\n    1/2 1 4\r\n    1/3 1/4 1];\r\ny_correct = 1;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3\r\n    1/2 0 4\r\n    1/3 1/4 1];\r\ny_correct = 0;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n%%\r\nx = [1 1 1\r\n    1 1 1\r\n    1 1 0.5];\r\ny_correct = 0;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n\r\n%%\r\nx = [1 1 95\r\n    1 1 1\r\n    1 1 1];\r\ny_correct = 0;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n%%\r\nx = [1 2 2\r\n    1/2 1 2\r\n    1/2 1/2 1];\r\ny_correct = 1;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n\r\n%%\r\nm = randi([2 5]);\r\nx = [1 m m\r\n    1/m 1 m\r\n    1/m 1/m 1];\r\ny_correct = 1;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n\r\n%%\r\nx = [1 2 3 4 \r\n    1/2 1 5 6\r\n    1/3 1/5 1 7\r\n    1/4 1/6 1/7 1];\r\ny_correct = 1;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n\r\n%%\r\nx = [0 2 3 4 \r\n    1/2 0 5 6\r\n    1/3 1/5 0 7\r\n    1/4 1/6 1/7 0];\r\ny_correct = 0;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n%% check size also\r\nx = [1 1 1 1 \r\n    1 1 1 1 \r\n    1 1 1 1 ];\r\ny_correct = 0;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n\r\n%% check size also\r\nx = [1 1 1 \r\n    1 1 1 \r\n    1 1 1 \r\n    1 1 1 ];\r\ny_correct = 0;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n\r\n%%\r\nx = [1 1 1 1 1 \r\n    1 1 1 1 1\r\n    1 1 1 1 1 \r\n    1 1 1 1 1\r\n    1 1 1 1 1];\r\ny_correct = 1;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n\r\n%%\r\nx = [1 0.125 0.125 0.111 0.125 0.125;\r\n    8 1 1 0.143 0.143 0.2;\r\n    8 1 1 0.111 0.111 0.143;\r\n    9 7 9 1 5 7;\r\n    8 7 9 0.2 1 0.333;\r\n    8 5 7 0.143 3 1];\r\ny_correct = 1;\r\nassert(isequal(isValidAHP(x),y_correct))\r\n\r\n\r\n\r\n%%\r\nfor idx = 1:20\r\n    x = ones(randi([1 20]));\r\n    y_correct = 1;\r\n    assert(isequal(isValidAHP(x),y_correct))\r\nend\r\n\r\n%%\r\nfor idx = 1:20\r\n    x = zeros(randi([1 20]));\r\n    y_correct = 0;\r\n    assert(isequal(isValidAHP(x),y_correct))\r\nend\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":3,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":137,"test_suite_updated_at":"2018-01-30T07:15:13.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-30T04:30:42.000Z","updated_at":"2026-03-24T05:22:28.000Z","published_at":"2018-01-30T06:27:14.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\u003eInput is a matrix. Output is a true or false statement (1 or 0). Return true if input is a valid Analytic Hierarchy Process evaluation matrix.\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\u003eIn a valid AHP matrix;\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\u003eAll diagonal elements should be 1\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\u003eLower triangular part should be element-wise reciprocals of upper triangular part\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\u003eSquare matrix\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\u003eFor 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[   [ 1   2\\n    1/2  1]  -  \u003e True\\n\\n   [1 5\\n    2 1 ]   -  \u003e False\\n\\n   [1 5 \\n   1/5 2]   -  \u003e False]]\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\u003eNote: See test suite 19 for what is asked about rounding\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":451,"title":"Is this matrix orthogonal?","description":"Given a square matrix, a, determine whether it is orthogonal.\r\nINPUT: a, a n x n matrix\r\nOUTPUT: true or false","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; 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: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 81px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 40.5px; transform-origin: 407px 40.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 190px 8px; transform-origin: 190px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a square matrix, a, determine whether it is orthogonal.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 72px 8px; transform-origin: 72px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eINPUT: a, a n x n matrix\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 69px 8px; transform-origin: 69px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eOUTPUT: true or false\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = isOrthogonal(x)\r\n  y = x;\r\nend","test_suite":"%% test one\r\nx = orth(randn(3));\r\ny_correct = true;\r\nassert(isequal(isOrthogonal(x),y_correct))\r\n\r\n%% test two\r\nx = orth(randn(4));\r\ny_correct = true;\r\nassert(isequal(isOrthogonal(x),y_correct))\r\n\r\n%% test three\r\nx = orth(randn(5));\r\ny_correct = true;\r\nassert(isequal(isOrthogonal(x),y_correct))\r\n\r\n%% test four\r\nx=sqrt([3,1;1,1]);\r\ny_correct = false;\r\nassert(isequal(isOrthogonal(x),y_correct))\r\n\r\n%% test five\r\nx = magic(6);\r\ny_correct = false;\r\nassert(isequal(isOrthogonal(x),y_correct))\r\n\r\n%% test six\r\nx = randn(2)+1;\r\ny_correct = false;\r\nassert(isequal(isOrthogonal(x),y_correct))\r\n\r\n%%Test cases added by Dyuman Joshi, 2-8-23\r\n%% test seven\r\nx = [1 0; 0 0];\r\ny_correct = false;\r\nassert(isequal(isOrthogonal(x),y_correct))\r\n\r\n%% test eight\r\nx = eye(3);\r\ny_correct = true;\r\nassert(isequal(isOrthogonal(x),y_correct))\r\n\r\n%% test nine\r\nx = -eye(6);\r\ny_correct = true;\r\nassert(isequal(isOrthogonal(x),y_correct))\r\n\r\n%% test ten\r\nx = [1 0 0 0; 0 0 0 1; 0 0 1 0; 0 1 0 0]; \r\ny_correct = true;\r\nassert(isequal(isOrthogonal(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":3,"created_by":1103,"edited_by":223089,"edited_at":"2023-08-02T08:02:43.000Z","deleted_by":null,"deleted_at":null,"solvers_count":403,"test_suite_updated_at":"2023-08-02T08:02:43.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-03-05T05:06:16.000Z","updated_at":"2026-03-24T05:24:36.000Z","published_at":"2012-03-06T04:36:47.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eGiven a square matrix, a, determine whether it is orthogonal.\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\u003eINPUT: a, a n x n matrix\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\u003eOUTPUT: true or false\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":2130,"title":"Orthonormal matrix","description":"You decide whether any given matrix is an orthonormal matrix or not.\r\n\r\nIf each column in a matrix is perpendicular to the others, the matrix is orthonormal. Also each column in the matrix must be a unit vector.\r\n\r\nExample\r\n\r\n a = [1 0 0; 0 1 0; 0 0 1] is an orthonormal matrix ","description_html":"\u003cp\u003eYou decide whether any given matrix is an orthonormal matrix or not.\u003c/p\u003e\u003cp\u003eIf each column in a matrix is perpendicular to the others, the matrix is orthonormal. Also each column in the matrix must be a unit vector.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e a = [1 0 0; 0 1 0; 0 0 1] is an orthonormal matrix \u003c/pre\u003e","function_template":"function tf = ortho_normal(A)\r\n  tf = [];\r\nend","test_suite":"%%\r\na=[1 0 0 ;0 1 0;0 0 1]\r\ntf = 1;\r\nassert(isequal(ortho_normal(a),tf))\r\n\r\n%%\r\na=[0 0 1 0;0 1 0 0;1 0 0 0;0 0 0 1]\r\ntf = 1;\r\nassert(isequal(ortho_normal(a),tf))\r\n\r\n%%\r\na=eye(20)\r\nk=a;\r\np=a;\r\na(:,1)=k(:,end);\r\na(:,end)=k(:,1);\r\na(:,5)=p(:,9);\r\na(:,9)=p(:,5)\r\ntf = 1;\r\nassert(isequal(ortho_normal(a),tf))\r\n\r\n%%\r\na=[1 0 1 0;0 1 0 0;1 0 0 0;0 0 0 1]\r\ntf = 0;\r\nassert(isequal(ortho_normal(a),tf))\r\n\r\n%%\r\na=[0 0 2 0;0 1 0 0;1 0 -1 0;0 0 0 1]\r\ntf = 0;\r\nassert(isequal(ortho_normal(a),tf))\r\n\r\n%%\r\na=[1 2 3 ;1 1 5;3 0 1]\r\ntf = 0;\r\nassert(isequal(ortho_normal(a),tf))\r\n\r\n%%\r\na =[1 0 0 ;0 0 0; 0 0 0]\r\ntf = 0;\r\nassert(isequal(ortho_normal(a),tf))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":22216,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":232,"test_suite_updated_at":"2014-01-24T17:13:37.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-01-23T20:03:06.000Z","updated_at":"2026-03-31T14:42:21.000Z","published_at":"2014-01-23T20:03:06.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\u003eYou decide whether any given matrix is an orthonormal matrix or not.\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\u003eIf each column in a matrix is perpendicular to the others, the matrix is orthonormal. Also each column in the matrix must be a unit vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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[ a = [1 0 0; 0 1 0; 0 0 1] is an orthonormal matrix]]\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":615,"title":"Nilpotent matrix","description":"Check if matrix A is \r\n\u003chttp://mathworks.com/ nilpotent\u003e.","description_html":"\u003cp\u003eCheck if matrix A is  \u003ca href=\"http://mathworks.com/\"\u003enilpotent\u003c/a\u003e.\u003c/p\u003e","function_template":"function y = isnilpotent(A)\r\n  y = true;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = false;\r\nassert(isequal(isnilpotent(x),y_correct))\r\n\r\n%%\r\nx = gallery('chebspec',5,0);\r\ny_correct = true;\r\nassert(isequal(isnilpotent(x),y_correct))\r\n\r\n%%\r\nx = gallery('chebspec',3,0);\r\ny_correct = true;\r\nassert(isequal(isnilpotent(x),y_correct))\r\n\r\n%%\r\nx = [1 0 0;0 2 0; 0 0 -3];\r\ny_correct = false;\r\nassert(isequal(isnilpotent(x),y_correct))\r\n\r\n%%\r\nx = [6 -9; 4 -6];\r\ny_correct = true;\r\nassert(isequal(isnilpotent(x),y_correct))\r\n\r\n%%\r\nx = rand(50);\r\ny_correct = false;\r\nassert(isequal(isnilpotent(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":3062,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":317,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-23T18:06:07.000Z","updated_at":"2026-03-31T14:39:19.000Z","published_at":"2012-04-23T18:10: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\u003eCheck if matrix A is \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://mathworks.com/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003enilpotent\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\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":3073,"title":"Projector Matrix","description":"Write a function to determine whether or not the matrix is a projector. Projector matrices are defined as P^2 = P.","description_html":"\u003cp\u003eWrite a function to determine whether or not the matrix is a projector. Projector matrices are defined as P^2 = P.\u003c/p\u003e","function_template":"function [tf] = projector_matrix(P)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nP = (1/2)*[1 -1; -1 1];\r\nassert(isequal(projector_matrix(P),1))\r\n\r\n%%\r\nP = [1 1; 1 0];\r\nassert(isequal(projector_matrix(P),0))\r\n\r\n%%\r\ntheta = pi/2;\r\nP = .5*[1-cos(theta) sin(theta); sin(theta) 1+cos(theta)];\r\nassert(isequal(projector_matrix(P),1))\r\n\r\n%%\r\nP = (1/3)*[2 1 -1; 1 2 1; -1 1 2];\r\nassert(isequal(projector_matrix(P),1))\r\n\r\n%%\r\nP = [-2 1; -6 3];\r\nassert(isequal(projector_matrix(P),1))\r\n\r\n%%\r\nP = [1 1; 0 0];\r\nassert(isequal(projector_matrix(P),1))\r\n\r\n%%\r\nP = [-2 1; -6 2];\r\nassert(isequal(projector_matrix(P),0))\r\n\r\n%%\r\ntheta = pi/2;\r\nP = .5*[1-cos(theta) sin(theta); 1+sin(theta) 1+cos(theta)];\r\nassert(isequal(projector_matrix(P),0))\r\n\r\n%%\r\nP = [1 0; 0 1];\r\nassert(isequal(projector_matrix(P),1))\r\n\r\n%%\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tP = (1/2)*[1 -1; -1 1];\r\n\t\tassert(isequal(projector_matrix(P),1))\r\n\tcase 2\r\n\t\tP = [1 1; 0 0];\r\n\t\tassert(isequal(projector_matrix(P),1))\r\n\tcase 3\r\n\t\tP = [-2 1; -6 3];\r\n\t\tassert(isequal(projector_matrix(P),1))\r\n\tcase 4\r\n\t\tP = [-2 1; -6 2];\r\n\t\tassert(isequal(projector_matrix(P),0))\r\nend\r\n\r\n%%\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tP = [1 1; 0 0];\r\n\t\tassert(isequal(projector_matrix(P),1))\r\n\tcase 2\r\n\t\ttheta = pi/2;\r\n\t\tP = .5*[1-cos(theta) sin(theta); 1+sin(theta) 1+cos(theta)];\r\n\t\tassert(isequal(projector_matrix(P),0))\r\n\tcase 3\r\n\t\tP = [-2 1; -6 2];\r\n\t\tassert(isequal(projector_matrix(P),0))\r\n\tcase 4\r\n\t\tP = (1/2)*[1 -1; -1 1];\r\n\t\tassert(isequal(projector_matrix(P),1))\r\nend\r\n\r\n%%\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tP = [-2 1; -6 3];\r\n\t\tassert(isequal(projector_matrix(P),1))\r\n\tcase 2\r\n\t\ttheta = pi/2;\r\n\t\tP = .5*[1-cos(theta) sin(theta); 1+sin(theta) 1+cos(theta)];\r\n\t\tassert(isequal(projector_matrix(P),0))\r\n\tcase 3\r\n\t\tP = (1/2)*[1 -1; -1 1];\r\n\t\tassert(isequal(projector_matrix(P),1))\r\n\tcase 4\r\n\t\tP = [-2 1; -6 2];\r\n\t\tassert(isequal(projector_matrix(P),0))\r\nend\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":181,"test_suite_updated_at":"2015-03-10T16:19:28.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2015-03-10T02:56:10.000Z","updated_at":"2026-03-24T05:33:00.000Z","published_at":"2015-03-10T02:56:09.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 determine whether or not the matrix is a projector. Projector matrices are defined as P^2 = P.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"no_progress_badge":{"id":53,"name":"Unknown","symbol":"unknown","description":"Partially completed groups","description_html":null,"image_location":"/images/responsive/supporting/matlabcentral/cody/badges/problem_groups_unknown_2.png","bonus":null,"players_count":0,"active":false,"created_by":null,"updated_by":null,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"created_at":"2018-01-10T23:20:29.000Z","updated_at":"2018-01-10T23:20:29.000Z","community_badge_id":null,"award_multiples":false}}