{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":44890,"title":"Invert a 3D rotation matrix","description":"Given a 3D rotation matrix, belonging to the matrix group SO(3), compute its inverse without using the functions inv() or pinv() .","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: 43px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 21.5px; transform-origin: 407px 21.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"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 21.5px; text-align: left; transform-origin: 384px 21.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: 349.5px 8px; transform-origin: 349.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a 3D rotation matrix, belonging to the matrix group SO(3), compute its inverse without using the functions\u003c/span\u003e\u003c/span\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\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: 20px 8px; transform-origin: 20px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 20px 8.5px; transform-origin: 20px 8.5px; \"\u003einv()\u003c/span\u003e\u003c/span\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: 8.5px 8px; transform-origin: 8.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e or\u003c/span\u003e\u003c/span\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\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: 24px 8px; transform-origin: 24px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 24px 8.5px; transform-origin: 24px 8.5px; \"\u003epinv()\u003c/span\u003e\u003c/span\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e .\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%% Test for inv usage \r\npattern = '@inv|@pinv|inv\\(|pinv\\(';\r\nfid = fopen(which('your_fcn_name'), 'r'); \r\nc = onCleanup(@()fclose(fid)); \r\ntline = fgetl(fid); \r\nwhile ischar(tline), \r\n  if ~isempty(regexp(tline, pattern))\r\n    error('Don''t use inv() or pinv()'); \r\n  end \r\n  tline = fgetl(fid); \r\nend\r\n\r\n%%\r\nx = [1 -1 0; 1 1 0; 0 0 sqrt(2)]/sqrt(2);\r\nerr = x * your_fcn_name(x) - eye(3,3);\r\nassert(norm(err) \u003c 10*eps)\r\n\r\n%%\r\nx = [1 0 0; 0 0 -1; 0 1 0];\r\nassert(isequal(your_fcn_name(x), [1 0 0; 0 0 1; 0 -1 0]))\r\n\r\n%%\r\nx = eye(3);\r\nassert(isequal(your_fcn_name(x),x))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":13332,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":24,"test_suite_updated_at":"2022-01-03T15:04:54.000Z","rescore_all_solutions":false,"group_id":629,"created_at":"2019-04-23T09:40:54.000Z","updated_at":"2026-02-17T15:49:50.000Z","published_at":"2019-04-23T10:51:19.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a 3D rotation matrix, belonging to the matrix group SO(3), compute its inverse without using the functions\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\u003einv()\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\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\u003epinv()\u003c/w:t\u003e\u003c/w:r\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\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":44894,"title":"Orientation of a 3D coordinate frame","description":"The orientation of a body-fixed frame {B} with respect to the world frame {W} is described by an SO(3) rotation matrix.  Compute a unit-vector, with respect to frame {W}, that is parallel to the z-axis of frame {B}.","description_html":"\u003cp\u003eThe orientation of a body-fixed frame {B} with respect to the world frame {W} is described by an SO(3) rotation matrix.  Compute a unit-vector, with respect to frame {W}, that is parallel to the z-axis of frame {B}.\u003c/p\u003e","function_template":"function z = your_fcn_name(R)\r\n  % z is a row vector parallel to the z-axis of the frame with attitude described by R\r\n  z = 0;\r\nend","test_suite":"%%\r\nrpy = (rand(1,3)-0.5)*pi;\r\nr = rpy(1); p = rpy(2); y = rpy(3);\r\nR = reshape([cos(p).*cos(y),cos(p).*sin(y),-sin(p),-cos(r).*sin(y)+cos(y).*sin(p).*sin(r),cos(r).*cos(y)+sin(p).*sin(r).*sin(y),cos(p).*sin(r),sin(r).*sin(y)+cos(r).*cos(y).*sin(p),-cos(y).*sin(r)+cos(r).*sin(p).*sin(y),cos(p).*cos(r)],[3,3]);\r\nz = your_fcn_name(R);\r\nassert(all(size(z) == [1 3]), 'shape of z should be 1x3');\r\n\r\nerr = abs(z*R(:,1)) + abs(z*R(:,2))\r\nassert(sum(abs(err)) \u003c 10*eps)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":13332,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":14,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":629,"created_at":"2019-04-23T10:35:10.000Z","updated_at":"2025-12-07T21:49:12.000Z","published_at":"2019-04-23T10:49:00.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\u003eThe orientation of a body-fixed frame {B} with respect to the world frame {W} is described by an SO(3) rotation matrix. Compute a unit-vector, with respect to frame {W}, that is parallel to the z-axis of frame {B}.\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":44892,"title":"Create a 3D rotation matrix","description":"Consider an arbitrary coordinate frame {A}.  Consider another coordinate frame {B} which has the same origin as {A} but is rotated by -90degrees about the y-axis of frame {A}.  Write the SO(3) rotation matrix that will transform the coordinates of a point, defined with respect to {B}, to the coordinates with respect to {A}.","description_html":"\u003cp\u003eConsider an arbitrary coordinate frame {A}.  Consider another coordinate frame {B} which has the same origin as {A} but is rotated by -90degrees about the y-axis of frame {A}.  Write the SO(3) rotation matrix that will transform the coordinates of a point, defined with respect to {B}, to the coordinates with respect to {A}.\u003c/p\u003e","function_template":"function y = your_fcn_name()\r\n  y = 1;\r\nend","test_suite":"%%\r\ny_correct = [0 0 -1; 0 1 0; 1 0 0];\r\nassert(isequal(your_fcn_name(),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":13332,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":629,"created_at":"2019-04-23T09:50:57.000Z","updated_at":"2026-03-16T11:36:08.000Z","published_at":"2019-04-23T10:50:28.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\u003eConsider an arbitrary coordinate frame {A}. Consider another coordinate frame {B} which has the same origin as {A} but is rotated by -90degrees about the y-axis of frame {A}. Write the SO(3) rotation matrix that will transform the coordinates of a point, defined with respect to {B}, to the coordinates with respect to {A}.\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":44893,"title":"Create a 3D rotation matrix from roll-pitch-yaw angles","description":"Consider a robotics application where the world reference coordinate frame {W} and a robot manipulator arm with an attached tool coordinate frame {T}.  The orientation of {T} is described in terms of roll-pitch-yaw angles defined as a sequence of rotations, starting with the {W} frame, where yaw is about the X axis, pitch is about the Y axis and roll is about the Z axis.","description_html":"\u003cp\u003eConsider a robotics application where the world reference coordinate frame {W} and a robot manipulator arm with an attached tool coordinate frame {T}.  The orientation of {T} is described in terms of roll-pitch-yaw angles defined as a sequence of rotations, starting with the {W} frame, where yaw is about the X axis, pitch is about the Y axis and roll is about the Z axis.\u003c/p\u003e","function_template":"function y = your_fcn_name(rpy)\r\n  % rpy is a vector containing [roll pitch yaw] in units of radians\r\n  y = 0;  % is a 3x3 matrix\r\nend","test_suite":"%%\r\nrpy = [-2,-1,-2]*pi/2; t = [1,2,3]; t_ans = [-3,2,1];\r\nassert(norm(your_fcn_name(rpy)*t' - t_ans') \u003c 10*eps)\r\n\r\n%%\r\nrpy = [-1,2,-2]*pi/2; t = [1,2,3]; t_ans = [-2,1,3];\r\nassert(norm(your_fcn_name(rpy)*t' - t_ans') \u003c 10*eps)\r\n\r\n%%\r\nrpy = [-2,2,1]*pi/2; t = [1,2,3]; t_ans = [1,3,-2];\r\nassert(norm(your_fcn_name(rpy)*t' - t_ans') \u003c 10*eps)\r\n\r\n%%\r\nrpy = [1,-2,0]*pi/2; t = [1,2,3]; t_ans = [2,1,-3];\r\nassert(norm(your_fcn_name(rpy)*t' - t_ans') \u003c 10*eps)","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":13332,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":10,"test_suite_updated_at":"2019-04-24T02:20:45.000Z","rescore_all_solutions":true,"group_id":629,"created_at":"2019-04-23T10:13:54.000Z","updated_at":"2025-11-18T17:54:47.000Z","published_at":"2019-04-24T02:17:05.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\u003eConsider a robotics application where the world reference coordinate frame {W} and a robot manipulator arm with an attached tool coordinate frame {T}. The orientation of {T} is described in terms of roll-pitch-yaw angles defined as a sequence of rotations, starting with the {W} frame, where yaw is about the X axis, pitch is about the Y axis and roll is about the Z axis.\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":44895,"title":"Determine roll pitch yaw angles from a 3D rotation matrix","description":"Consider an aerospace application where the world reference coordinate frame {W} and a body-fixed coordinate frame {B}.  The origins of {W} and {B} are coincident.  The orientation of {B} is described in terms of roll-pitch-yaw angles defined as a sequence of rotations where yaw is about the Z, pitch is about the Y axis and roll is about the X axis.\r\n\r\nGiven an SO(3) rotation matrix describing the orientation of {B} with respect to {W} determine the roll-pitch-yaw angles.","description_html":"\u003cp\u003eConsider an aerospace application where the world reference coordinate frame {W} and a body-fixed coordinate frame {B}.  The origins of {W} and {B} are coincident.  The orientation of {B} is described in terms of roll-pitch-yaw angles defined as a sequence of rotations where yaw is about the Z, pitch is about the Y axis and roll is about the X axis.\u003c/p\u003e\u003cp\u003eGiven an SO(3) rotation matrix describing the orientation of {B} with respect to {W} determine the roll-pitch-yaw angles.\u003c/p\u003e","function_template":"function rpy = your_fcn_name(R)\r\n  % rpy is a 1x3 vector [roll pitch yaw]\r\n  rpy = 0;\r\nend","test_suite":"%% handle regular case\r\n\r\n% compute random SO(3)\r\nfor count = 1:5\r\n  rpy = (rand(1,3)-0.5)*pi;\r\n  r = rpy(1); p = rpy(2); y = rpy(3);\r\n\r\n  rpy2r = @(r,p,y) reshape([cos(p).*cos(y),cos(p).*sin(y),-sin(p),-cos(r).*sin(y)+cos(y).*sin(p).*sin(r),cos(r).*cos(y)+sin(p).*sin(r).*sin(y),cos(p).*sin(r),sin(r).*sin(y)+cos(r).*cos(y).*sin(p),-cos(y).*sin(r)+cos(r).*sin(p).*sin(y),cos(p).*cos(r)],[3,3]);\r\n  R_correct = rpy2r(r, p, y);\r\n\r\n  % user's estimate\r\n  rpy = your_fcn_name(R_correct);\r\n  r = rpy(1); p = rpy(2); y = rpy(3);\r\n\r\n  err = R_correct' * rpy2r(r,p,y) - eye(3,3);\r\n  assert(norm(err) \u003c 10*eps)\r\nend\r\n\r\n%% handle singular case\r\nrpy = (rand(1,3)-0.5)*pi;\r\nr = rpy(1); p = pi/2; y = rpy(3);\r\n\r\nrpy2r = @(r,p,y) reshape([cos(p).*cos(y),cos(p).*sin(y),-sin(p),-cos(r).*sin(y)+cos(y).*sin(p).*sin(r),cos(r).*cos(y)+sin(p).*sin(r).*sin(y),cos(p).*sin(r),sin(r).*sin(y)+cos(r).*cos(y).*sin(p),-cos(y).*sin(r)+cos(r).*sin(p).*sin(y),cos(p).*cos(r)],[3,3]);\r\nR_correct = rpy2r(r, p, y);\r\n\r\n% user's estimate\r\nrpy = your_fcn_name(R_correct);\r\nr = rpy(1); p = rpy(2); y = rpy(3);\r\n\r\nerr = R_correct' * rpy2r(r,p,y) - eye(3,3);\r\nassert(norm(err) \u003c 10*eps)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":5,"created_by":13332,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":"2019-04-24T02:02:23.000Z","rescore_all_solutions":false,"group_id":629,"created_at":"2019-04-23T10:43:03.000Z","updated_at":"2025-11-18T02:44:02.000Z","published_at":"2019-04-23T10:46:56.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\u003eConsider an aerospace application where the world reference coordinate frame {W} and a body-fixed coordinate frame {B}. The origins of {W} and {B} are coincident. The orientation of {B} is described in terms of roll-pitch-yaw angles defined as a sequence of rotations where yaw is about the Z, pitch is about the Y axis and roll is about the X axis.\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\u003eGiven an SO(3) rotation matrix describing the orientation of {B} with respect to {W} determine the roll-pitch-yaw angles.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":44890,"title":"Invert a 3D rotation matrix","description":"Given a 3D rotation matrix, belonging to the matrix group SO(3), compute its inverse without using the functions inv() or pinv() .","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: 43px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 21.5px; transform-origin: 407px 21.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"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 21.5px; text-align: left; transform-origin: 384px 21.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: 349.5px 8px; transform-origin: 349.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a 3D rotation matrix, belonging to the matrix group SO(3), compute its inverse without using the functions\u003c/span\u003e\u003c/span\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\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: 20px 8px; transform-origin: 20px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 20px 8.5px; transform-origin: 20px 8.5px; \"\u003einv()\u003c/span\u003e\u003c/span\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: 8.5px 8px; transform-origin: 8.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e or\u003c/span\u003e\u003c/span\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\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: 24px 8px; transform-origin: 24px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 24px 8.5px; transform-origin: 24px 8.5px; \"\u003epinv()\u003c/span\u003e\u003c/span\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e .\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%% Test for inv usage \r\npattern = '@inv|@pinv|inv\\(|pinv\\(';\r\nfid = fopen(which('your_fcn_name'), 'r'); \r\nc = onCleanup(@()fclose(fid)); \r\ntline = fgetl(fid); \r\nwhile ischar(tline), \r\n  if ~isempty(regexp(tline, pattern))\r\n    error('Don''t use inv() or pinv()'); \r\n  end \r\n  tline = fgetl(fid); \r\nend\r\n\r\n%%\r\nx = [1 -1 0; 1 1 0; 0 0 sqrt(2)]/sqrt(2);\r\nerr = x * your_fcn_name(x) - eye(3,3);\r\nassert(norm(err) \u003c 10*eps)\r\n\r\n%%\r\nx = [1 0 0; 0 0 -1; 0 1 0];\r\nassert(isequal(your_fcn_name(x), [1 0 0; 0 0 1; 0 -1 0]))\r\n\r\n%%\r\nx = eye(3);\r\nassert(isequal(your_fcn_name(x),x))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":13332,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":24,"test_suite_updated_at":"2022-01-03T15:04:54.000Z","rescore_all_solutions":false,"group_id":629,"created_at":"2019-04-23T09:40:54.000Z","updated_at":"2026-02-17T15:49:50.000Z","published_at":"2019-04-23T10:51:19.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a 3D rotation matrix, belonging to the matrix group SO(3), compute its inverse without using the functions\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\u003einv()\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\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\u003epinv()\u003c/w:t\u003e\u003c/w:r\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\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":44894,"title":"Orientation of a 3D coordinate frame","description":"The orientation of a body-fixed frame {B} with respect to the world frame {W} is described by an SO(3) rotation matrix.  Compute a unit-vector, with respect to frame {W}, that is parallel to the z-axis of frame {B}.","description_html":"\u003cp\u003eThe orientation of a body-fixed frame {B} with respect to the world frame {W} is described by an SO(3) rotation matrix.  Compute a unit-vector, with respect to frame {W}, that is parallel to the z-axis of frame {B}.\u003c/p\u003e","function_template":"function z = your_fcn_name(R)\r\n  % z is a row vector parallel to the z-axis of the frame with attitude described by R\r\n  z = 0;\r\nend","test_suite":"%%\r\nrpy = (rand(1,3)-0.5)*pi;\r\nr = rpy(1); p = rpy(2); y = rpy(3);\r\nR = reshape([cos(p).*cos(y),cos(p).*sin(y),-sin(p),-cos(r).*sin(y)+cos(y).*sin(p).*sin(r),cos(r).*cos(y)+sin(p).*sin(r).*sin(y),cos(p).*sin(r),sin(r).*sin(y)+cos(r).*cos(y).*sin(p),-cos(y).*sin(r)+cos(r).*sin(p).*sin(y),cos(p).*cos(r)],[3,3]);\r\nz = your_fcn_name(R);\r\nassert(all(size(z) == [1 3]), 'shape of z should be 1x3');\r\n\r\nerr = abs(z*R(:,1)) + abs(z*R(:,2))\r\nassert(sum(abs(err)) \u003c 10*eps)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":13332,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":14,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":629,"created_at":"2019-04-23T10:35:10.000Z","updated_at":"2025-12-07T21:49:12.000Z","published_at":"2019-04-23T10:49:00.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\u003eThe orientation of a body-fixed frame {B} with respect to the world frame {W} is described by an SO(3) rotation matrix. Compute a unit-vector, with respect to frame {W}, that is parallel to the z-axis of frame {B}.\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":44892,"title":"Create a 3D rotation matrix","description":"Consider an arbitrary coordinate frame {A}.  Consider another coordinate frame {B} which has the same origin as {A} but is rotated by -90degrees about the y-axis of frame {A}.  Write the SO(3) rotation matrix that will transform the coordinates of a point, defined with respect to {B}, to the coordinates with respect to {A}.","description_html":"\u003cp\u003eConsider an arbitrary coordinate frame {A}.  Consider another coordinate frame {B} which has the same origin as {A} but is rotated by -90degrees about the y-axis of frame {A}.  Write the SO(3) rotation matrix that will transform the coordinates of a point, defined with respect to {B}, to the coordinates with respect to {A}.\u003c/p\u003e","function_template":"function y = your_fcn_name()\r\n  y = 1;\r\nend","test_suite":"%%\r\ny_correct = [0 0 -1; 0 1 0; 1 0 0];\r\nassert(isequal(your_fcn_name(),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":13332,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":629,"created_at":"2019-04-23T09:50:57.000Z","updated_at":"2026-03-16T11:36:08.000Z","published_at":"2019-04-23T10:50:28.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\u003eConsider an arbitrary coordinate frame {A}. Consider another coordinate frame {B} which has the same origin as {A} but is rotated by -90degrees about the y-axis of frame {A}. Write the SO(3) rotation matrix that will transform the coordinates of a point, defined with respect to {B}, to the coordinates with respect to {A}.\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":44893,"title":"Create a 3D rotation matrix from roll-pitch-yaw angles","description":"Consider a robotics application where the world reference coordinate frame {W} and a robot manipulator arm with an attached tool coordinate frame {T}.  The orientation of {T} is described in terms of roll-pitch-yaw angles defined as a sequence of rotations, starting with the {W} frame, where yaw is about the X axis, pitch is about the Y axis and roll is about the Z axis.","description_html":"\u003cp\u003eConsider a robotics application where the world reference coordinate frame {W} and a robot manipulator arm with an attached tool coordinate frame {T}.  The orientation of {T} is described in terms of roll-pitch-yaw angles defined as a sequence of rotations, starting with the {W} frame, where yaw is about the X axis, pitch is about the Y axis and roll is about the Z axis.\u003c/p\u003e","function_template":"function y = your_fcn_name(rpy)\r\n  % rpy is a vector containing [roll pitch yaw] in units of radians\r\n  y = 0;  % is a 3x3 matrix\r\nend","test_suite":"%%\r\nrpy = [-2,-1,-2]*pi/2; t = [1,2,3]; t_ans = [-3,2,1];\r\nassert(norm(your_fcn_name(rpy)*t' - t_ans') \u003c 10*eps)\r\n\r\n%%\r\nrpy = [-1,2,-2]*pi/2; t = [1,2,3]; t_ans = [-2,1,3];\r\nassert(norm(your_fcn_name(rpy)*t' - t_ans') \u003c 10*eps)\r\n\r\n%%\r\nrpy = [-2,2,1]*pi/2; t = [1,2,3]; t_ans = [1,3,-2];\r\nassert(norm(your_fcn_name(rpy)*t' - t_ans') \u003c 10*eps)\r\n\r\n%%\r\nrpy = [1,-2,0]*pi/2; t = [1,2,3]; t_ans = [2,1,-3];\r\nassert(norm(your_fcn_name(rpy)*t' - t_ans') \u003c 10*eps)","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":13332,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":10,"test_suite_updated_at":"2019-04-24T02:20:45.000Z","rescore_all_solutions":true,"group_id":629,"created_at":"2019-04-23T10:13:54.000Z","updated_at":"2025-11-18T17:54:47.000Z","published_at":"2019-04-24T02:17:05.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\u003eConsider a robotics application where the world reference coordinate frame {W} and a robot manipulator arm with an attached tool coordinate frame {T}. The orientation of {T} is described in terms of roll-pitch-yaw angles defined as a sequence of rotations, starting with the {W} frame, where yaw is about the X axis, pitch is about the Y axis and roll is about the Z axis.\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":44895,"title":"Determine roll pitch yaw angles from a 3D rotation matrix","description":"Consider an aerospace application where the world reference coordinate frame {W} and a body-fixed coordinate frame {B}.  The origins of {W} and {B} are coincident.  The orientation of {B} is described in terms of roll-pitch-yaw angles defined as a sequence of rotations where yaw is about the Z, pitch is about the Y axis and roll is about the X axis.\r\n\r\nGiven an SO(3) rotation matrix describing the orientation of {B} with respect to {W} determine the roll-pitch-yaw angles.","description_html":"\u003cp\u003eConsider an aerospace application where the world reference coordinate frame {W} and a body-fixed coordinate frame {B}.  The origins of {W} and {B} are coincident.  The orientation of {B} is described in terms of roll-pitch-yaw angles defined as a sequence of rotations where yaw is about the Z, pitch is about the Y axis and roll is about the X axis.\u003c/p\u003e\u003cp\u003eGiven an SO(3) rotation matrix describing the orientation of {B} with respect to {W} determine the roll-pitch-yaw angles.\u003c/p\u003e","function_template":"function rpy = your_fcn_name(R)\r\n  % rpy is a 1x3 vector [roll pitch yaw]\r\n  rpy = 0;\r\nend","test_suite":"%% handle regular case\r\n\r\n% compute random SO(3)\r\nfor count = 1:5\r\n  rpy = (rand(1,3)-0.5)*pi;\r\n  r = rpy(1); p = rpy(2); y = rpy(3);\r\n\r\n  rpy2r = @(r,p,y) reshape([cos(p).*cos(y),cos(p).*sin(y),-sin(p),-cos(r).*sin(y)+cos(y).*sin(p).*sin(r),cos(r).*cos(y)+sin(p).*sin(r).*sin(y),cos(p).*sin(r),sin(r).*sin(y)+cos(r).*cos(y).*sin(p),-cos(y).*sin(r)+cos(r).*sin(p).*sin(y),cos(p).*cos(r)],[3,3]);\r\n  R_correct = rpy2r(r, p, y);\r\n\r\n  % user's estimate\r\n  rpy = your_fcn_name(R_correct);\r\n  r = rpy(1); p = rpy(2); y = rpy(3);\r\n\r\n  err = R_correct' * rpy2r(r,p,y) - eye(3,3);\r\n  assert(norm(err) \u003c 10*eps)\r\nend\r\n\r\n%% handle singular case\r\nrpy = (rand(1,3)-0.5)*pi;\r\nr = rpy(1); p = pi/2; y = rpy(3);\r\n\r\nrpy2r = @(r,p,y) reshape([cos(p).*cos(y),cos(p).*sin(y),-sin(p),-cos(r).*sin(y)+cos(y).*sin(p).*sin(r),cos(r).*cos(y)+sin(p).*sin(r).*sin(y),cos(p).*sin(r),sin(r).*sin(y)+cos(r).*cos(y).*sin(p),-cos(y).*sin(r)+cos(r).*sin(p).*sin(y),cos(p).*cos(r)],[3,3]);\r\nR_correct = rpy2r(r, p, y);\r\n\r\n% user's estimate\r\nrpy = your_fcn_name(R_correct);\r\nr = rpy(1); p = rpy(2); y = rpy(3);\r\n\r\nerr = R_correct' * rpy2r(r,p,y) - eye(3,3);\r\nassert(norm(err) \u003c 10*eps)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":5,"created_by":13332,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":"2019-04-24T02:02:23.000Z","rescore_all_solutions":false,"group_id":629,"created_at":"2019-04-23T10:43:03.000Z","updated_at":"2025-11-18T02:44:02.000Z","published_at":"2019-04-23T10:46:56.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\u003eConsider an aerospace application where the world reference coordinate frame {W} and a body-fixed coordinate frame {B}. The origins of {W} and {B} are coincident. The orientation of {B} is described in terms of roll-pitch-yaw angles defined as a sequence of rotations where yaw is about the Z, pitch is about the Y axis and roll is about the X axis.\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\u003eGiven an SO(3) rotation matrix describing the orientation of {B} with respect to {W} determine the roll-pitch-yaw angles.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"so(3)\"","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:\"so(3)\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"so(3)\"","","\"","so(3)","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f25170a3848\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f25170a3708\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f25170a2e48\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f25170a3b68\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f25170a3ac8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f25170a3988\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f25170a38e8\u003e":"tag:\"so(3)\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f25170a38e8\u003e":"tag:\"so(3)\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"so(3)\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"so(3)\"","","\"","so(3)","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f25170a3848\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f25170a3708\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f25170a2e48\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f25170a3b68\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f25170a3ac8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f25170a3988\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f25170a38e8\u003e":"tag:\"so(3)\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f25170a38e8\u003e":"tag:\"so(3)\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":44890,"difficulty_rating":"easy"},{"id":44894,"difficulty_rating":"easy-medium"},{"id":44892,"difficulty_rating":"easy-medium"},{"id":44893,"difficulty_rating":"easy-medium"},{"id":44895,"difficulty_rating":"medium"}]}}