{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-06T14:01:22.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2026-04-06T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":48070,"title":"Center of Mass(es) in 3D Space","description":"Given a matrix of format [x1,y1,z1,m1; x2,y2,z2,m2 . . .], return the center of mass of all listed points in 3d space [xc,yc,zc]. Return pt_com = 'Bad Data' if any value for mass is negative\r\nInspired by: http://hyperphysics.phy-astr.gsu.edu/hbase/cm.html","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: 72px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 36px; transform-origin: 407px 36px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; 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 21px; text-align: left; transform-origin: 384px 21px; 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: 383.5px 8px; transform-origin: 383.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a matrix of format [x1,y1,z1,m1; x2,y2,z2,m2 . . .], return the center of mass of all listed points in 3d space [xc,yc,zc]. Return pt_com = 'Bad Data' if any value for mass is negative\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: 38.5px 8px; transform-origin: 38.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eInspired by: \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehttp://hyperphysics.phy-astr.gsu.edu/hbase/cm.html\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function pt_com = com_finder(x)\r\n  pt_com = x;\r\nend","test_suite":"%%\r\nx = [10    4    12    65\r\n     3     5     8     6\r\n     7     2    13    11\r\n    10     1     6    32\r\n     8     5     2    77\r\n     4     6     9     6\r\n     4     6    15     8\r\n     7     1     6    38\r\n     6     3     8    44\r\n     2     1     1    68];\r\ny_correct = [6.7690,2.9606,6.0254];\r\nTOL = 1e-3;\r\nassert(all(abs(y_correct-com_finder(x))\u003c=TOL))\r\n\r\n%%\r\nx = [10    4    12    65\r\n     3     5     8     6\r\n     7     2    13    11\r\n    10     1     6    32\r\n     8     5     2    77\r\n     4     6     9    -6\r\n     4     6    15     8\r\n     7     1     6    38\r\n     6     3     8    44\r\n     2     1     1    68];\r\ny_correct = [6.7690,2.9606,6.0254];\r\nTOL = 1e-3;\r\nassert(isequal(com_finder(x),'Bad Data'))\r\n\r\n%%\r\n\r\nx = [-47   -41    -3    47\r\n      -3  -121    -4    75\r\n     -34   -68    -4   402\r\n     -12  -137    -3   555\r\n      -1  -106    -4   256\r\n     -29  -157    -1   163\r\n     -83  -106    -6   646\r\n      -9   -55    -2   212\r\n     -56  -149    -2   434\r\n     -65  -157    -3   431\r\n     -69  -162    -1   693\r\n     -42  -153    -6   607\r\n     -57   -16    -4   520\r\n     -25   -42    -3   160\r\n    -100  -151    -1   413\r\n     -21   -51    -3   415\r\n     -99   -29    -4   290\r\n     -45   -63    -1   534\r\n     -20  -135    -2   550\r\n     -29  -134    -3    19\r\n      -4  -178    -6   179\r\n      -6   -72    -3   111\r\n     -64   -60    -3    24\r\n     -79  -100    -2   401\r\n     -45  -200    -6   391\r\n     -98  -129    -5   111\r\n     -52   -64    -5   424\r\n     -50   -47    -2   324\r\n     -87  -176    -6   205\r\n     -52   -49    -6   487\r\n     -51  -200    -6   656\r\n     -61   -69    -5   544\r\n     -13  -153    -5   114\r\n     -21    -2    -1   661\r\n     -81  -159    -4   519\r\n     -33    -9    -5   699\r\n     -23   -42    -4    28\r\n      -7   -34    -3   332\r\n     -93  -140    -1   157\r\n     -30   -80    -1   191\r\n     -15  -124    -6   605\r\n     -72  -118    -1    94\r\n      -5  -127    -6   385\r\n     -43  -190    -6   533\r\n     -33  -191    -1   104\r\n     -19   -56    -2   548\r\n     -58   -18    -4   354\r\n     -65  -182    -3   228\r\n     -93  -131    -4   644\r\n     -11  -184    -5   107\r\n     -46   -54    -1   459\r\n      -5  -100    -4   249\r\n     -44   -28    -4   278\r\n     -81   -18    -1   458\r\n     -51   -39    -1   318\r\n     -97   -26    -6    59\r\n      -4  -134    -5   159\r\n      -4  -167    -2   625\r\n      -9  -144    -2   279\r\n     -52  -138    -1    75\r\n      -2  -156    -6   183\r\n     -48  -173    -5   215\r\n    -100   -15    -5   504\r\n     -92   -21    -4   467\r\n      -9  -144    -5   690\r\n     -81   -99    -4   529\r\n     -26  -104    -1   101\r\n      -9  -175    -1   472\r\n     -68   -79    -5    77\r\n     -96  -196    -3   418\r\n     -83  -162    -3    60\r\n     -64   -54    -6   323\r\n     -78   -31    -2   174\r\n     -26   -55    -2   243\r\n     -41   -24    -6    47\r\n     -90  -178    -2   448\r\n     -97  -136    -1    33\r\n     -18   -43    -5   213\r\n     -20  -103    -4   141\r\n     -46  -106    -1    59\r\n     -44   -74    -5   266\r\n     -74  -141    -5   109\r\n     -48   -92    -6   199\r\n     -40   -90    -1    76\r\n      -9   -93    -5   486\r\n     -68   -43    -2   313\r\n     -21   -57    -2   400\r\n     -32   -81    -5     3\r\n     -46  -108    -6   149\r\n     -72   -26    -4   336\r\n     -26   -47    -4    35\r\n     -37   -66    -1   576\r\n     -51   -75    -1    97\r\n     -91   -18    -5   655\r\n     -16   -49    -6   686\r\n     -49   -12    -4   436\r\n     -17  -199    -6   181\r\n     -56   -11    -6   665\r\n     -51   -44    -2    14\r\n     -34   -34    -6   317\r\n     -81   -18    -2    82\r\n     -27  -111    -2    24\r\n     -14   -70    -3   184\r\n     -14   -66    -4   329\r\n      -3   -74    -5   199\r\n     -97   -24    -1   523\r\n      -3   -27    -1    47\r\n     -90   -95    -4   119\r\n     -31    -4    -3   164\r\n     -43   -42    -6   402\r\n      -3   -46    -1   249\r\n     -62  -140    -4   459\r\n     -40   -13    -3    38\r\n     -70  -170    -6   470\r\n     -17   -19    -5   148\r\n      -4  -156    -6   542\r\n     -57   -92    -4   432\r\n     -64  -160    -3   429\r\n      -8  -129    -6   279\r\n     -99   -52    -6   115\r\n     -85   -82    -2   106\r\n     -85   -86    -5   257\r\n     -53  -147    -5   396\r\n     -49  -161    -3   190\r\n      -8   -43    -5   460\r\n      -4  -128    -2    40\r\n     -23   -51    -6   245\r\n     -78  -198    -1   421\r\n     -99   -33    -3    96\r\n     -64  -117    -6   259\r\n     -96   -26    -5   695\r\n     -53   -17    -6   561\r\n     -76   -43    -2   266\r\n     -56    -3    -2   438\r\n     -93   -54    -6   222\r\n     -78   -34    -1   389\r\n     -47  -124    -5   178\r\n     -64   -41    -1    98\r\n     -90  -196    -4   631\r\n     -33   -35    -6   278\r\n     -33   -31    -2   283\r\n     -36   -11    -6   464\r\n     -58  -139    -4   564\r\n     -75   -43    -3   372\r\n     -28   -51    -2   626\r\n     -59  -133    -5   115\r\n      -1   -12    -4    74\r\n      -5   -10    -3   401\r\n     -58    -6    -4   455\r\n     -20  -125    -1   690\r\n     -12  -126    -1    62\r\n     -16   -54    -4   443\r\n     -55  -193    -4   587\r\n     -20   -54    -1   433\r\n     -85   -42    -4   324\r\n      -1  -198    -3   436\r\n     -77  -184    -2   279\r\n     -89  -195    -1    82\r\n     -61  -118    -4   274\r\n     -31   -36    -4   483\r\n      -9  -104    -6    80\r\n     -91   -26    -4   603\r\n     -73   -31    -2   124\r\n     -62   -15    -4   128\r\n     -10   -69    -5   597\r\n     -53   -78    -4   640\r\n     -99  -118    -3    26\r\n     -57  -118    -5    79\r\n     -14  -151    -5   332\r\n     -46  -137    -3   246\r\n     -33   -49    -1   429\r\n      -3  -139    -4   639\r\n     -92  -200    -3    85\r\n     -17   -83    -2   350\r\n     -14   -95    -6   690\r\n     -36  -157    -3   621\r\n     -40  -165    -2   491\r\n     -86   -12    -5   104\r\n     -99  -176    -4   686\r\n     -26   -17    -6   477\r\n     -52   -62    -6   241\r\n      -7    -9    -2   519\r\n     -13  -106    -6   551\r\n     -75   -83    -4    31\r\n     -29   -17    -2   209\r\n     -92  -175    -4   221\r\n     -30   -83    -2   581\r\n     -14   -28    -4   356\r\n     -67   -85    -6   301\r\n     -73   -89    -5     8\r\n     -13    -5    -2    81\r\n     -40   -80    -4   632\r\n     -97   -50    -3   284\r\n     -57   -73    -1   322\r\n     -99   -17    -1   587\r\n     -51   -67    -6   450\r\n     -77  -107    -1   201\r\n     -94   -48    -4   303\r\n     -85   -96    -1   101\r\n     -22   -30    -4   118\r\n      -7   -87    -1   512\r\n     -38  -132    -3   136\r\n     -77  -179    -2   298\r\n     -70  -122    -6   435\r\n     -84  -107    -1   364\r\n     -54   -62    -6   260\r\n      -9  -106    -4   567\r\n     -18  -104    -2   165\r\n     -12   -86    -5   523\r\n     -51   -25    -6   374\r\n     -45   -47    -6   139\r\n     -68   -85    -4   658\r\n     -39   -40    -1   407\r\n     -86  -148    -4   176\r\n     -45   -99    -4   500\r\n     -72   -93    -1   252\r\n     -13   -98    -2   361\r\n     -48   -24    -4   559\r\n     -90   -72    -2   605\r\n     -89    -6    -5   440\r\n     -94   -66    -2   237\r\n     -37  -166    -6   422\r\n     -91    -9    -4   217\r\n     -88  -120    -2    57\r\n     -29  -116    -1   457\r\n      -7  -115    -2   591\r\n     -23  -195    -3   232\r\n     -34  -102    -3   131\r\n     -84  -123    -4   572\r\n     -25   -72    -2   587\r\n     -53  -186    -6   252\r\n     -21   -73    -3   631\r\n     -34   -80    -1   654\r\n     -82    -6    -1   329\r\n     -86  -173    -5    48\r\n      -6  -163    -5   567\r\n     -67   -31    -5   688\r\n     -74   -54    -1   117\r\n     -44  -167    -2    27\r\n     -66   -86    -4   143\r\n     -20  -122    -6   373\r\n     -69  -163    -3   537\r\n     -88   -13    -3   254\r\n     -66   -87    -5   310\r\n     -19   -28    -4   127\r\n     -32  -158    -3   318\r\n      -9  -189    -4   335\r\n     -41   -79    -3    30\r\n     -56  -196    -5   630\r\n     -46   -39    -6   153\r\n     -58  -104    -1    43\r\n     -40   -94    -3    37\r\n     -88  -156    -1   137\r\n     -43   -45    -1   197\r\n     -49   -31    -3   281\r\n     -31  -154    -2   191\r\n     -86   -64    -1   271\r\n     -95  -159    -3   598\r\n     -74   -47    -3   335\r\n     -61  -104    -4   368\r\n     -49  -169    -4   553\r\n     -37   -90    -3   294\r\n     -26  -164    -1   624\r\n      -9   -17    -2   327\r\n     -81  -188    -6   226\r\n     -60   -90    -6   129\r\n     -10  -150    -3   396\r\n     -42  -109    -3   131\r\n     -73  -161    -4   308\r\n     -53    -9    -6     2\r\n     -96  -106    -6   459\r\n     -78   -17    -1   253\r\n     -61  -187    -5   524\r\n     -61   -54    -5   120\r\n     -84   -58    -2   317\r\n     -42   -71    -1   675\r\n     -44   -80    -5   560\r\n     -24  -131    -6   308\r\n     -30   -62    -3   648\r\n     -67   -47    -6   529\r\n     -39  -120    -5   453\r\n     -34  -104    -1   203\r\n      -3  -109    -3   327\r\n     -79   -28    -1   222\r\n     -43  -169    -6    15\r\n     -32   -66    -4   529\r\n     -87   -22    -1   584\r\n     -44   -76    -5   308\r\n     -53  -126    -5    48\r\n     -62   -80    -5   648\r\n     -44   -68    -5   104\r\n     -33   -38    -6   188\r\n     -46   -25    -6    29\r\n     -23  -148    -3   103\r\n     -98  -200    -4   106\r\n     -39   -94    -6   397\r\n     -77   -72    -2   125\r\n      -1   -64    -2   560\r\n     -89  -161    -3   673\r\n     -91  -198    -3   526];\r\ny_correct = [-48.2024,-92.6248,-3.6100];\r\nTOL = 1e-3;\r\nassert(all(abs(y_correct-com_finder(x))\u003c=TOL))\r\n\r\n%%\r\nx = [(0:5:500)',(0:6:600)',(0:7:700)',(0:1:100)'];\r\ny_correct = [335.0000,402.0000,469.0000];\r\nTOL = 1e-3;\r\nassert(all(abs(y_correct-com_finder(x))\u003c=TOL))\r\n\r\n%%\r\nx = [(0:-5:-500)',(0:6:600)',(0:-7:-700)',(0:8:800)'];\r\ny_correct = [-335.0000,402.0000,-469.0000];\r\nTOL = 1e-3;\r\nassert(all(abs(y_correct-com_finder(x))\u003c=TOL))\r\n\r\n%%\r\nx = circshift(spiral(4),2,2)-2;\r\nassert(isequal(com_finder(x),'Bad Data'))\r\n\r\n%%\r\nid = randi([7 11]);\r\nx = randi(100,id,4);\r\nx(id,4) = -x(id,4);\r\nassert(isequal(com_finder(x),'Bad Data'))\r\n\r\n%%\r\nx = [zeros(17,3) (1:17)'];\r\ny_correct = zeros(1,3);\r\nTOL = 1e-3;\r\nassert(all(abs(y_correct-com_finder(x))\u003c=TOL))\r\n\r\n\r\n%%\r\n%Cheating is bad\r\nfunctions={'!','feval','eval','str2func','str2num','regex','system','dos','unix','perl','assert','fopen','write','save','setenv','path','please'};\r\nassessFunctionAbsence(functions, 'FileName', 'com_finder.m');\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":728283,"edited_by":223089,"edited_at":"2023-02-02T12:44:18.000Z","deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2023-02-02T12:44:18.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-12-17T20:58:08.000Z","updated_at":"2026-03-05T14:22:01.000Z","published_at":"2020-12-18T16:06:36.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 matrix of format [x1,y1,z1,m1; x2,y2,z2,m2 . . .], return the center of mass of all listed points in 3d space [xc,yc,zc]. Return pt_com = 'Bad Data' if any value for mass is negative\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\u003eInspired by: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://hyperphysics.phy-astr.gsu.edu/hbase/cm.html\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":48070,"title":"Center of Mass(es) in 3D Space","description":"Given a matrix of format [x1,y1,z1,m1; x2,y2,z2,m2 . . .], return the center of mass of all listed points in 3d space [xc,yc,zc]. Return pt_com = 'Bad Data' if any value for mass is negative\r\nInspired by: http://hyperphysics.phy-astr.gsu.edu/hbase/cm.html","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: 72px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 36px; transform-origin: 407px 36px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; 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 21px; text-align: left; transform-origin: 384px 21px; 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: 383.5px 8px; transform-origin: 383.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a matrix of format [x1,y1,z1,m1; x2,y2,z2,m2 . . .], return the center of mass of all listed points in 3d space [xc,yc,zc]. Return pt_com = 'Bad Data' if any value for mass is negative\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: 38.5px 8px; transform-origin: 38.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eInspired by: \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehttp://hyperphysics.phy-astr.gsu.edu/hbase/cm.html\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function pt_com = com_finder(x)\r\n  pt_com = x;\r\nend","test_suite":"%%\r\nx = [10    4    12    65\r\n     3     5     8     6\r\n     7     2    13    11\r\n    10     1     6    32\r\n     8     5     2    77\r\n     4     6     9     6\r\n     4     6    15     8\r\n     7     1     6    38\r\n     6     3     8    44\r\n     2     1     1    68];\r\ny_correct = [6.7690,2.9606,6.0254];\r\nTOL = 1e-3;\r\nassert(all(abs(y_correct-com_finder(x))\u003c=TOL))\r\n\r\n%%\r\nx = [10    4    12    65\r\n     3     5     8     6\r\n     7     2    13    11\r\n    10     1     6    32\r\n     8     5     2    77\r\n     4     6     9    -6\r\n     4     6    15     8\r\n     7     1     6    38\r\n     6     3     8    44\r\n     2     1     1    68];\r\ny_correct = [6.7690,2.9606,6.0254];\r\nTOL = 1e-3;\r\nassert(isequal(com_finder(x),'Bad Data'))\r\n\r\n%%\r\n\r\nx = [-47   -41    -3    47\r\n      -3  -121    -4    75\r\n     -34   -68    -4   402\r\n     -12  -137    -3   555\r\n      -1  -106    -4   256\r\n     -29  -157    -1   163\r\n     -83  -106    -6   646\r\n      -9   -55    -2   212\r\n     -56  -149    -2   434\r\n     -65  -157    -3   431\r\n     -69  -162    -1   693\r\n     -42  -153    -6   607\r\n     -57   -16    -4   520\r\n     -25   -42    -3   160\r\n    -100  -151    -1   413\r\n     -21   -51    -3   415\r\n     -99   -29    -4   290\r\n     -45   -63    -1   534\r\n     -20  -135    -2   550\r\n     -29  -134    -3    19\r\n      -4  -178    -6   179\r\n      -6   -72    -3   111\r\n     -64   -60    -3    24\r\n     -79  -100    -2   401\r\n     -45  -200    -6   391\r\n     -98  -129    -5   111\r\n     -52   -64    -5   424\r\n     -50   -47    -2   324\r\n     -87  -176    -6   205\r\n     -52   -49    -6   487\r\n     -51  -200    -6   656\r\n     -61   -69    -5   544\r\n     -13  -153    -5   114\r\n     -21    -2    -1   661\r\n     -81  -159    -4   519\r\n     -33    -9    -5   699\r\n     -23   -42    -4    28\r\n      -7   -34    -3   332\r\n     -93  -140    -1   157\r\n     -30   -80    -1   191\r\n     -15  -124    -6   605\r\n     -72  -118    -1    94\r\n      -5  -127    -6   385\r\n     -43  -190    -6   533\r\n     -33  -191    -1   104\r\n     -19   -56    -2   548\r\n     -58   -18    -4   354\r\n     -65  -182    -3   228\r\n     -93  -131    -4   644\r\n     -11  -184    -5   107\r\n     -46   -54    -1   459\r\n      -5  -100    -4   249\r\n     -44   -28    -4   278\r\n     -81   -18    -1   458\r\n     -51   -39    -1   318\r\n     -97   -26    -6    59\r\n      -4  -134    -5   159\r\n      -4  -167    -2   625\r\n      -9  -144    -2   279\r\n     -52  -138    -1    75\r\n      -2  -156    -6   183\r\n     -48  -173    -5   215\r\n    -100   -15    -5   504\r\n     -92   -21    -4   467\r\n      -9  -144    -5   690\r\n     -81   -99    -4   529\r\n     -26  -104    -1   101\r\n      -9  -175    -1   472\r\n     -68   -79    -5    77\r\n     -96  -196    -3   418\r\n     -83  -162    -3    60\r\n     -64   -54    -6   323\r\n     -78   -31    -2   174\r\n     -26   -55    -2   243\r\n     -41   -24    -6    47\r\n     -90  -178    -2   448\r\n     -97  -136    -1    33\r\n     -18   -43    -5   213\r\n     -20  -103    -4   141\r\n     -46  -106    -1    59\r\n     -44   -74    -5   266\r\n     -74  -141    -5   109\r\n     -48   -92    -6   199\r\n     -40   -90    -1    76\r\n      -9   -93    -5   486\r\n     -68   -43    -2   313\r\n     -21   -57    -2   400\r\n     -32   -81    -5     3\r\n     -46  -108    -6   149\r\n     -72   -26    -4   336\r\n     -26   -47    -4    35\r\n     -37   -66    -1   576\r\n     -51   -75    -1    97\r\n     -91   -18    -5   655\r\n     -16   -49    -6   686\r\n     -49   -12    -4   436\r\n     -17  -199    -6   181\r\n     -56   -11    -6   665\r\n     -51   -44    -2    14\r\n     -34   -34    -6   317\r\n     -81   -18    -2    82\r\n     -27  -111    -2    24\r\n     -14   -70    -3   184\r\n     -14   -66    -4   329\r\n      -3   -74    -5   199\r\n     -97   -24    -1   523\r\n      -3   -27    -1    47\r\n     -90   -95    -4   119\r\n     -31    -4    -3   164\r\n     -43   -42    -6   402\r\n      -3   -46    -1   249\r\n     -62  -140    -4   459\r\n     -40   -13    -3    38\r\n     -70  -170    -6   470\r\n     -17   -19    -5   148\r\n      -4  -156    -6   542\r\n     -57   -92    -4   432\r\n     -64  -160    -3   429\r\n      -8  -129    -6   279\r\n     -99   -52    -6   115\r\n     -85   -82    -2   106\r\n     -85   -86    -5   257\r\n     -53  -147    -5   396\r\n     -49  -161    -3   190\r\n      -8   -43    -5   460\r\n      -4  -128    -2    40\r\n     -23   -51    -6   245\r\n     -78  -198    -1   421\r\n     -99   -33    -3    96\r\n     -64  -117    -6   259\r\n     -96   -26    -5   695\r\n     -53   -17    -6   561\r\n     -76   -43    -2   266\r\n     -56    -3    -2   438\r\n     -93   -54    -6   222\r\n     -78   -34    -1   389\r\n     -47  -124    -5   178\r\n     -64   -41    -1    98\r\n     -90  -196    -4   631\r\n     -33   -35    -6   278\r\n     -33   -31    -2   283\r\n     -36   -11    -6   464\r\n     -58  -139    -4   564\r\n     -75   -43    -3   372\r\n     -28   -51    -2   626\r\n     -59  -133    -5   115\r\n      -1   -12    -4    74\r\n      -5   -10    -3   401\r\n     -58    -6    -4   455\r\n     -20  -125    -1   690\r\n     -12  -126    -1    62\r\n     -16   -54    -4   443\r\n     -55  -193    -4   587\r\n     -20   -54    -1   433\r\n     -85   -42    -4   324\r\n      -1  -198    -3   436\r\n     -77  -184    -2   279\r\n     -89  -195    -1    82\r\n     -61  -118    -4   274\r\n     -31   -36    -4   483\r\n      -9  -104    -6    80\r\n     -91   -26    -4   603\r\n     -73   -31    -2   124\r\n     -62   -15    -4   128\r\n     -10   -69    -5   597\r\n     -53   -78    -4   640\r\n     -99  -118    -3    26\r\n     -57  -118    -5    79\r\n     -14  -151    -5   332\r\n     -46  -137    -3   246\r\n     -33   -49    -1   429\r\n      -3  -139    -4   639\r\n     -92  -200    -3    85\r\n     -17   -83    -2   350\r\n     -14   -95    -6   690\r\n     -36  -157    -3   621\r\n     -40  -165    -2   491\r\n     -86   -12    -5   104\r\n     -99  -176    -4   686\r\n     -26   -17    -6   477\r\n     -52   -62    -6   241\r\n      -7    -9    -2   519\r\n     -13  -106    -6   551\r\n     -75   -83    -4    31\r\n     -29   -17    -2   209\r\n     -92  -175    -4   221\r\n     -30   -83    -2   581\r\n     -14   -28    -4   356\r\n     -67   -85    -6   301\r\n     -73   -89    -5     8\r\n     -13    -5    -2    81\r\n     -40   -80    -4   632\r\n     -97   -50    -3   284\r\n     -57   -73    -1   322\r\n     -99   -17    -1   587\r\n     -51   -67    -6   450\r\n     -77  -107    -1   201\r\n     -94   -48    -4   303\r\n     -85   -96    -1   101\r\n     -22   -30    -4   118\r\n      -7   -87    -1   512\r\n     -38  -132    -3   136\r\n     -77  -179    -2   298\r\n     -70  -122    -6   435\r\n     -84  -107    -1   364\r\n     -54   -62    -6   260\r\n      -9  -106    -4   567\r\n     -18  -104    -2   165\r\n     -12   -86    -5   523\r\n     -51   -25    -6   374\r\n     -45   -47    -6   139\r\n     -68   -85    -4   658\r\n     -39   -40    -1   407\r\n     -86  -148    -4   176\r\n     -45   -99    -4   500\r\n     -72   -93    -1   252\r\n     -13   -98    -2   361\r\n     -48   -24    -4   559\r\n     -90   -72    -2   605\r\n     -89    -6    -5   440\r\n     -94   -66    -2   237\r\n     -37  -166    -6   422\r\n     -91    -9    -4   217\r\n     -88  -120    -2    57\r\n     -29  -116    -1   457\r\n      -7  -115    -2   591\r\n     -23  -195    -3   232\r\n     -34  -102    -3   131\r\n     -84  -123    -4   572\r\n     -25   -72    -2   587\r\n     -53  -186    -6   252\r\n     -21   -73    -3   631\r\n     -34   -80    -1   654\r\n     -82    -6    -1   329\r\n     -86  -173    -5    48\r\n      -6  -163    -5   567\r\n     -67   -31    -5   688\r\n     -74   -54    -1   117\r\n     -44  -167    -2    27\r\n     -66   -86    -4   143\r\n     -20  -122    -6   373\r\n     -69  -163    -3   537\r\n     -88   -13    -3   254\r\n     -66   -87    -5   310\r\n     -19   -28    -4   127\r\n     -32  -158    -3   318\r\n      -9  -189    -4   335\r\n     -41   -79    -3    30\r\n     -56  -196    -5   630\r\n     -46   -39    -6   153\r\n     -58  -104    -1    43\r\n     -40   -94    -3    37\r\n     -88  -156    -1   137\r\n     -43   -45    -1   197\r\n     -49   -31    -3   281\r\n     -31  -154    -2   191\r\n     -86   -64    -1   271\r\n     -95  -159    -3   598\r\n     -74   -47    -3   335\r\n     -61  -104    -4   368\r\n     -49  -169    -4   553\r\n     -37   -90    -3   294\r\n     -26  -164    -1   624\r\n      -9   -17    -2   327\r\n     -81  -188    -6   226\r\n     -60   -90    -6   129\r\n     -10  -150    -3   396\r\n     -42  -109    -3   131\r\n     -73  -161    -4   308\r\n     -53    -9    -6     2\r\n     -96  -106    -6   459\r\n     -78   -17    -1   253\r\n     -61  -187    -5   524\r\n     -61   -54    -5   120\r\n     -84   -58    -2   317\r\n     -42   -71    -1   675\r\n     -44   -80    -5   560\r\n     -24  -131    -6   308\r\n     -30   -62    -3   648\r\n     -67   -47    -6   529\r\n     -39  -120    -5   453\r\n     -34  -104    -1   203\r\n      -3  -109    -3   327\r\n     -79   -28    -1   222\r\n     -43  -169    -6    15\r\n     -32   -66    -4   529\r\n     -87   -22    -1   584\r\n     -44   -76    -5   308\r\n     -53  -126    -5    48\r\n     -62   -80    -5   648\r\n     -44   -68    -5   104\r\n     -33   -38    -6   188\r\n     -46   -25    -6    29\r\n     -23  -148    -3   103\r\n     -98  -200    -4   106\r\n     -39   -94    -6   397\r\n     -77   -72    -2   125\r\n      -1   -64    -2   560\r\n     -89  -161    -3   673\r\n     -91  -198    -3   526];\r\ny_correct = [-48.2024,-92.6248,-3.6100];\r\nTOL = 1e-3;\r\nassert(all(abs(y_correct-com_finder(x))\u003c=TOL))\r\n\r\n%%\r\nx = [(0:5:500)',(0:6:600)',(0:7:700)',(0:1:100)'];\r\ny_correct = [335.0000,402.0000,469.0000];\r\nTOL = 1e-3;\r\nassert(all(abs(y_correct-com_finder(x))\u003c=TOL))\r\n\r\n%%\r\nx = [(0:-5:-500)',(0:6:600)',(0:-7:-700)',(0:8:800)'];\r\ny_correct = [-335.0000,402.0000,-469.0000];\r\nTOL = 1e-3;\r\nassert(all(abs(y_correct-com_finder(x))\u003c=TOL))\r\n\r\n%%\r\nx = circshift(spiral(4),2,2)-2;\r\nassert(isequal(com_finder(x),'Bad Data'))\r\n\r\n%%\r\nid = randi([7 11]);\r\nx = randi(100,id,4);\r\nx(id,4) = -x(id,4);\r\nassert(isequal(com_finder(x),'Bad Data'))\r\n\r\n%%\r\nx = [zeros(17,3) (1:17)'];\r\ny_correct = zeros(1,3);\r\nTOL = 1e-3;\r\nassert(all(abs(y_correct-com_finder(x))\u003c=TOL))\r\n\r\n\r\n%%\r\n%Cheating is bad\r\nfunctions={'!','feval','eval','str2func','str2num','regex','system','dos','unix','perl','assert','fopen','write','save','setenv','path','please'};\r\nassessFunctionAbsence(functions, 'FileName', 'com_finder.m');\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":728283,"edited_by":223089,"edited_at":"2023-02-02T12:44:18.000Z","deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2023-02-02T12:44:18.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-12-17T20:58:08.000Z","updated_at":"2026-03-05T14:22:01.000Z","published_at":"2020-12-18T16:06:36.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 matrix of format [x1,y1,z1,m1; x2,y2,z2,m2 . . .], return the center of mass of all listed points in 3d space [xc,yc,zc]. Return pt_com = 'Bad Data' if any value for mass is negative\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\u003eInspired by: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://hyperphysics.phy-astr.gsu.edu/hbase/cm.html\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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\"}]}"}],"term":"tag:\"com\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"com\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"com\"","","\"","com","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f03b9e0e250\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f03b9e0e1b0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f03b9e0d8f0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f03b9e0e4d0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f03b9e0e430\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f03b9e0e390\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f03b9e0e2f0\u003e":"tag:\"com\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f03b9e0e2f0\u003e":"tag:\"com\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"cody-search","password":"78X075ddcV44","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"com\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"com\"","","\"","com","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f03b9e0e250\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f03b9e0e1b0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f03b9e0d8f0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f03b9e0e4d0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f03b9e0e430\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f03b9e0e390\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f03b9e0e2f0\u003e":"tag:\"com\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f03b9e0e2f0\u003e":"tag:\"com\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":48070,"difficulty_rating":"easy"}]}}