{"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":44245,"title":"Cell Operator *","description":"Please implement operator * for cell:\r\n\r\n  \u003e\u003e {2,3} * 2\r\nans =\r\n  1×4 cell array\r\n    [2]    [3]    [2]    [3]\r\n\u003e\u003e {2,3} * [2 3]\r\nans =\r\n  2×6 cell array\r\n    [2]    [3]    [2]    [3]    [2]    [3]\r\n    [2]    [3]    [2]    [3]    [2]    [3]\r\n\r\nThe |mtimes.m| you submitted will be moved to the class folder |@cell|:\r\n  \r\n  mkdir @cell\r\n  movefile submission/mtimes.m @cell","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: 245.9px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 122.95px; transform-origin: 407px 122.95px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 114px 8px; transform-origin: 114px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ePlease implement operator * for cell:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 183.9px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 91.95px; transform-origin: 404px 91.95px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 48px 8.5px; transform-origin: 48px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u0026gt;\u0026gt; {2,3} * 2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 20px 8.5px; transform-origin: 20px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eans =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003e1\u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(255, 0, 0); border-block-start-color: rgb(255, 0, 0); border-bottom-color: rgb(255, 0, 0); border-inline-end-color: rgb(255, 0, 0); border-inline-start-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(255, 0, 0); perspective-origin: 4px 8.5px; text-decoration: none; text-decoration-color: rgb(255, 0, 0); text-emphasis-color: rgb(255, 0, 0); transform-origin: 4px 8.5px; \"\u003e×\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 28px 8.5px; transform-origin: 28px 8.5px; \"\u003e4 cell \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 20px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 20px 8.5px; \"\u003earray\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 104px 8.5px; transform-origin: 104px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e  [2]    [3]    [2]    [3]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 64px 8.5px; transform-origin: 64px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u0026gt;\u0026gt; {2,3} * [2 3]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 20px 8.5px; transform-origin: 20px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eans =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003e2\u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(255, 0, 0); border-block-start-color: rgb(255, 0, 0); border-bottom-color: rgb(255, 0, 0); border-inline-end-color: rgb(255, 0, 0); border-inline-start-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(255, 0, 0); perspective-origin: 4px 8.5px; text-decoration: none; text-decoration-color: rgb(255, 0, 0); text-emphasis-color: rgb(255, 0, 0); transform-origin: 4px 8.5px; \"\u003e×\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 28px 8.5px; transform-origin: 28px 8.5px; \"\u003e6 cell \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 20px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 20px 8.5px; \"\u003earray\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 160px 8.5px; transform-origin: 160px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e  [2]    [3]    [2]    [3]    [2]    [3]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 160px 8.5px; transform-origin: 160px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e  [2]    [3]    [2]    [3]    [2]    [3]\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; 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: 2px 8px; transform-origin: 2px 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 c = m_times(a, b)\r\n%STAY HOME, STAY SAFE\r\n%WEAR A MASK\r\nend","test_suite":"%%\r\na = {2 3};\r\nb = 2; \r\nassert(isequal(m_times(a,b),{2 3 2 3}))\r\n\r\n%%\r\na = {[1 2] 3};\r\nb = [2 3]; \r\nassert(isequal(m_times(a,b),{[1 2] 3 [1 2] 3 [1 2] 3; [1 2] 3 [1 2] 3 [1 2] 3}))\r\n\r\n%%\r\na = {-3 -2 -1};\r\nb = 3; \r\nassert(isequal(m_times(a,b),{-3 -2 -1 -3 -2 -1 -3 -2 -1}))\r\n\r\n%%\r\na = {exp(1) pi};\r\nb = 1; \r\nassert(isequal(m_times(a,b),{exp(1) pi}))\r\n\r\n%%\r\na = {2 3 5 7};\r\nb = [1 2]; \r\nassert(isequal(m_times(a,b),{2 3 5 7 2 3 5 7}))\r\n\r\n%%\r\na = {44245 255 -27};\r\nb = [3 1]; \r\nassert(isequal(m_times(a,b),{44245 255 -27;44245 255 -27;44245 255 -27}))\r\n\r\n%%\r\na = {[9 5 21] 7};\r\nb = [2 2]; \r\nassert(isequal(m_times(a,b),{[9 5 21] 7 [9 5 21] 7; [9 5 21] 7 [9 5 21] 7}))","published":true,"deleted":false,"likes_count":2,"comments_count":3,"created_by":1434,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":27,"test_suite_updated_at":"2021-05-09T15:23:59.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-06-28T18:12:59.000Z","updated_at":"2026-03-14T17:23:57.000Z","published_at":"2017-06-28T18:12:59.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\u003ePlease implement operator * for cell:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[\u003e\u003e {2,3} * 2\\nans =\\n1×4 cell array\\n  [2]    [3]    [2]    [3]\\n\u003e\u003e {2,3} * [2 3]\\nans =\\n2×6 cell array\\n  [2]    [3]    [2]    [3]    [2]    [3]\\n  [2]    [3]    [2]    [3]    [2]    [3]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\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":2892,"title":"Deriving a function using the difference quotient","description":"Write a function that evaluates the derivative of a function in a given point using the well-know formula of the difference quotient:\r\n\r\n  f'(x)=(f(x+h)-\u0000f(x\u0000-h))/(2*h)\r\n\r\nExample:\r\n\r\n  input: @sin,pi/4,1e-4\r\n  output: 0.7071\r\n","description_html":"\u003cp\u003eWrite a function that evaluates the derivative of a function in a given point using the well-know formula of the difference quotient:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ef'(x)=(f(x+h)-\u0000f(x\u0000-h))/(2*h)\r\n\u003c/pre\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003einput: @sin,pi/4,1e-4\r\noutput: 0.7071\r\n\u003c/pre\u003e","function_template":"function y = diffquot(fh,x0,h)\r\n  y = x;\r\nend","test_suite":"%%\r\nfh=@sin; x0=pi/4; h=1e-4;\r\ny_correct = 0.707106780007960;\r\ntol=1e-4;\r\nassert(abs(diffquot(fh,x0,h)-y_correct)\u003ctol);\r\n\r\n%% \r\nfh=@(x) x^2+1; x0=2; h=1e-4;\r\ny_correct = 4.000000\r\ntol=1e-4;\r\nassert(abs(diffquot(fh,x0,h)-y_correct)\u003ctol);\r\n\r\n\r\n%% \r\nfh=@(x) 3*sqrt(x^2+1); x0=5; h=1e-4;\r\ny_correct = 2.941742027049443\r\ntol=1e-4;\r\nassert(abs(diffquot(fh,x0,h)-y_correct)\u003ctol);\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":33949,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":81,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-01-28T16:21:31.000Z","updated_at":"2026-04-02T09:24:17.000Z","published_at":"2015-01-28T16:23:16.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that evaluates the derivative of a function in a given point using the well-know formula of the difference quotient:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[f'(x)=(f(x+h)-f(x-h))/(2*h)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[input: @sin,pi/4,1e-4\\noutput: 0.7071]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44259,"title":"Product of two multivariate polynomials","description":"MATLAB \u003chttps://www.mathworks.com/help/matlab/polynomials.html has a few functions\u003e for creating and manipulating single-variable polynomials, but outside of the Symbolic Math Toolbox there is nothing for multivariate polynomials such as |y-x^2| or |x^2+y^2+z^2-1|. Generalizing the approach for one variable, we can define an array of coefficients with one dimension for each variable. We will index them in decreasing order, for example if |p(x) = A + B x^3|, then the coefficients are\r\n\r\n  c = [B 0 0 A].\r\n\r\nNote this is same order as used by the builtin functions. A couple more examples: if |p(x,y) = x - y^2|, then\r\n\r\n  c = [0 -1; 0 0; 1 0].\r\n\r\nIf |p(x,y,z) = z-2|, then |c| has dimensions |[1 1 2]| with |c(:,:,1) = 1| and |c(:,:,2) = -2|.\r\n\r\nThe challenge is to create a function |polyMult| that takes two arrays of coefficients for polynomials |p1| and |p2| and returns the coefficients for |p1*p2|. See the tests for examples.","description_html":"\u003cp\u003eMATLAB \u003ca href = \"https://www.mathworks.com/help/matlab/polynomials.html\"\u003ehas a few functions\u003c/a\u003e for creating and manipulating single-variable polynomials, but outside of the Symbolic Math Toolbox there is nothing for multivariate polynomials such as \u003ctt\u003ey-x^2\u003c/tt\u003e or \u003ctt\u003ex^2+y^2+z^2-1\u003c/tt\u003e. Generalizing the approach for one variable, we can define an array of coefficients with one dimension for each variable. We will index them in decreasing order, for example if \u003ctt\u003ep(x) = A + B x^3\u003c/tt\u003e, then the coefficients are\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = [B 0 0 A].\r\n\u003c/pre\u003e\u003cp\u003eNote this is same order as used by the builtin functions. A couple more examples: if \u003ctt\u003ep(x,y) = x - y^2\u003c/tt\u003e, then\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = [0 -1; 0 0; 1 0].\r\n\u003c/pre\u003e\u003cp\u003eIf \u003ctt\u003ep(x,y,z) = z-2\u003c/tt\u003e, then \u003ctt\u003ec\u003c/tt\u003e has dimensions \u003ctt\u003e[1 1 2]\u003c/tt\u003e with \u003ctt\u003ec(:,:,1) = 1\u003c/tt\u003e and \u003ctt\u003ec(:,:,2) = -2\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eThe challenge is to create a function \u003ctt\u003epolyMult\u003c/tt\u003e that takes two arrays of coefficients for polynomials \u003ctt\u003ep1\u003c/tt\u003e and \u003ctt\u003ep2\u003c/tt\u003e and returns the coefficients for \u003ctt\u003ep1*p2\u003c/tt\u003e. See the tests for examples.\u003c/p\u003e","function_template":"function c = polyMult(c1,c2)\r\n  y = c1*c2;\r\nend","test_suite":"%% Test polyMult\r\nfiletext = fileread('polyMult.m');\r\nassert(~contains(filetext,'regexp'))\r\n\r\n%% p1 = A*x, p2 = B*y\r\nc1 = randi(1000); c2 = randi(1000);\r\nassert(isequal(c1*c2,polyMult(c1,c2)))\r\n\r\n%% p1 = y-x^2, p2 = x-2\r\nc1 = [0 -1; 0 0; 1 0];\r\nc2 = [1; -2];\r\nc = [0 -1; 0 2; 1 0; -2 0];\r\nassert(isequal(c,polyMult(c1,c2)))\r\n\r\n%% p1 = y-x^2, p2 = z-2\r\nc1 = [0 -1; 0 0; 1 0];\r\nc2 = reshape([1; -2],[1 1 2]);\r\nc = reshape([0 0 1 -1 0 0 0 0 -2 2 0 0],[3 2 2]);\r\nassert(isequal(c,polyMult(c1,c2)))\r\n\r\n%% p1 = z-x^3, p2 = y-x^2, p3 = x^2+y^2+z^2-1, p4 = z-2\r\nc1 = reshape([0 0 0 1 -1 0 0 0],[4 1 2]);\r\nc2 = [0 -1; 0 0; 1 0];\r\nc3 = zeros([3 3 3]);\r\nc3([9 21 25]) = [1 1 1];\r\nc3(27) = -1;\r\nc4 = reshape([1; -2],[1 1 2]);\r\nc = zeros(8,4,5);\r\nc([56 91 104 118 126 139 149 153]) = -2*ones(1,8);\r\nc([30 53 78 88 92 101 115 123]) = -1*ones(1,8);\r\nc([24 59 72 86 94 107 117 121]) =  1*ones(1,8);\r\nc([62 85 110 120 124 133 147 155]) =  2*ones(1,8);\r\nassert(isequal(c,polyMult(c1,polyMult(c2,polyMult(c3,c4)))))\r\n\r\n%% Commutative\r\nc1 = randi(1000,[2 3 4]);\r\nc2 = randi(1000,[4 5 1]);\r\nassert(isequal(polyMult(c1,c2),polyMult(c2,c1)))","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":1011,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":21,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-07-11T22:41:35.000Z","updated_at":"2025-12-22T12:43:34.000Z","published_at":"2017-07-11T22:43:47.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMATLAB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/help/matlab/polynomials.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehas a few functions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e for creating and manipulating single-variable polynomials, but outside of the Symbolic Math Toolbox there is nothing for multivariate polynomials such as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey-x^2\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\u003ex^2+y^2+z^2-1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Generalizing the approach for one variable, we can define an array of coefficients with one dimension for each variable. We will index them in decreasing order, for example if\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\u003ep(x) = A + B x^3\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, then the coefficients are\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[c = [B 0 0 A].]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote this is same order as used by the builtin functions. A couple more examples: if\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\u003ep(x,y) = x - y^2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, then\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[c = [0 -1; 0 0; 1 0].]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\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\u003ep(x,y,z) = z-2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, then\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\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e has dimensions\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\u003e[1 1 2]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with\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\u003ec(:,:,1) = 1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ec(:,:,2) = -2\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\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe challenge is to create a function\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003epolyMult\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that takes two arrays of coefficients for polynomials\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\u003ep1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ep2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and returns the coefficients for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ep1*p2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. See the tests for examples.\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":42848,"title":"Lambert's W","description":"Matlab cody does not support lambertw. Try to create a lambert's w function yourself.\r\n\r\nLambert's W is the function that solves \r\n\r\n  x*exp(x) = A;\r\n\r\ngiven the value of A.\r\n\r\nRead more about Lambert's W \u003chttps://en.wikipedia.org/wiki/Lambert_W_function here\u003e.\r\n\r\nThough it is not particularly appropriate for this particular function, consider using \u003chttps://en.wikipedia.org/wiki/Newton's_method Newton-Raphson's method\u003e. Since all test cases will converge if starting with 0.\r\n\r\nThe relative tolerance for the result of x*exp(x) compared to A is 1e-5.","description_html":"\u003cp\u003eMatlab cody does not support lambertw. Try to create a lambert's w function yourself.\u003c/p\u003e\u003cp\u003eLambert's W is the function that solves\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex*exp(x) = A;\r\n\u003c/pre\u003e\u003cp\u003egiven the value of A.\u003c/p\u003e\u003cp\u003eRead more about Lambert's W \u003ca href = \"https://en.wikipedia.org/wiki/Lambert_W_function\"\u003ehere\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eThough it is not particularly appropriate for this particular function, consider using \u003ca href = \"https://en.wikipedia.org/wiki/Newton's_method\"\u003eNewton-Raphson's method\u003c/a\u003e. Since all test cases will converge if starting with 0.\u003c/p\u003e\u003cp\u003eThe relative tolerance for the result of x*exp(x) compared to A is 1e-5.\u003c/p\u003e","function_template":"function x = LambertW(A)\r\n  y = log(x);\r\nend","test_suite":"%%\r\nA = 1;\r\nx = LambertW(A);\r\nA_correct = x*exp(x);\r\nassert(abs(A_correct/A-1)\u003c1e-5)\r\n\r\n%%\r\nA = 6.8;\r\nx = LambertW(A);\r\nA_correct = x*exp(x);\r\nassert(abs(A_correct/A-1)\u003c1e-5)\r\n\r\n%%\r\nA = 14;\r\nx = LambertW(A);\r\nA_correct = x*exp(x);\r\nassert(abs(A_correct/A-1)\u003c1e-5)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":12767,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":52,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-05-05T14:37:35.000Z","updated_at":"2025-12-07T18:24:23.000Z","published_at":"2016-05-05T14:38:09.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMatlab cody does not support lambertw. Try to create a lambert's w function yourself.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLambert's W is the function that solves\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[x*exp(x) = A;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003egiven the value of A.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRead more about Lambert's W\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Lambert_W_function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehere\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThough it is not particularly appropriate for this particular function, consider using\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Newton's_method\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eNewton-Raphson's method\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Since all test cases will converge if starting with 0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe relative tolerance for the result of x*exp(x) compared to A is 1e-5.\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":44083,"title":"First use of arrayfun() and anonymous function @(x)","description":"Create an anonymous function using @(x) for a parabola equation for the given coefficients stored in s with\r\ns(1)x2 + s(2)x + s(3).\r\nUse arrayfun() to apply the parabola equation to each element in the array A.\r\nNote: for , while , and eval are forbidden.\r\nHave fun :o)","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: 141px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 70.5px; transform-origin: 407px 70.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 337px 8px; transform-origin: 337px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eCreate an anonymous function using @(x) for a parabola equation for the given coefficients stored in s with\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: 65.5px 8px; transform-origin: 65.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003es(1)x2 + s(2)x + s(3).\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: 243px 8px; transform-origin: 243px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eUse arrayfun() to apply the parabola equation to each element in the array A.\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: 16.5px 8px; transform-origin: 16.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eNote:\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: 8.5px 8px; transform-origin: 8.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003efor\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\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: 15.5px 8px; transform-origin: 15.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003ewhile\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: 18px 8px; transform-origin: 18px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e , and\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: 12.5px 8px; transform-origin: 12.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eeval\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: 46.5px 8px; transform-origin: 46.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e are forbidden.\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=\"\"\u003eHave fun :o)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function B = parabola_equation(A,s)\r\n    \r\n  B = A;\r\n  \r\nend","test_suite":"%%\r\nA = [0 1 2];\r\ns = [1 2 3];\r\ny_correct = [3 6 11];\r\nassert(isequal(parabola_equation(A,s),y_correct))\r\n%%\r\nA = -12:4:11;\r\ns = [-5 -8 0];\r\ny_correct = [-624  -256   -48     0  -112  -384];\r\nassert(isequal(parabola_equation(A,s),y_correct))\r\n%%\r\nA = -2:2;\r\ns = [0 pi 0];\r\ny_correct = [-2*pi -pi 0  pi 2*pi];\r\nassert(isequal(parabola_equation(A,s),y_correct))\r\n%%\r\nassert(isempty(regexp(evalc('type parabola_equation'),'(eval|for|while|polyval|)')))\r\nassert(not(isempty(regexp(evalc('type parabola_equation'),'(@)'))))\r\nassert(not(isempty(regexp(evalc('type parabola_equation'),'arrayfun'))))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":100084,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":72,"test_suite_updated_at":"2022-03-01T19:46:58.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-03-10T22:47:36.000Z","updated_at":"2026-03-16T13:46:36.000Z","published_at":"2017-03-10T22:48:28.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCreate an anonymous function using @(x) for a parabola equation for the given coefficients stored in s with\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\u003es(1)x2 + s(2)x + s(3).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eUse arrayfun() to apply the parabola equation to each element in the array A.\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\u003eNote:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003efor\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:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ewhile\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eeval\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are forbidden.\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\u003eHave fun :o)\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":42793,"title":"Fast 1-D Convolution (full shape)","description":"This is the first problem in the \u003chttp://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution fast 1-D convolution series\u003e. This problem asks you to find a fast algorithm to compute the 1-D convolution in its full output shape.  \r\n\r\nThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in *conv* function invoked in the form *conv(u,v,'full')*, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out. \r\n\r\n* Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape Fast 1-D Convolution (same shape)\u003e.","description_html":"\u003cp\u003eThis is the first problem in the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\"\u003efast 1-D convolution series\u003c/a\u003e. This problem asks you to find a fast algorithm to compute the 1-D convolution in its full output shape.\u003c/p\u003e\u003cp\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in \u003cb\u003econv\u003c/b\u003e function invoked in the form \u003cb\u003econv(u,v,'full')\u003c/b\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/p\u003e\u003cul\u003e\u003cli\u003eNext problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape\"\u003eFast 1-D Convolution (same shape)\u003c/a\u003e.\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = fconv1f(u,v)\r\n  y = conv(u,v,'full');   % Extremely inefficient solution!\r\nend","test_suite":"%%\r\n%{\r\n╔═════════════════════════════════════════════════════════════╗\r\n║ Please note that problems in this series are designed for   ║\r\n║ optimizing the code performance, rather than the usual Cody ║\r\n║ \"size\". We are achieving this goal by courtesy of LY Cao's  ║ \r\n║ new scoring function, which automatically grants a better   ║\r\n║ score to a faster solution. Kindly note that simply using   ║\r\n║ the conv function may result in a poor score or even failure║\r\n║ in one of the tests. Suggestions and comments are welcome.  ║\r\n║                                                             ║\r\n║ Thanks \u0026 have fun!                                          ║\r\n║ Peng                                                        ║\r\n╚═════════════════════════════════════════════════════════════╝\r\n%}\r\n\r\n%%\r\nfid = fopen('EvaluateSolution.p','wb'); \r\nfwrite(fid,uint8(sscanf('7630312E30307630302E30300005B01CF7473FB1000000B50000010D000001A93014D309F9979F2A2C808C4F104ACA1480D0378FBCF4FF1C4C94A38C84A4969D0A597F5F12C8D564E7CD9584DF8BDD849A3B8C5FDEB66A3837A064275728B38736860BB79ABC4B3091D37C9A2010BE0378E708E59716738F85AA4AEBC8982C45E6CD45BAD19BD043D16D5834122D405752633CE6BD78ABA0676336E7BCDD4F2E181FF1CE8E9165F6BF30D850ED74385A40BDEB73AD82518B4CF2BB034951B1D23D360EDF335C22C209AAB3857BCEF61D192170FDE9D5449721A6B6DD082257E430059753696F1C5CD66E6B09AD24270B0335E830203EACA5BDF3E2A57620D5DB44A96AFCDE0387EF112F2A83FBF90E4AF09F9D4FCAA22134055610D0F7B55568D50A52CD5C46A3F0CA655C1B68','%2x')));\r\nfclose(fid);\r\n\r\n%%\r\nu = 1; v = 1;\r\ny_correct = 1;\r\nassert(isequal(fconv1f(u,v),y_correct))\r\n\r\n%%\r\nu = 1:10; v = 1:5;\r\ny_correct = [1,4,10,20,35,50,65,80,95,110,114,106,85,50];\r\nassert(all(abs(fconv1f(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = [2 -4 0 1].'; v = [1:5].';\r\ny_correct = [2,0,-2,-3,-4,-17,4,5].';\r\nassert(all(abs(fconv1f(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(20,1); v = rand(10,1);\r\ny_correct = conv(u,v,'full');\r\nassert(all(abs(fconv1f(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\n% Large data size\r\nglobal sol_score\r\nu = rand(8e5,1); v = rand(1e5,1);\r\nt = builtin('tic');\r\ny = fconv1f(u,v);\r\nsol_score = 50*builtin('toc',t);\r\nAbsTol = 1e-6;   % Maximum absolute error tolerance\r\npass = EvaluateSolution(u,v,y,AbsTol);  \r\nassert(pass);\r\n\r\n%%\r\n% New scoring function by LY Cao\r\nglobal sol_score\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\nscore(sol_score);\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":6,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":34,"test_suite_updated_at":"2016-04-04T03:53:09.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-04-02T21:05:59.000Z","updated_at":"2025-12-09T13:00:47.000Z","published_at":"2016-04-03T19:56:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the first problem in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efast 1-D convolution series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. This problem asks you to find a fast algorithm to compute the 1-D convolution in its full output shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econv\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function invoked in the form\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econv(u,v,'full')\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNext problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (same shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44324,"title":"Rewrite setdiff to account for non-unique values","description":"Setdiff(a,b) is a function that will remove all values of b from a.  Sometimes, you need this function to do a little bit extra, though.  Write a newer version of setdiff that will take into account numbers appearing multiple times in a.  For example:\r\n\r\na=[8 7 6 5 4 3 2 1 1];\r\nb=[1 3 4 5 6 7];\r\n\r\nIn this example, setdiff(a,b) would return [2 8], since only 2 and 8 are not included in a.  However, there are two \"1\" values in a, and only one \"1\" in b, so new_setdiff should return [1 2 8].  Your output vector should be sorted from low to high.\r\n\r\nYou can assume that there are no Inf or NaN in either vector, and that no values will appear in b more times than will appear in a.\r\n","description_html":"\u003cp\u003eSetdiff(a,b) is a function that will remove all values of b from a.  Sometimes, you need this function to do a little bit extra, though.  Write a newer version of setdiff that will take into account numbers appearing multiple times in a.  For example:\u003c/p\u003e\u003cp\u003ea=[8 7 6 5 4 3 2 1 1];\r\nb=[1 3 4 5 6 7];\u003c/p\u003e\u003cp\u003eIn this example, setdiff(a,b) would return [2 8], since only 2 and 8 are not included in a.  However, there are two \"1\" values in a, and only one \"1\" in b, so new_setdiff should return [1 2 8].  Your output vector should be sorted from low to high.\u003c/p\u003e\u003cp\u003eYou can assume that there are no Inf or NaN in either vector, and that no values will appear in b more times than will appear in a.\u003c/p\u003e","function_template":"function y = new_setdiff(a,b)\r\n  y = [a,b];\r\nend","test_suite":"%%\r\na=[1 1 2 3 4 5 6 7 8]; b=[1 3 4 5 6 7];\r\ny_correct=[1 2 8];\r\nassert(isequal(new_setdiff(a,b),y_correct))\r\nassert(isequal(new_setdiff(fliplr(a),b),y_correct))\r\nassert(isequal(new_setdiff(a,fliplr(b)),y_correct))\r\n%%\r\na=repmat([1:10],1,2);\r\nb=repmat([1:5],1,2);\r\ny_correct=[6 6 7 7 8 8 9 9 10 10];\r\nassert(isequal(new_setdiff(a,b),y_correct))\r\n%%\r\na=[randperm(10) 3 5 7];\r\nb=randperm(6)+1;\r\ny_correct=[1 3 5 7 8 9 10];\r\nassert(isequal(new_setdiff(a,b),y_correct))\r\n%%\r\na=[-5:5 -4:4];\r\nb=[-4:4];\r\ny_correct=[-5:5]\r\nassert(isequal(new_setdiff(a,b),y_correct))\r\n%%\r\na=[2 2 2 2 3 3 5 7];\r\nb=[2 2 2 2 3 3 5];\r\ny_correct=8;\r\nassert(isequal(new_setdiff(a,b),y_correct-1))\r\n%%\r\na=[21 124 23 20 21 23 124];\r\nb=[20 21 21 23 23];\r\ny_correct=[124 124]\r\nassert(isequal(new_setdiff(a,b),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":32,"test_suite_updated_at":"2018-01-02T15:45:30.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2017-09-14T16:19:26.000Z","updated_at":"2025-12-22T13:27:45.000Z","published_at":"2017-09-14T16:19:26.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eSetdiff(a,b) is a function that will remove all values of b from a. Sometimes, you need this function to do a little bit extra, though. Write a newer version of setdiff that will take into account numbers appearing multiple times in a. For example:\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\u003ea=[8 7 6 5 4 3 2 1 1]; b=[1 3 4 5 6 7];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn this example, setdiff(a,b) would return [2 8], since only 2 and 8 are not included in a. However, there are two \\\"1\\\" values in a, and only one \\\"1\\\" in b, so new_setdiff should return [1 2 8]. Your output vector should be sorted from low to high.\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\u003eYou can assume that there are no Inf or NaN in either vector, and that no values will appear in b more times than will appear in 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":44704,"title":"Damping of Servomotors with Tachometer Feedback","description":"In Control Engineering, servomotors with tachometer feedback can be modeled by the second order system\r\n\r\n K / [J*s^2 + (B + K*K_v)*s + K] \r\n\r\nDepending on the damping ratio of the servomotor, the system can be classified as underdamped, critically damped or overdamped. In this problem, you will be given the following as input:\r\n\r\nB - damping of servomotor (viscous and friction elements)\r\n\r\nJ - inertia of servomotor\r\n\r\nK - gain of proportional controller\r\n\r\nK_v - velocity feedback constant of tachometer \r\n\r\nYou are to correctly classify the system by returning either ' _underdamped_ ', ' _critical_ ' or ' _overdamped_ '.","description_html":"\u003cp\u003eIn Control Engineering, servomotors with tachometer feedback can be modeled by the second order system\u003c/p\u003e\u003cpre\u003e K / [J*s^2 + (B + K*K_v)*s + K] \u003c/pre\u003e\u003cp\u003eDepending on the damping ratio of the servomotor, the system can be classified as underdamped, critically damped or overdamped. In this problem, you will be given the following as input:\u003c/p\u003e\u003cp\u003eB - damping of servomotor (viscous and friction elements)\u003c/p\u003e\u003cp\u003eJ - inertia of servomotor\u003c/p\u003e\u003cp\u003eK - gain of proportional controller\u003c/p\u003e\u003cp\u003eK_v - velocity feedback constant of tachometer\u003c/p\u003e\u003cp\u003eYou are to correctly classify the system by returning either ' \u003ci\u003eunderdamped\u003c/i\u003e ', ' \u003ci\u003ecritical\u003c/i\u003e ' or ' \u003ci\u003eoverdamped\u003c/i\u003e '.\u003c/p\u003e","function_template":"function damp = ServoDamp(B,J,K,K_v)\r\n % damp?   \r\n  switch B \u003e B_c     %Critical damping\r\n      case 1\r\n          'underdamped'\r\n      case 2\r\n          'critical'\r\n      case 3\r\n          'overdamped'\r\n  end\r\nend","test_suite":"%%\r\nB = 1; J = 1; K = 12.5; K_v = 0.1;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'underdamped'))\r\n\r\n%%\r\nB = 2; J = 1; K = 4; K_v = 0.5;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'critical'))\r\n\r\n%%\r\nB = 1; J = 1; K = 12.5; K_v = 0.5;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'overdamped'))\r\n\r\n%%\r\nB = 2; J = 2; K = 8; K_v = 0.75;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'critical'))\r\n\r\n%%\r\nB = 2; J = 2; K = 10; K_v = 0.75;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'overdamped'))\r\n\r\n%%\r\nB = 1; J = 2; K = 10; K_v = 0.75;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'underdamped'))\r\n\r\n%%\r\nB = rand; J = 2; K = 10; K_v = 0.75;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'underdamped'))\r\n\r\n%%\r\nB = rand; J = 2; K = 10; K_v = 1;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'overdamped'))\r\n\r\n%%\r\nB = rand; J = 1; K = 10; K_v = 1;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'overdamped'))\r\n\r\n%%\r\nB = 3; J = 3; K = 3; K_v = 1;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'critical'))\r\n\r\n%%\r\nB = 4; J = 4; K = 4; K_v = 1;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'critical'))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":178544,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":42,"test_suite_updated_at":"2018-08-02T17:30:44.000Z","rescore_all_solutions":false,"group_id":67,"created_at":"2018-08-01T23:16:46.000Z","updated_at":"2025-12-07T05:40:58.000Z","published_at":"2018-08-02T08:43:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn Control Engineering, servomotors with tachometer feedback can be modeled by the second order system\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ K / [J*s^2 + (B + K*K_v)*s + K]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDepending on the damping ratio of the servomotor, the system can be classified as underdamped, critically damped or overdamped. In this problem, you will be given the following as input:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eB - damping of servomotor (viscous and friction elements)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eJ - inertia of servomotor\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eK - gain of proportional controller\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eK_v - velocity feedback constant of tachometer\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou are to correctly classify the system by returning either '\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eunderdamped\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:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecritical\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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eoverdamped\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\"},{\"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":42795,"title":" Fast 1-D Convolution (valid shape) ","description":"Pursuant to the first problem in the \u003chttp://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution fast 1-D convolution series\u003e, this problem asks for the fast algorithm to compute the 1-D convolution in its \"valid\" output shape.  \r\n\r\nThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in *conv* function invoked in the form *conv(u,v,'valid')*, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out. \r\n\r\n* Previous problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape Fast 1-D Convolution (same shape)\u003e.","description_html":"\u003cp\u003ePursuant to the first problem in the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\"\u003efast 1-D convolution series\u003c/a\u003e, this problem asks for the fast algorithm to compute the 1-D convolution in its \"valid\" output shape.\u003c/p\u003e\u003cp\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in \u003cb\u003econv\u003c/b\u003e function invoked in the form \u003cb\u003econv(u,v,'valid')\u003c/b\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/p\u003e\u003cul\u003e\u003cli\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape\"\u003eFast 1-D Convolution (same shape)\u003c/a\u003e.\u003c/li\u003e\u003c/ul\u003e","function_template":"function w = fconv1v(u,v)\r\n  % Extremely inefficient solution not guaranteed to pass all tests :-(\r\n  w = conv(u,v,'valid'); \r\nend","test_suite":"%%\r\n%{\r\n╔═════════════════════════════════════════════════════════════╗\r\n║ Please note that problems in this series are designed for   ║\r\n║ optimizing the code performance, rather than the usual Cody ║\r\n║ \"size\". We are achieving this goal by courtesy of LY Cao's  ║ \r\n║ new scoring function, which automatically grants a better   ║\r\n║ score to a faster solution. Kindly note that simply using   ║\r\n║ the conv function may result in a poor score or even failure║\r\n║ in one of the tests. Suggestions and comments are welcome.  ║\r\n║                                                             ║\r\n║ Thanks \u0026 have fun!                                          ║\r\n║ Peng                                                        ║\r\n╚═════════════════════════════════════════════════════════════╝\r\n%}\r\n\r\n%%\r\nfid = fopen('EvaluateSolution.p','wb'); \r\nfwrite(fid,uint8(sscanf('7630312E30307630302E3030000CF01CCC561FB1000000C30000012D000001D160E44E2EC6DB5CE66B30F9B560AF40D6A7226365293F6413AE84ABD44D4C7EE5C617DCDAC2521B24B2951C23F50BA9DAA4179B35DCED27A697FC9CA9A308698729973CACEC16670C077236F96E9D16612152B0C32FC57E4755E80E40AC876804B7835D9703BC5A1D6FC519FDEDE22237DC59455FF0014FEBCEF1CB2A840158E11CDD5D6C78D594F50B575A4DF9FB54705F2C6D40341F12CE207B892CBEDEC018A1F94CFA1D5FBB9E1912BA424CD5C6C422D6F3451A8BDD2543834B3FFAD3107D8F16C78D75DD9F3AD197D5591B1686E190D8DF4B5EF3AC28C641296E92FB02BC395D442C03480E156E48F8B61AA3C6F1526AA95C1C466C77A3803AF8523098B0A3ED10A07E2F93274DC8207B05A572988754AAC211A330C2FEC7928CFD51D3A6FBDD9FFA6036C948E0C4239A16','%2x')));\r\nfclose(fid);\r\n\r\n%%\r\nu = 1; v = 1;\r\ny_correct = 1;\r\nassert(isequal(fconv1v(u,v),y_correct))\r\n\r\n%%\r\nu = 1:10; v = 1:5;\r\ny_correct = conv(u,v,'valid');\r\nassert(all(abs(fconv1v(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = 1:5; v = 1:10;\r\ny_correct = zeros(1,0);\r\nassert(isequal(fconv1v(u,v),y_correct))\r\n\r\n%%\r\nu = rand(20,1); v = rand(10,1);\r\ny_correct = conv(u,v,'valid');\r\nassert(all(abs(fconv1v(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(10,1); v = rand(20,1);\r\ny_correct = zeros(0,1);\r\nassert(isequal(fconv1v(u,v),y_correct))\r\n\r\n%%\r\n% Large data size\r\nglobal sol_score\r\nAbsTol = 1e-6;   % Maximum absolute error tolerance\r\nuu = rand(5e6,15); vv = rand(2e5,15);\r\nfor iter = 15:-1:1\r\n    u = uu(:,iter); v = vv(:,iter);\r\n    t = builtin('tic');\r\n    y = fconv1v(u,v);\r\n    timeSpan(iter) = builtin('toc',t);\r\n    pass(iter) = EvaluateSolution(u,v,y,AbsTol);  \r\nend\r\nsol_score = sum(timeSpan);\r\nassert(all(pass));\r\n\r\n%%\r\n% New scoring function by LY Cao\r\nglobal sol_score\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\nscore(sol_score);","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2016-04-05T21:09:16.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2016-04-02T21:30:34.000Z","updated_at":"2025-12-21T14:08:51.000Z","published_at":"2016-04-04T01:47:39.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the first problem in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efast 1-D convolution series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, this problem asks for the fast algorithm to compute the 1-D convolution in its \\\"valid\\\" output shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econv\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function invoked in the form\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econv(u,v,'valid')\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (same shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44260,"title":"Multivariate polynomials - convert monomial form to array","description":"In \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44259-product-of-two-multidimensional-polynomials Problem 44259\u003e I asked you to multiply two multidimensional polynomials that were represented by an array that is a generalization of the way MATLAB handles one-variable polynomials. However, that representation has at least two problems:\r\n\r\n# Defining a polynomial is an indexing headache, with a high probability of errors.  \r\n# Polynomials often have a small number of terms, so if they are higher order there will be a lot of wasted storage.\r\n\r\nHere, we will represent a polynomial as a sum of monomials. For example, the polynomial |p(x,y) = 2*x^5*y + 3*x*y^5| is the sum of two monomials in |x| and |y|. We will represent this by |exponents|, a matrix of integers with each row representing the exponents of one monomial (including zeros); and a column vector |coefficients| for the coefficient of each monomial. For |p(x,y)|, these are\r\n\r\n  exponents = [5 1; 1 5];\r\ncoefficients = [2; 3];\r\n\r\nLet's hedge our bets, though, and create a function that converts this form to the array form. Your task is to create a function\r\n\r\n  function c = coeffArray(exponents,coefficients)\r\n\r\nthat inputs the exponents and coefficients and returns an array as defined in Problem 44259.","description_html":"\u003cp\u003eIn \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44259-product-of-two-multidimensional-polynomials\"\u003eProblem 44259\u003c/a\u003e I asked you to multiply two multidimensional polynomials that were represented by an array that is a generalization of the way MATLAB handles one-variable polynomials. However, that representation has at least two problems:\u003c/p\u003e\u003col\u003e\u003cli\u003eDefining a polynomial is an indexing headache, with a high probability of errors.\u003c/li\u003e\u003cli\u003ePolynomials often have a small number of terms, so if they are higher order there will be a lot of wasted storage.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eHere, we will represent a polynomial as a sum of monomials. For example, the polynomial \u003ctt\u003ep(x,y) = 2*x^5*y + 3*x*y^5\u003c/tt\u003e is the sum of two monomials in \u003ctt\u003ex\u003c/tt\u003e and \u003ctt\u003ey\u003c/tt\u003e. We will represent this by \u003ctt\u003eexponents\u003c/tt\u003e, a matrix of integers with each row representing the exponents of one monomial (including zeros); and a column vector \u003ctt\u003ecoefficients\u003c/tt\u003e for the coefficient of each monomial. For \u003ctt\u003ep(x,y)\u003c/tt\u003e, these are\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eexponents = [5 1; 1 5];\r\ncoefficients = [2; 3];\r\n\u003c/pre\u003e\u003cp\u003eLet's hedge our bets, though, and create a function that converts this form to the array form. Your task is to create a function\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003efunction c = coeffArray(exponents,coefficients)\r\n\u003c/pre\u003e\u003cp\u003ethat inputs the exponents and coefficients and returns an array as defined in Problem 44259.\u003c/p\u003e","function_template":"function c = coeffArray(exponents,coefficients)\r\nc = 0;\r\nend","test_suite":"%% test coeffArray\r\nfiletext = fileread('coeffArray.m');\r\nassert(~contains(filetext,'regexp'))\r\n\r\n%% No variables\r\nexponents = 0;\r\ncoefficients = randi(1000);\r\ncA = coefficients;\r\nassert(isequal(coeffArray(exponents,coefficients),cA))\r\n\r\n%% Single variable\r\ncoefficients = randi(1000,[10 1]);\r\nexponents = (9:-1:0)';\r\ncA = coefficients;\r\nassert(isequal(coeffArray(exponents,coefficients),cA))\r\n\r\n%% a*x^2+b*y\r\na = randi(1000);\r\nb = randi(1000);\r\nexponents = [2 0; 0 1];\r\ncoefficients = [a; b];\r\ncA = [0 a; 0 0; b 0];\r\nassert(isequal(coeffArray(exponents,coefficients),cA))\r\n\r\n%% a*x^2+b*y^2+c*z^2+d\r\na = randi(1000);\r\nb = randi(1000);\r\nc = randi(1000);\r\nd = randi(1000);\r\nexponents = [2 0 0; 0 2 0; 0 0 2; 0 0 0];\r\ncoefficients = [a; b; c; d];\r\ncA = zeros([3 3 3]);\r\ncA(1,3,3) = a;\r\ncA(3,1,3) = b;\r\ncA(3,3,1) = c;\r\ncA(3,3,3) = d;\r\nassert(isequal(coeffArray(exponents,coefficients),cA))\r\n\r\n%% Many variables\r\ncoefficients = randi(1000);\r\nnVars = randi(20)+1;\r\nexponents = ones(1,nVars);\r\ncA = zeros(2*ones(1,nVars));\r\ncA(1) = coefficients;\r\nassert(isequal(coeffArray(exponents,coefficients),cA))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":8,"created_by":1011,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":12,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-07-13T16:16:41.000Z","updated_at":"2025-12-22T13:09:01.000Z","published_at":"2017-07-13T16:26:38.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44259-product-of-two-multidimensional-polynomials\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44259\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e I asked you to multiply two multidimensional polynomials that were represented by an array that is a generalization of the way MATLAB handles one-variable polynomials. However, that representation has at least two problems:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDefining a polynomial is an indexing headache, with a high probability of errors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePolynomials often have a small number of terms, so if they are higher order there will be a lot of wasted storage.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHere, we will represent a polynomial as a sum of monomials. For example, the polynomial\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\u003ep(x,y) = 2*x^5*y + 3*x*y^5\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is the sum of two monomials in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. We will represent this by\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eexponents\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, a matrix of integers with each row representing the exponents of one monomial (including zeros); and a column vector\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\u003ecoefficients\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for the coefficient of each monomial. For\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ep(x,y)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, these are\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[exponents = [5 1; 1 5];\\ncoefficients = [2; 3];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet's hedge our bets, though, and create a function that converts this form to the array form. Your task is to create a function\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[function c = coeffArray(exponents,coefficients)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethat inputs the exponents and coefficients and returns an array as defined in Problem 44259.\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":44262,"title":"Multivariate polynomials - overload multiplication","description":"Problems \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44260-multivariate-polynomials-convert-monomial-form-to-array 44260\u003e and \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44261-sort-multivariate-monomials 44261\u003e work with a monomial representation of multivariate polynomials. This has two parts, a matrix |exponents| with a row of exponents for each monomial, and a column vector |coefficients| with a coefficient for each monomial.\r\n\r\nIt would be nice to define polynomials so they can be multiplied using simple notation:\r\n\r\n  p = p1*p2;\r\n\r\nThis can be done by \u003chttps://www.mathworks.com/help/matlab/matlab_oop/user-defined-classes.html defining a class\u003e |mPoly| with two properties, |exponents| and |coefficients|, and two methods: a \u003chttps://www.mathworks.com/help/matlab/matlab_oop/class-constructor-methods.html constructor\u003e with the syntax\r\n\r\n  p = mPoly(exponents, coefficients)\r\n\r\nand a method \u003chttps://www.mathworks.com/help/matlab/ref/mtimes.html?searchHighlight=mtimes\u0026s_tid=doc_srchtitle mtimes\u003e for multiplying two polynomials. You can assume that the polynomials being multiplied have the same number of variables.\r\n","description_html":"\u003cp\u003eProblems \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44260-multivariate-polynomials-convert-monomial-form-to-array\"\u003e44260\u003c/a\u003e and \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44261-sort-multivariate-monomials\"\u003e44261\u003c/a\u003e work with a monomial representation of multivariate polynomials. This has two parts, a matrix \u003ctt\u003eexponents\u003c/tt\u003e with a row of exponents for each monomial, and a column vector \u003ctt\u003ecoefficients\u003c/tt\u003e with a coefficient for each monomial.\u003c/p\u003e\u003cp\u003eIt would be nice to define polynomials so they can be multiplied using simple notation:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ep = p1*p2;\r\n\u003c/pre\u003e\u003cp\u003eThis can be done by \u003ca href = \"https://www.mathworks.com/help/matlab/matlab_oop/user-defined-classes.html\"\u003edefining a class\u003c/a\u003e \u003ctt\u003emPoly\u003c/tt\u003e with two properties, \u003ctt\u003eexponents\u003c/tt\u003e and \u003ctt\u003ecoefficients\u003c/tt\u003e, and two methods: a \u003ca href = \"https://www.mathworks.com/help/matlab/matlab_oop/class-constructor-methods.html\"\u003econstructor\u003c/a\u003e with the syntax\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ep = mPoly(exponents, coefficients)\r\n\u003c/pre\u003e\u003cp\u003eand a method \u003ca href = \"https://www.mathworks.com/help/matlab/ref/mtimes.html?searchHighlight=mtimes\u0026s_tid=doc_srchtitle\"\u003emtimes\u003c/a\u003e for multiplying two polynomials. You can assume that the polynomials being multiplied have the same number of variables.\u003c/p\u003e","function_template":"classdef mPoly \r\n    %MPOLY Class of multivariate polynomials\r\n    \r\n    properties\r\n        exponents\r\n        coefficients\r\n    end\r\n    \r\n    methods\r\n        function p = mPoly(ex,co)\r\n        end\r\n        function p = mtimes(p1,p2)\r\n        end\r\n    end\r\n    \r\nend\r\n","test_suite":"%% Test polyMult\r\nfiletext = fileread('mPoly.m');\r\nassert(~contains(filetext,'regexp'))\r\n\r\n%% p1 = A, p2 = B\r\nc1 = randi(1000); c2 = randi(1000);\r\ne = 0;\r\np1 = mPoly(e,c1);\r\np2 = mPoly(e,c2);\r\np = p1*p2;\r\nassert(isequal(c1*c2,p.coefficients))\r\nassert(isequal(e,p.exponents))\r\n\r\n%% p1 = y-x^2, p2 = x-2\r\ne1 = [2 0; 0 1];\r\nc1 = [-1; 1];\r\ne2 = [1 0; 0 0];\r\nc2 = [1; -2];\r\np1 = mPoly(e1,c1);\r\np2 = mPoly(e2,c2);\r\np = p1*p2;\r\n\r\n[e,idx] = unique(p.exponents,'rows');\r\nc = p.coefficients(idx);\r\nassert(isequal(e,[0 1; 1 1; 2 0; 3 0]))\r\nassert(isequal(c,[-2; 1; 2; -1]))\r\n\r\n%% p1 = y-x^2, p2 = z-2\r\ne1 = [0 1 0; 2 0 0];\r\nc1 = [1; -1];\r\ne2 = [0 0 1; 0 0 0];\r\nc2 = [1; -2];\r\np1 = mPoly(e1,c1);\r\np2 = mPoly(e2,c2);\r\np = p1*p2;\r\n\r\n[e,idx] = unique(p.exponents,'rows');\r\nc = p.coefficients(idx);\r\nassert(isequal(e,[0 1 0; 0 1 1; 2 0 0; 2 0 1]))\r\nassert(isequal(c,[-2; 1; 2; -1]))\r\n\r\n\r\n%% p1 = z-x^3, p2 = x^2+y^2+z^2-1\r\ne1 = [0 0 1; 3 0 0];\r\nc1 = [1; -1];\r\ne2 = [2 0 0; 0 2 0; 0 0 2; 0 0 0];\r\nc2 = [1; 1; 1; -1];\r\n\r\np1 = mPoly(e1,c1);\r\np2 = mPoly(e2,c2);\r\np = p1*p2;\r\n\r\n[e,idx] = unique(p.exponents,'rows');\r\nc = p.coefficients(idx);\r\nassert(isequal(e,[0 0 1; 0 0 3; 0 2 1; 2 0 1; 3 0 0; 3 0 2; 3 2 0; 5 0 0]))\r\nassert(isequal(c,[-1 1 1 1 1 -1 -1 -1]'))\r\n\r\n%% Commutative\r\nc1 = randi(1000,[2 1]);\r\ne1 = randi(1000,[2 2]);\r\nc2 = randi(1000,[3 1]);\r\ne2 = randi(1000,[3 2]);\r\np1 = mPoly(e1,c1);\r\np2 = mPoly(e2,c2);\r\np12 = p1*p2;\r\np21 = p2*p1;\r\n[e12,i12] = unique(p12.exponents,'rows');\r\n[e21,i21] = unique(p21.exponents,'rows');\r\nc12 = p12.coefficients(i12);\r\nc21 = p21.coefficients(i21);\r\nassert(isequal(e12,e21))\r\nassert(isequal(c12,c21))","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":1011,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-07-14T04:04:05.000Z","updated_at":"2025-12-22T13:16:38.000Z","published_at":"2017-07-14T04:04: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\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eProblems\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44260-multivariate-polynomials-convert-monomial-form-to-array\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e44260\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44261-sort-multivariate-monomials\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e44261\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e work with a monomial representation of multivariate polynomials. This has two parts, a matrix\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\u003eexponents\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with a row of exponents for each monomial, and a column vector\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\u003ecoefficients\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with a coefficient for each monomial.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt would be nice to define polynomials so they can be multiplied using simple notation:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[p = p1*p2;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis can be done by\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/help/matlab/matlab_oop/user-defined-classes.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edefining a class\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emPoly\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with two properties,\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\u003eexponents\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecoefficients\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and two methods: a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/help/matlab/matlab_oop/class-constructor-methods.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003econstructor\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e with the syntax\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[p = mPoly(exponents, coefficients)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eand a method\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/help/matlab/ref/mtimes.html?searchHighlight=mtimes\u0026amp;s_tid=doc_srchtitle\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emtimes\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e for multiplying two polynomials. You can assume that the polynomials being multiplied have the same number of variables.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42794,"title":" Fast 1-D Convolution (same shape) ","description":"Pursuant to the first problem in the \u003chttp://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution fast 1-D convolution series\u003e, this problem asks for the fast algorithm to compute the 1-D convolution with the same input-output shape.  \r\n\r\nThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in *conv* function invoked in the form *conv(u,v,'same')*, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out. \r\n\r\n* Previous problem:  \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42793-fast-1-d-convolution-full-shape Fast 1-D Convolution (full shape)\u003e\r\n* Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42795-fast-1-d-convolution-valid-shape Fast 1-D Convolution (valid shape)\u003e\r\n","description_html":"\u003cp\u003ePursuant to the first problem in the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\"\u003efast 1-D convolution series\u003c/a\u003e, this problem asks for the fast algorithm to compute the 1-D convolution with the same input-output shape.\u003c/p\u003e\u003cp\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in \u003cb\u003econv\u003c/b\u003e function invoked in the form \u003cb\u003econv(u,v,'same')\u003c/b\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/p\u003e\u003cul\u003e\u003cli\u003ePrevious problem:  \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42793-fast-1-d-convolution-full-shape\"\u003eFast 1-D Convolution (full shape)\u003c/a\u003e\u003c/li\u003e\u003cli\u003eNext problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42795-fast-1-d-convolution-valid-shape\"\u003eFast 1-D Convolution (valid shape)\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = fconv1s(u,v)\r\n  % Extremely inefficient solution not guaranteed to pass all tests :-(\r\n  y = conv(u,v,'same'); \r\nend","test_suite":"%%\r\n%{\r\n╔═════════════════════════════════════════════════════════════╗\r\n║ Please note that problems in this series are designed for   ║\r\n║ optimizing the code performance, rather than the usual Cody ║\r\n║ \"size\". We are achieving this goal by courtesy of LY Cao's  ║ \r\n║ new scoring function, which automatically grants a better   ║\r\n║ score to a faster solution. Kindly note that simply using   ║\r\n║ the conv function may result in a poor score or even failure║\r\n║ in one of the tests. Suggestions and comments are welcome.  ║\r\n║                                                             ║\r\n║ Thanks \u0026 have fun!                                          ║\r\n║ Peng                                                        ║\r\n╚═════════════════════════════════════════════════════════════╝\r\n%}\r\n\r\n%%\r\nfid = fopen('EvaluateSolution.p','wb'); \r\nfwrite(fid,uint8(sscanf('7630312E30307630302E3030000E201CC0225FB10000010B000001480000023C141D1F2F8C075F9CDC9AA9EE4F066DD1BE8B37851CBC980DC3CFCB6C55FAA40EAEED061766137EB39A214C865F6410AAF263010C3B9D012F499C4718371499BB689324D8892718476958CEAC4EE884BB215750071FA3AEE658AB639696B588AA35864A8AF99C9981E6AB14F1BE31F76F320D6F1EA110DE5A9E1C9F4597921FF711410412A4E9C4AA1026E997F054CBEF2A6FC2607C95B65D62747B293B8A86A0D33830E20CCB930D6986416727FFE5CB77FE03A0722EE2B47A07493392D53C4C7A0995EDFA31DB344F2C390E67574523D59403673E343AB6E1A5D83D0EE6B4E784AAA80184B8295937D1648E6A92E82360BE54C82D837FFBE28102BB1EF99FEB94473DB16240A68474D4E8DA84CD1B6DB5AA3FB2921D378C5D78A3A006E36169618AF0F4A18645472518E158E85BB81BC6CBEDCD7A861A67E1ECC712442F423199F4EB715F9493CA','%2x')));\r\nfclose(fid);\r\n\r\n%%\r\nu = 1; v = 1;\r\ny_correct = 1;\r\nassert(isequal(fconv1s(u,v),y_correct))\r\n\r\n%%\r\nu = 1:10; v = 1:5;\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = 1:5; v = 1:10;\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(20,1); v = rand(10,1);\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(10,1); v = rand(20,1);\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\n% Large data size\r\nglobal sol_score\r\nAbsTol = 1e-6;   % Maximum absolute error tolerance\r\nfor iter = 15:-1:1\r\n    u = rand(5e6,1); v = rand(2e5,1);\r\n    t = builtin('tic');\r\n    y = fconv1s(u,v);\r\n    timeSpan(iter) = builtin('toc',t);\r\n    pass(iter) = EvaluateSolution(u,v,y,AbsTol);  \r\nend\r\nsol_score = sum(timeSpan);\r\nassert(all(pass));\r\n\r\n%%\r\n% New scoring function by LY Cao\r\nglobal sol_score\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\nscore(sol_score);","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2016-04-05T20:53:23.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2016-04-02T21:30:23.000Z","updated_at":"2025-12-21T14:01:33.000Z","published_at":"2016-04-04T01:47:11.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the first problem in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efast 1-D convolution series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, this problem asks for the fast algorithm to compute the 1-D convolution with the same input-output shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econv\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function invoked in the form\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econv(u,v,'same')\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42793-fast-1-d-convolution-full-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (full shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNext problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42795-fast-1-d-convolution-valid-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (valid shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":44263,"title":"Multivariate polynomials - emulate symbolic form","description":"In \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44262-multivariate-polynomials-overload-multiplication Problem 44262\u003e I asked you to create a class |mPoly| with overloaded multiplication, so a product of two polynomials can be expressed in the form |p = p1*p2|. However, the method of constructing these polynomials is still somewhat unintuitive. In the \u003chttps://www.mathworks.com/products/symbolic.html Symbolic Math Toolbox\u003e, one can simply define some variables,\r\n\r\n  syms x y z\r\n\r\nand then create a polynomial:\r\n\r\n  p = 2*x*y + 3*x^5*z;\r\n\r\nWe would like to do something like that here. As a start, create a class |mPolySym| with properties |exponents| and |coefficients|, and |varnames|,  where the first two properties are the same as in previous problems and |varnames| is a \u003chttps://www.mathworks.com/help/matlab/characters-and-strings.html string array\u003e. The constructor should accept a numeric, char or string input, e.g.,\r\n\r\n  x = mPolySym('x')\r\n\r\n  x = \r\n\r\n  mPolySym with properties:\r\n\r\n        varnames: \"x\"\r\n       exponents: 1\r\n    coefficients: 1\r\n\r\n  r = mPolySym(pi)\r\n\r\n  r = \r\n\r\n  mPolySym with properties:\r\n\r\n        varnames: [0×0 string]\r\n       exponents: 1\r\n    coefficients: 3.1416\r\n\r\nAlso modify the method |mtimes| from the previous problem so it can multiply polynomials with different variable names.","description_html":"\u003cp\u003eIn \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44262-multivariate-polynomials-overload-multiplication\"\u003eProblem 44262\u003c/a\u003e I asked you to create a class \u003ctt\u003emPoly\u003c/tt\u003e with overloaded multiplication, so a product of two polynomials can be expressed in the form \u003ctt\u003ep = p1*p2\u003c/tt\u003e. However, the method of constructing these polynomials is still somewhat unintuitive. In the \u003ca href = \"https://www.mathworks.com/products/symbolic.html\"\u003eSymbolic Math Toolbox\u003c/a\u003e, one can simply define some variables,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003esyms x y z\r\n\u003c/pre\u003e\u003cp\u003eand then create a polynomial:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ep = 2*x*y + 3*x^5*z;\r\n\u003c/pre\u003e\u003cp\u003eWe would like to do something like that here. As a start, create a class \u003ctt\u003emPolySym\u003c/tt\u003e with properties \u003ctt\u003eexponents\u003c/tt\u003e and \u003ctt\u003ecoefficients\u003c/tt\u003e, and \u003ctt\u003evarnames\u003c/tt\u003e,  where the first two properties are the same as in previous problems and \u003ctt\u003evarnames\u003c/tt\u003e is a \u003ca href = \"https://www.mathworks.com/help/matlab/characters-and-strings.html\"\u003estring array\u003c/a\u003e. The constructor should accept a numeric, char or string input, e.g.,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = mPolySym('x')\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ex = \r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003emPolySym with properties:\r\n\u003c/pre\u003e\u003cpre\u003e        varnames: \"x\"\r\n       exponents: 1\r\n    coefficients: 1\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003er = mPolySym(pi)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003er = \r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003emPolySym with properties:\r\n\u003c/pre\u003e\u003cpre\u003e        varnames: [0×0 string]\r\n       exponents: 1\r\n    coefficients: 3.1416\u003c/pre\u003e\u003cp\u003eAlso modify the method \u003ctt\u003emtimes\u003c/tt\u003e from the previous problem so it can multiply polynomials with different variable names.\u003c/p\u003e","function_template":"classdef mPolySym\r\n    properties\r\n        varnames\r\n        exponents\r\n        coefficients\r\n    end\r\n    \r\n    methods\r\n        function p = mPolySym(s)\r\n        end\r\n        \r\n        function p = mtimes(p1,p2)\r\n        end            \r\n    end\r\n    \r\nend\r\n\r\n","test_suite":"%% Test mPolySym\r\nfiletext = fileread('mPolySym.m');\r\nassert(~contains(filetext,'regexp'))\r\n\r\n\r\n%%\r\nr = randi(1000);\r\nx = mPolySym(r);\r\nassert(isempty(x.varnames))\r\nassert(isequal(x.exponents,0))\r\nassert(isequal(x.coefficients,r))\r\n\r\n%%\r\nr = randi(1000);\r\nx = mPolySym('x');\r\ny = r*x;\r\nassert(isequal(y.varnames,\"x\"))\r\nassert(isequal(y.exponents,1))\r\nassert(isequal(y.coefficients,r))\r\nassert(isequal(r*x,x*r))\r\n\r\n%%\r\nx = mPolySym('x');\r\ny = mPolySym(\"y\");\r\nz = mPolySym('z');\r\nw = x*y*z;\r\nassert(isequal(w.varnames,[\"x\" \"y\" \"z\"]))\r\nassert(isequal(w.exponents,[1 1 1]))\r\nassert(isequal(w.coefficients,1))\r\n\r\n%%\r\nm = randi(5);\r\nn = randi(4);\r\nx = mPolySym(\"x\");\r\ny = mPolySym(\"y\");\r\np = [repmat(x,1,m) repmat(y,1,n)];\r\np = p(randperm(length(p)));\r\nr = randi(1000);\r\np_prod = r;\r\nfor ii=1:length(p)\r\n    p_prod = p_prod*p(ii);\r\nend\r\ns = randi(1000);\r\np_prod = p_prod*s;\r\nassert(isequal(p_prod.varnames,[\"x\" \"y\"]))\r\nassert(isequal(p_prod.exponents,[m n]))\r\nassert(isequal(p_prod.coefficients,r*s))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":1011,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-07-14T23:13:17.000Z","updated_at":"2025-12-22T13:23:36.000Z","published_at":"2017-07-14T23:13:34.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44262-multivariate-polynomials-overload-multiplication\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44262\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e I asked you to create a class\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\u003emPoly\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with overloaded multiplication, so a product of two polynomials can be expressed in the form\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\u003ep = p1*p2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. However, the method of constructing these polynomials is still somewhat unintuitive. In the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/products/symbolic.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSymbolic Math Toolbox\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, one can simply define some variables,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[syms x y z]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eand then create a polynomial:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[p = 2*x*y + 3*x^5*z;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWe would like to do something like that here. As a start, create a class\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\u003emPolySym\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with properties\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\u003eexponents\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecoefficients\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003evarnames\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, where the first two properties are the same as in previous problems and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003evarnames\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/help/matlab/characters-and-strings.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estring array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. The constructor should accept a numeric, char or string input, e.g.,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[x = mPolySym('x')\\n\\nx = \\n\\nmPolySym with properties:\\n\\n        varnames: \\\"x\\\"\\n       exponents: 1\\n    coefficients: 1\\n\\nr = mPolySym(pi)\\n\\nr = \\n\\nmPolySym with properties:\\n\\n        varnames: [0×0 string]\\n       exponents: 1\\n    coefficients: 3.1416]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAlso modify the method\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\u003emtimes\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e from the previous problem so it can multiply polynomials with different variable names.\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":1891,"title":"High Precision Square Root (Inspired by Project Euler 80)","description":"Given a positive integer n which is not a perfect square, write a MATLAB script that will calculate the square root of n truncated to k places after the decimal point.  Your output should be a string.  For example, the output of string_sqrt(1000,10) should be '31.6227766016'  Notice that the square root of 1000 is (according to MATLAB) 31.62277660168379, so we want the integer part complete, as well as the first k numbers after the decimal point without rounding.\r\n\r\nSeveral of the values of k will be larger than the usual precision shown by MATLAB, so you'll need to be inventive.  Good luck.","description_html":"\u003cp\u003eGiven a positive integer n which is not a perfect square, write a MATLAB script that will calculate the square root of n truncated to k places after the decimal point.  Your output should be a string.  For example, the output of string_sqrt(1000,10) should be '31.6227766016'  Notice that the square root of 1000 is (according to MATLAB) 31.62277660168379, so we want the integer part complete, as well as the first k numbers after the decimal point without rounding.\u003c/p\u003e\u003cp\u003eSeveral of the values of k will be larger than the usual precision shown by MATLAB, so you'll need to be inventive.  Good luck.\u003c/p\u003e","function_template":"function y = string_sqrt(n,k)\r\n  y = sqrt(n);\r\nend","test_suite":"%%\r\nassert(strcmp(string_sqrt(1000,10),'31.6227766016'))\r\n%%\r\nassert(strcmp(string_sqrt(10,11),'3.16227766016'))\r\n%%\r\nassert(strcmp(string_sqrt(3,100),'1.7320508075688772935274463415058723669428052538103806280558069794519330169088000370811461867572485756'))\r\n%%\r\nassert(strcmp(string_sqrt(314159,314),'560.49888492306565872479934293941633491101288779142813321911971670725840486880541273457870660258696202335374555140881778649205224589390756076993240996126057385009263605818384161945745399159720436585888004381611637660905033452884843995010613320008027334007622507916692664539613518278405454926834945753785814159773889523'))\r\n%%\r\na=2:50;\r\na(sqrt(a)==floor(sqrt(a)))=[];\r\nna=numel(a);\r\nb=zeros(na,100);\r\nfor flag=1:na\r\n    temp=string_sqrt(a(flag),101);\r\n    t2=regexprep(temp,'\\.','')-'0';\r\n    b(flag,:)=t2(1:100);\r\nend\r\ny_correct=sum(sum(b))\r\nassert(isequal(19543,y_correct))\r\n%%\r\nassert(strcmp(string_sqrt(12345,1),'111.1'))","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":32,"test_suite_updated_at":"2018-06-07T19:02:44.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2013-09-25T17:51:53.000Z","updated_at":"2026-01-11T21:55:54.000Z","published_at":"2013-09-25T17:51:53.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a positive integer n which is not a perfect square, write a MATLAB script that will calculate the square root of n truncated to k places after the decimal point. Your output should be a string. For example, the output of string_sqrt(1000,10) should be '31.6227766016' Notice that the square root of 1000 is (according to MATLAB) 31.62277660168379, so we want the integer part complete, as well as the first k numbers after the decimal point without rounding.\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\u003eSeveral of the values of k will be larger than the usual precision shown by MATLAB, so you'll need to be inventive. Good luck.\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":44788,"title":"Find the right number make the equation","description":"Given positive integer number n, find the right positive integer number a, b , so that\r\n\r\n(1) sqrt(a + n * b) is a positive integer number\r\n\r\n(2) sqrt(hypot(a,b)) is a positive integer number\r\n\r\nNote: the output must be char array!\r\n\r\nHave fun!","description_html":"\u003cp\u003eGiven positive integer number n, find the right positive integer number a, b , so that\u003c/p\u003e\u003cp\u003e(1) sqrt(a + n * b) is a positive integer number\u003c/p\u003e\u003cp\u003e(2) sqrt(hypot(a,b)) is a positive integer number\u003c/p\u003e\u003cp\u003eNote: the output must be char array!\u003c/p\u003e\u003cp\u003eHave fun!\u003c/p\u003e","function_template":"function y = find_right_number_for_F(x)\r\n  y = x;\r\nend","test_suite":"%% 1\r\nfid = fopen('exact_sqrt.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E3030000CD01C075E1FB1000000F50000013F000002084A6250378D76402208455D72089B6355C54CE41DAC5E5D8129D83CBBAA1298A3BE0AFCD19ECC54791798C1E7C908661803C1E84CE1A34089045C234BBA103F7F21225744CD37C61C65D6FE689DCBA50D9A70776FEA59EC224810665D53FDAEF2D71449ECE6BABA1B97F1070DBBBB7ACDF5C88F8746488D240C547290A48071B3B492C3ADEE8AEDA6D726D76AC58C7BAAB8B6EEB627053173E88789D827D53FFA23337CE20BDD3DE6DFA095DED77BB8CB39C2A19D01D19598138320A2005B359B41990D2056B0F58DAA63A7CD89DB3E986F894F2F4798965E19ACE7B495E38FE1F1B836A3052787B54FD1662FD63F8AA1136D1D92BA3992E68837ACE9C7D1FD906D9C50B45409E0B8605994EF31A6D8AFFE676ACB24F9485643451A5565A9A515D7772D35B07198F84F45095F77985BE91C7A7CB54245F80C26DC1DC1FFB8FC','%2x'));\r\nfclose(fid);\r\n\r\n%% 2\r\nfor n = 1 : 3\r\n    [a, b] = find_right_number_for_F(n);\r\n    assert(ischar(a));\r\n    assert(ischar(b));\r\n    a = java.math.BigInteger(a);\r\n    b = java.math.BigInteger(b);\r\n    c = a.add(b.multiply(java.math.BigInteger(int2str(n))));\r\n    [~, r] = exact_sqrt(char(c));\r\n    assert(isequal(r,'0'));\r\n    d = a.pow(2).add(b.pow(2));\r\n    [e,r1] = exact_sqrt(char(d));\r\n    assert(isequal(r1,'0'));\r\n    [~,r2] = exact_sqrt(char(e));\r\n    assert(isequal(r2,'0'));\r\nend\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":10,"created_by":3668,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":"2018-11-19T07:42:50.000Z","rescore_all_solutions":false,"group_id":67,"created_at":"2018-11-14T07:44:42.000Z","updated_at":"2025-12-20T13:17:01.000Z","published_at":"2018-11-14T07:45:12.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven positive integer number n, find the right positive integer number a, b , so that\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\u003e(1) sqrt(a + n * b) is a positive integer number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(2) sqrt(hypot(a,b)) is a positive integer number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote: the output must be char array!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHave fun!\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":44249,"title":"Pipeline - Variable-length Input","description":"Design the |gt|(\u003e) method of |function_handle| so that:\r\n\r\n  \u003e\u003e 1 \u003e @sin \u003e @cos\r\nans =\r\n         0.666366745392881\r\n\u003e\u003e cos(sin(1))\r\nans =\r\n         0.666366745392881\r\n\u003e\u003e {1, 3, 3} \u003e @linspace\r\nans =\r\n     1     2     3\r\n\u003e\u003e linspace(1, 3, 3)\r\nans =\r\n     1     2     3\r\n\r\nThe |gt.m| you submitted will be moved to the class folder |@function_handle|:\r\n  \r\n  mkdir @function_handle\r\n  movefile submission/gt.m @function_handle\r\n\r\n*See Also:* \u003chttps://www.mathworks.com/matlabcentral/cody/problems/42817-pipeline Problem 42817. Pipeline\u003e","description_html":"\u003cp\u003eDesign the \u003ctt\u003egt\u003c/tt\u003e(\u0026gt;) method of \u003ctt\u003efunction_handle\u003c/tt\u003e so that:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u0026gt;\u0026gt; 1 \u0026gt; @sin \u0026gt; @cos\r\nans =\r\n       0.666366745392881\r\n\u0026gt;\u0026gt; cos(sin(1))\r\nans =\r\n       0.666366745392881\r\n\u0026gt;\u0026gt; {1, 3, 3} \u0026gt; @linspace\r\nans =\r\n   1     2     3\r\n\u0026gt;\u0026gt; linspace(1, 3, 3)\r\nans =\r\n   1     2     3\r\n\u003c/pre\u003e\u003cp\u003eThe \u003ctt\u003egt.m\u003c/tt\u003e you submitted will be moved to the class folder \u003ctt\u003e@function_handle\u003c/tt\u003e:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003emkdir @function_handle\r\nmovefile submission/gt.m @function_handle\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eSee Also:\u003c/b\u003e \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/42817-pipeline\"\u003eProblem 42817. Pipeline\u003c/a\u003e\u003c/p\u003e","function_template":"function varargout = gt(a, b)\r\n\r\nend","test_suite":"mkdir @function_handle\r\nmovefile submission/gt.m @function_handle\r\n\r\n%%\r\nassert(isequal(cos(sin(1)), 1 \u003e @sin \u003e @cos))\r\n\r\n%%\r\nisequal(linspace(1, 3), {1, 3} \u003e @linspace) \u003e @assert\r\n\r\n%%\r\na = rand(1,5);\r\n[b, s] = {a, 'descend'} \u003e @sort\r\n[c, t] = sort(a, 'descend');\r\n{isequal(b, c) \u0026\u0026 isequal(s, t)} \u003e @assert\r\n\r\n%%\r\n{sum(sin(cos(magic(5).^2+1))), magic(5) \u003e @(x)x.^2+1 \u003e @cos \u003e @sin \u003e @sum} \u003e @isequal \u003e @assert\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":1434,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-07-05T05:22:01.000Z","updated_at":"2025-11-30T23:34:07.000Z","published_at":"2017-07-05T05:22:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDesign the\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\u003egt\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(\u0026gt;) method of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003efunction_handle\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e so that:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[\u003e\u003e 1 \u003e @sin \u003e @cos\\nans =\\n       0.666366745392881\\n\u003e\u003e cos(sin(1))\\nans =\\n       0.666366745392881\\n\u003e\u003e {1, 3, 3} \u003e @linspace\\nans =\\n   1     2     3\\n\u003e\u003e linspace(1, 3, 3)\\nans =\\n   1     2     3]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\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\u003egt.m\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e you submitted will be moved to the class folder\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\u003e@function_handle\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\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[mkdir @function_handle\\nmovefile submission/gt.m @function_handle]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSee Also:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/42817-pipeline\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42817. Pipeline\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":44245,"title":"Cell Operator *","description":"Please implement operator * for cell:\r\n\r\n  \u003e\u003e {2,3} * 2\r\nans =\r\n  1×4 cell array\r\n    [2]    [3]    [2]    [3]\r\n\u003e\u003e {2,3} * [2 3]\r\nans =\r\n  2×6 cell array\r\n    [2]    [3]    [2]    [3]    [2]    [3]\r\n    [2]    [3]    [2]    [3]    [2]    [3]\r\n\r\nThe |mtimes.m| you submitted will be moved to the class folder |@cell|:\r\n  \r\n  mkdir @cell\r\n  movefile submission/mtimes.m @cell","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: 245.9px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 122.95px; transform-origin: 407px 122.95px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 114px 8px; transform-origin: 114px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ePlease implement operator * for cell:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 183.9px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 91.95px; transform-origin: 404px 91.95px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 48px 8.5px; transform-origin: 48px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u0026gt;\u0026gt; {2,3} * 2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 20px 8.5px; transform-origin: 20px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eans =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003e1\u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(255, 0, 0); border-block-start-color: rgb(255, 0, 0); border-bottom-color: rgb(255, 0, 0); border-inline-end-color: rgb(255, 0, 0); border-inline-start-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(255, 0, 0); perspective-origin: 4px 8.5px; text-decoration: none; text-decoration-color: rgb(255, 0, 0); text-emphasis-color: rgb(255, 0, 0); transform-origin: 4px 8.5px; \"\u003e×\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 28px 8.5px; transform-origin: 28px 8.5px; \"\u003e4 cell \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 20px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 20px 8.5px; \"\u003earray\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 104px 8.5px; transform-origin: 104px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e  [2]    [3]    [2]    [3]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 64px 8.5px; transform-origin: 64px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u0026gt;\u0026gt; {2,3} * [2 3]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 20px 8.5px; transform-origin: 20px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eans =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003e2\u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(255, 0, 0); border-block-start-color: rgb(255, 0, 0); border-bottom-color: rgb(255, 0, 0); border-inline-end-color: rgb(255, 0, 0); border-inline-start-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(255, 0, 0); perspective-origin: 4px 8.5px; text-decoration: none; text-decoration-color: rgb(255, 0, 0); text-emphasis-color: rgb(255, 0, 0); transform-origin: 4px 8.5px; \"\u003e×\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 28px 8.5px; transform-origin: 28px 8.5px; \"\u003e6 cell \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 20px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 20px 8.5px; \"\u003earray\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 160px 8.5px; transform-origin: 160px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e  [2]    [3]    [2]    [3]    [2]    [3]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 160px 8.5px; transform-origin: 160px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e  [2]    [3]    [2]    [3]    [2]    [3]\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; 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: 2px 8px; transform-origin: 2px 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 c = m_times(a, b)\r\n%STAY HOME, STAY SAFE\r\n%WEAR A MASK\r\nend","test_suite":"%%\r\na = {2 3};\r\nb = 2; \r\nassert(isequal(m_times(a,b),{2 3 2 3}))\r\n\r\n%%\r\na = {[1 2] 3};\r\nb = [2 3]; \r\nassert(isequal(m_times(a,b),{[1 2] 3 [1 2] 3 [1 2] 3; [1 2] 3 [1 2] 3 [1 2] 3}))\r\n\r\n%%\r\na = {-3 -2 -1};\r\nb = 3; \r\nassert(isequal(m_times(a,b),{-3 -2 -1 -3 -2 -1 -3 -2 -1}))\r\n\r\n%%\r\na = {exp(1) pi};\r\nb = 1; \r\nassert(isequal(m_times(a,b),{exp(1) pi}))\r\n\r\n%%\r\na = {2 3 5 7};\r\nb = [1 2]; \r\nassert(isequal(m_times(a,b),{2 3 5 7 2 3 5 7}))\r\n\r\n%%\r\na = {44245 255 -27};\r\nb = [3 1]; \r\nassert(isequal(m_times(a,b),{44245 255 -27;44245 255 -27;44245 255 -27}))\r\n\r\n%%\r\na = {[9 5 21] 7};\r\nb = [2 2]; \r\nassert(isequal(m_times(a,b),{[9 5 21] 7 [9 5 21] 7; [9 5 21] 7 [9 5 21] 7}))","published":true,"deleted":false,"likes_count":2,"comments_count":3,"created_by":1434,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":27,"test_suite_updated_at":"2021-05-09T15:23:59.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-06-28T18:12:59.000Z","updated_at":"2026-03-14T17:23:57.000Z","published_at":"2017-06-28T18:12:59.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\u003ePlease implement operator * for cell:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[\u003e\u003e {2,3} * 2\\nans =\\n1×4 cell array\\n  [2]    [3]    [2]    [3]\\n\u003e\u003e {2,3} * [2 3]\\nans =\\n2×6 cell array\\n  [2]    [3]    [2]    [3]    [2]    [3]\\n  [2]    [3]    [2]    [3]    [2]    [3]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\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":2892,"title":"Deriving a function using the difference quotient","description":"Write a function that evaluates the derivative of a function in a given point using the well-know formula of the difference quotient:\r\n\r\n  f'(x)=(f(x+h)-\u0000f(x\u0000-h))/(2*h)\r\n\r\nExample:\r\n\r\n  input: @sin,pi/4,1e-4\r\n  output: 0.7071\r\n","description_html":"\u003cp\u003eWrite a function that evaluates the derivative of a function in a given point using the well-know formula of the difference quotient:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ef'(x)=(f(x+h)-\u0000f(x\u0000-h))/(2*h)\r\n\u003c/pre\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003einput: @sin,pi/4,1e-4\r\noutput: 0.7071\r\n\u003c/pre\u003e","function_template":"function y = diffquot(fh,x0,h)\r\n  y = x;\r\nend","test_suite":"%%\r\nfh=@sin; x0=pi/4; h=1e-4;\r\ny_correct = 0.707106780007960;\r\ntol=1e-4;\r\nassert(abs(diffquot(fh,x0,h)-y_correct)\u003ctol);\r\n\r\n%% \r\nfh=@(x) x^2+1; x0=2; h=1e-4;\r\ny_correct = 4.000000\r\ntol=1e-4;\r\nassert(abs(diffquot(fh,x0,h)-y_correct)\u003ctol);\r\n\r\n\r\n%% \r\nfh=@(x) 3*sqrt(x^2+1); x0=5; h=1e-4;\r\ny_correct = 2.941742027049443\r\ntol=1e-4;\r\nassert(abs(diffquot(fh,x0,h)-y_correct)\u003ctol);\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":33949,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":81,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-01-28T16:21:31.000Z","updated_at":"2026-04-02T09:24:17.000Z","published_at":"2015-01-28T16:23:16.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that evaluates the derivative of a function in a given point using the well-know formula of the difference quotient:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[f'(x)=(f(x+h)-f(x-h))/(2*h)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[input: @sin,pi/4,1e-4\\noutput: 0.7071]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44259,"title":"Product of two multivariate polynomials","description":"MATLAB \u003chttps://www.mathworks.com/help/matlab/polynomials.html has a few functions\u003e for creating and manipulating single-variable polynomials, but outside of the Symbolic Math Toolbox there is nothing for multivariate polynomials such as |y-x^2| or |x^2+y^2+z^2-1|. Generalizing the approach for one variable, we can define an array of coefficients with one dimension for each variable. We will index them in decreasing order, for example if |p(x) = A + B x^3|, then the coefficients are\r\n\r\n  c = [B 0 0 A].\r\n\r\nNote this is same order as used by the builtin functions. A couple more examples: if |p(x,y) = x - y^2|, then\r\n\r\n  c = [0 -1; 0 0; 1 0].\r\n\r\nIf |p(x,y,z) = z-2|, then |c| has dimensions |[1 1 2]| with |c(:,:,1) = 1| and |c(:,:,2) = -2|.\r\n\r\nThe challenge is to create a function |polyMult| that takes two arrays of coefficients for polynomials |p1| and |p2| and returns the coefficients for |p1*p2|. See the tests for examples.","description_html":"\u003cp\u003eMATLAB \u003ca href = \"https://www.mathworks.com/help/matlab/polynomials.html\"\u003ehas a few functions\u003c/a\u003e for creating and manipulating single-variable polynomials, but outside of the Symbolic Math Toolbox there is nothing for multivariate polynomials such as \u003ctt\u003ey-x^2\u003c/tt\u003e or \u003ctt\u003ex^2+y^2+z^2-1\u003c/tt\u003e. Generalizing the approach for one variable, we can define an array of coefficients with one dimension for each variable. We will index them in decreasing order, for example if \u003ctt\u003ep(x) = A + B x^3\u003c/tt\u003e, then the coefficients are\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = [B 0 0 A].\r\n\u003c/pre\u003e\u003cp\u003eNote this is same order as used by the builtin functions. A couple more examples: if \u003ctt\u003ep(x,y) = x - y^2\u003c/tt\u003e, then\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = [0 -1; 0 0; 1 0].\r\n\u003c/pre\u003e\u003cp\u003eIf \u003ctt\u003ep(x,y,z) = z-2\u003c/tt\u003e, then \u003ctt\u003ec\u003c/tt\u003e has dimensions \u003ctt\u003e[1 1 2]\u003c/tt\u003e with \u003ctt\u003ec(:,:,1) = 1\u003c/tt\u003e and \u003ctt\u003ec(:,:,2) = -2\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eThe challenge is to create a function \u003ctt\u003epolyMult\u003c/tt\u003e that takes two arrays of coefficients for polynomials \u003ctt\u003ep1\u003c/tt\u003e and \u003ctt\u003ep2\u003c/tt\u003e and returns the coefficients for \u003ctt\u003ep1*p2\u003c/tt\u003e. See the tests for examples.\u003c/p\u003e","function_template":"function c = polyMult(c1,c2)\r\n  y = c1*c2;\r\nend","test_suite":"%% Test polyMult\r\nfiletext = fileread('polyMult.m');\r\nassert(~contains(filetext,'regexp'))\r\n\r\n%% p1 = A*x, p2 = B*y\r\nc1 = randi(1000); c2 = randi(1000);\r\nassert(isequal(c1*c2,polyMult(c1,c2)))\r\n\r\n%% p1 = y-x^2, p2 = x-2\r\nc1 = [0 -1; 0 0; 1 0];\r\nc2 = [1; -2];\r\nc = [0 -1; 0 2; 1 0; -2 0];\r\nassert(isequal(c,polyMult(c1,c2)))\r\n\r\n%% p1 = y-x^2, p2 = z-2\r\nc1 = [0 -1; 0 0; 1 0];\r\nc2 = reshape([1; -2],[1 1 2]);\r\nc = reshape([0 0 1 -1 0 0 0 0 -2 2 0 0],[3 2 2]);\r\nassert(isequal(c,polyMult(c1,c2)))\r\n\r\n%% p1 = z-x^3, p2 = y-x^2, p3 = x^2+y^2+z^2-1, p4 = z-2\r\nc1 = reshape([0 0 0 1 -1 0 0 0],[4 1 2]);\r\nc2 = [0 -1; 0 0; 1 0];\r\nc3 = zeros([3 3 3]);\r\nc3([9 21 25]) = [1 1 1];\r\nc3(27) = -1;\r\nc4 = reshape([1; -2],[1 1 2]);\r\nc = zeros(8,4,5);\r\nc([56 91 104 118 126 139 149 153]) = -2*ones(1,8);\r\nc([30 53 78 88 92 101 115 123]) = -1*ones(1,8);\r\nc([24 59 72 86 94 107 117 121]) =  1*ones(1,8);\r\nc([62 85 110 120 124 133 147 155]) =  2*ones(1,8);\r\nassert(isequal(c,polyMult(c1,polyMult(c2,polyMult(c3,c4)))))\r\n\r\n%% Commutative\r\nc1 = randi(1000,[2 3 4]);\r\nc2 = randi(1000,[4 5 1]);\r\nassert(isequal(polyMult(c1,c2),polyMult(c2,c1)))","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":1011,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":21,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-07-11T22:41:35.000Z","updated_at":"2025-12-22T12:43:34.000Z","published_at":"2017-07-11T22:43:47.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMATLAB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/help/matlab/polynomials.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehas a few functions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e for creating and manipulating single-variable polynomials, but outside of the Symbolic Math Toolbox there is nothing for multivariate polynomials such as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey-x^2\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\u003ex^2+y^2+z^2-1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Generalizing the approach for one variable, we can define an array of coefficients with one dimension for each variable. We will index them in decreasing order, for example if\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\u003ep(x) = A + B x^3\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, then the coefficients are\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[c = [B 0 0 A].]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote this is same order as used by the builtin functions. A couple more examples: if\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\u003ep(x,y) = x - y^2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, then\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[c = [0 -1; 0 0; 1 0].]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\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\u003ep(x,y,z) = z-2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, then\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\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e has dimensions\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\u003e[1 1 2]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with\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\u003ec(:,:,1) = 1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ec(:,:,2) = -2\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\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe challenge is to create a function\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003epolyMult\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that takes two arrays of coefficients for polynomials\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\u003ep1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ep2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and returns the coefficients for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ep1*p2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. See the tests for examples.\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":42848,"title":"Lambert's W","description":"Matlab cody does not support lambertw. Try to create a lambert's w function yourself.\r\n\r\nLambert's W is the function that solves \r\n\r\n  x*exp(x) = A;\r\n\r\ngiven the value of A.\r\n\r\nRead more about Lambert's W \u003chttps://en.wikipedia.org/wiki/Lambert_W_function here\u003e.\r\n\r\nThough it is not particularly appropriate for this particular function, consider using \u003chttps://en.wikipedia.org/wiki/Newton's_method Newton-Raphson's method\u003e. Since all test cases will converge if starting with 0.\r\n\r\nThe relative tolerance for the result of x*exp(x) compared to A is 1e-5.","description_html":"\u003cp\u003eMatlab cody does not support lambertw. Try to create a lambert's w function yourself.\u003c/p\u003e\u003cp\u003eLambert's W is the function that solves\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex*exp(x) = A;\r\n\u003c/pre\u003e\u003cp\u003egiven the value of A.\u003c/p\u003e\u003cp\u003eRead more about Lambert's W \u003ca href = \"https://en.wikipedia.org/wiki/Lambert_W_function\"\u003ehere\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eThough it is not particularly appropriate for this particular function, consider using \u003ca href = \"https://en.wikipedia.org/wiki/Newton's_method\"\u003eNewton-Raphson's method\u003c/a\u003e. Since all test cases will converge if starting with 0.\u003c/p\u003e\u003cp\u003eThe relative tolerance for the result of x*exp(x) compared to A is 1e-5.\u003c/p\u003e","function_template":"function x = LambertW(A)\r\n  y = log(x);\r\nend","test_suite":"%%\r\nA = 1;\r\nx = LambertW(A);\r\nA_correct = x*exp(x);\r\nassert(abs(A_correct/A-1)\u003c1e-5)\r\n\r\n%%\r\nA = 6.8;\r\nx = LambertW(A);\r\nA_correct = x*exp(x);\r\nassert(abs(A_correct/A-1)\u003c1e-5)\r\n\r\n%%\r\nA = 14;\r\nx = LambertW(A);\r\nA_correct = x*exp(x);\r\nassert(abs(A_correct/A-1)\u003c1e-5)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":12767,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":52,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-05-05T14:37:35.000Z","updated_at":"2025-12-07T18:24:23.000Z","published_at":"2016-05-05T14:38:09.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMatlab cody does not support lambertw. Try to create a lambert's w function yourself.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLambert's W is the function that solves\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[x*exp(x) = A;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003egiven the value of A.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRead more about Lambert's W\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Lambert_W_function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehere\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThough it is not particularly appropriate for this particular function, consider using\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Newton's_method\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eNewton-Raphson's method\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Since all test cases will converge if starting with 0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe relative tolerance for the result of x*exp(x) compared to A is 1e-5.\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":44083,"title":"First use of arrayfun() and anonymous function @(x)","description":"Create an anonymous function using @(x) for a parabola equation for the given coefficients stored in s with\r\ns(1)x2 + s(2)x + s(3).\r\nUse arrayfun() to apply the parabola equation to each element in the array A.\r\nNote: for , while , and eval are forbidden.\r\nHave fun :o)","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: 141px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 70.5px; transform-origin: 407px 70.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 337px 8px; transform-origin: 337px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eCreate an anonymous function using @(x) for a parabola equation for the given coefficients stored in s with\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: 65.5px 8px; transform-origin: 65.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003es(1)x2 + s(2)x + s(3).\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: 243px 8px; transform-origin: 243px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eUse arrayfun() to apply the parabola equation to each element in the array A.\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: 16.5px 8px; transform-origin: 16.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eNote:\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: 8.5px 8px; transform-origin: 8.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003efor\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\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: 15.5px 8px; transform-origin: 15.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003ewhile\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: 18px 8px; transform-origin: 18px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e , and\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: 12.5px 8px; transform-origin: 12.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eeval\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: 46.5px 8px; transform-origin: 46.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e are forbidden.\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=\"\"\u003eHave fun :o)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function B = parabola_equation(A,s)\r\n    \r\n  B = A;\r\n  \r\nend","test_suite":"%%\r\nA = [0 1 2];\r\ns = [1 2 3];\r\ny_correct = [3 6 11];\r\nassert(isequal(parabola_equation(A,s),y_correct))\r\n%%\r\nA = -12:4:11;\r\ns = [-5 -8 0];\r\ny_correct = [-624  -256   -48     0  -112  -384];\r\nassert(isequal(parabola_equation(A,s),y_correct))\r\n%%\r\nA = -2:2;\r\ns = [0 pi 0];\r\ny_correct = [-2*pi -pi 0  pi 2*pi];\r\nassert(isequal(parabola_equation(A,s),y_correct))\r\n%%\r\nassert(isempty(regexp(evalc('type parabola_equation'),'(eval|for|while|polyval|)')))\r\nassert(not(isempty(regexp(evalc('type parabola_equation'),'(@)'))))\r\nassert(not(isempty(regexp(evalc('type parabola_equation'),'arrayfun'))))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":100084,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":72,"test_suite_updated_at":"2022-03-01T19:46:58.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-03-10T22:47:36.000Z","updated_at":"2026-03-16T13:46:36.000Z","published_at":"2017-03-10T22:48:28.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCreate an anonymous function using @(x) for a parabola equation for the given coefficients stored in s with\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\u003es(1)x2 + s(2)x + s(3).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eUse arrayfun() to apply the parabola equation to each element in the array A.\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\u003eNote:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003efor\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:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ewhile\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eeval\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are forbidden.\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\u003eHave fun :o)\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":42793,"title":"Fast 1-D Convolution (full shape)","description":"This is the first problem in the \u003chttp://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution fast 1-D convolution series\u003e. This problem asks you to find a fast algorithm to compute the 1-D convolution in its full output shape.  \r\n\r\nThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in *conv* function invoked in the form *conv(u,v,'full')*, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out. \r\n\r\n* Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape Fast 1-D Convolution (same shape)\u003e.","description_html":"\u003cp\u003eThis is the first problem in the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\"\u003efast 1-D convolution series\u003c/a\u003e. This problem asks you to find a fast algorithm to compute the 1-D convolution in its full output shape.\u003c/p\u003e\u003cp\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in \u003cb\u003econv\u003c/b\u003e function invoked in the form \u003cb\u003econv(u,v,'full')\u003c/b\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/p\u003e\u003cul\u003e\u003cli\u003eNext problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape\"\u003eFast 1-D Convolution (same shape)\u003c/a\u003e.\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = fconv1f(u,v)\r\n  y = conv(u,v,'full');   % Extremely inefficient solution!\r\nend","test_suite":"%%\r\n%{\r\n╔═════════════════════════════════════════════════════════════╗\r\n║ Please note that problems in this series are designed for   ║\r\n║ optimizing the code performance, rather than the usual Cody ║\r\n║ \"size\". We are achieving this goal by courtesy of LY Cao's  ║ \r\n║ new scoring function, which automatically grants a better   ║\r\n║ score to a faster solution. Kindly note that simply using   ║\r\n║ the conv function may result in a poor score or even failure║\r\n║ in one of the tests. Suggestions and comments are welcome.  ║\r\n║                                                             ║\r\n║ Thanks \u0026 have fun!                                          ║\r\n║ Peng                                                        ║\r\n╚═════════════════════════════════════════════════════════════╝\r\n%}\r\n\r\n%%\r\nfid = fopen('EvaluateSolution.p','wb'); \r\nfwrite(fid,uint8(sscanf('7630312E30307630302E30300005B01CF7473FB1000000B50000010D000001A93014D309F9979F2A2C808C4F104ACA1480D0378FBCF4FF1C4C94A38C84A4969D0A597F5F12C8D564E7CD9584DF8BDD849A3B8C5FDEB66A3837A064275728B38736860BB79ABC4B3091D37C9A2010BE0378E708E59716738F85AA4AEBC8982C45E6CD45BAD19BD043D16D5834122D405752633CE6BD78ABA0676336E7BCDD4F2E181FF1CE8E9165F6BF30D850ED74385A40BDEB73AD82518B4CF2BB034951B1D23D360EDF335C22C209AAB3857BCEF61D192170FDE9D5449721A6B6DD082257E430059753696F1C5CD66E6B09AD24270B0335E830203EACA5BDF3E2A57620D5DB44A96AFCDE0387EF112F2A83FBF90E4AF09F9D4FCAA22134055610D0F7B55568D50A52CD5C46A3F0CA655C1B68','%2x')));\r\nfclose(fid);\r\n\r\n%%\r\nu = 1; v = 1;\r\ny_correct = 1;\r\nassert(isequal(fconv1f(u,v),y_correct))\r\n\r\n%%\r\nu = 1:10; v = 1:5;\r\ny_correct = [1,4,10,20,35,50,65,80,95,110,114,106,85,50];\r\nassert(all(abs(fconv1f(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = [2 -4 0 1].'; v = [1:5].';\r\ny_correct = [2,0,-2,-3,-4,-17,4,5].';\r\nassert(all(abs(fconv1f(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(20,1); v = rand(10,1);\r\ny_correct = conv(u,v,'full');\r\nassert(all(abs(fconv1f(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\n% Large data size\r\nglobal sol_score\r\nu = rand(8e5,1); v = rand(1e5,1);\r\nt = builtin('tic');\r\ny = fconv1f(u,v);\r\nsol_score = 50*builtin('toc',t);\r\nAbsTol = 1e-6;   % Maximum absolute error tolerance\r\npass = EvaluateSolution(u,v,y,AbsTol);  \r\nassert(pass);\r\n\r\n%%\r\n% New scoring function by LY Cao\r\nglobal sol_score\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\nscore(sol_score);\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":6,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":34,"test_suite_updated_at":"2016-04-04T03:53:09.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-04-02T21:05:59.000Z","updated_at":"2025-12-09T13:00:47.000Z","published_at":"2016-04-03T19:56:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the first problem in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efast 1-D convolution series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. This problem asks you to find a fast algorithm to compute the 1-D convolution in its full output shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econv\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function invoked in the form\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econv(u,v,'full')\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNext problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (same shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44324,"title":"Rewrite setdiff to account for non-unique values","description":"Setdiff(a,b) is a function that will remove all values of b from a.  Sometimes, you need this function to do a little bit extra, though.  Write a newer version of setdiff that will take into account numbers appearing multiple times in a.  For example:\r\n\r\na=[8 7 6 5 4 3 2 1 1];\r\nb=[1 3 4 5 6 7];\r\n\r\nIn this example, setdiff(a,b) would return [2 8], since only 2 and 8 are not included in a.  However, there are two \"1\" values in a, and only one \"1\" in b, so new_setdiff should return [1 2 8].  Your output vector should be sorted from low to high.\r\n\r\nYou can assume that there are no Inf or NaN in either vector, and that no values will appear in b more times than will appear in a.\r\n","description_html":"\u003cp\u003eSetdiff(a,b) is a function that will remove all values of b from a.  Sometimes, you need this function to do a little bit extra, though.  Write a newer version of setdiff that will take into account numbers appearing multiple times in a.  For example:\u003c/p\u003e\u003cp\u003ea=[8 7 6 5 4 3 2 1 1];\r\nb=[1 3 4 5 6 7];\u003c/p\u003e\u003cp\u003eIn this example, setdiff(a,b) would return [2 8], since only 2 and 8 are not included in a.  However, there are two \"1\" values in a, and only one \"1\" in b, so new_setdiff should return [1 2 8].  Your output vector should be sorted from low to high.\u003c/p\u003e\u003cp\u003eYou can assume that there are no Inf or NaN in either vector, and that no values will appear in b more times than will appear in a.\u003c/p\u003e","function_template":"function y = new_setdiff(a,b)\r\n  y = [a,b];\r\nend","test_suite":"%%\r\na=[1 1 2 3 4 5 6 7 8]; b=[1 3 4 5 6 7];\r\ny_correct=[1 2 8];\r\nassert(isequal(new_setdiff(a,b),y_correct))\r\nassert(isequal(new_setdiff(fliplr(a),b),y_correct))\r\nassert(isequal(new_setdiff(a,fliplr(b)),y_correct))\r\n%%\r\na=repmat([1:10],1,2);\r\nb=repmat([1:5],1,2);\r\ny_correct=[6 6 7 7 8 8 9 9 10 10];\r\nassert(isequal(new_setdiff(a,b),y_correct))\r\n%%\r\na=[randperm(10) 3 5 7];\r\nb=randperm(6)+1;\r\ny_correct=[1 3 5 7 8 9 10];\r\nassert(isequal(new_setdiff(a,b),y_correct))\r\n%%\r\na=[-5:5 -4:4];\r\nb=[-4:4];\r\ny_correct=[-5:5]\r\nassert(isequal(new_setdiff(a,b),y_correct))\r\n%%\r\na=[2 2 2 2 3 3 5 7];\r\nb=[2 2 2 2 3 3 5];\r\ny_correct=8;\r\nassert(isequal(new_setdiff(a,b),y_correct-1))\r\n%%\r\na=[21 124 23 20 21 23 124];\r\nb=[20 21 21 23 23];\r\ny_correct=[124 124]\r\nassert(isequal(new_setdiff(a,b),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":32,"test_suite_updated_at":"2018-01-02T15:45:30.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2017-09-14T16:19:26.000Z","updated_at":"2025-12-22T13:27:45.000Z","published_at":"2017-09-14T16:19:26.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eSetdiff(a,b) is a function that will remove all values of b from a. Sometimes, you need this function to do a little bit extra, though. Write a newer version of setdiff that will take into account numbers appearing multiple times in a. For example:\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\u003ea=[8 7 6 5 4 3 2 1 1]; b=[1 3 4 5 6 7];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn this example, setdiff(a,b) would return [2 8], since only 2 and 8 are not included in a. However, there are two \\\"1\\\" values in a, and only one \\\"1\\\" in b, so new_setdiff should return [1 2 8]. Your output vector should be sorted from low to high.\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\u003eYou can assume that there are no Inf or NaN in either vector, and that no values will appear in b more times than will appear in 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":44704,"title":"Damping of Servomotors with Tachometer Feedback","description":"In Control Engineering, servomotors with tachometer feedback can be modeled by the second order system\r\n\r\n K / [J*s^2 + (B + K*K_v)*s + K] \r\n\r\nDepending on the damping ratio of the servomotor, the system can be classified as underdamped, critically damped or overdamped. In this problem, you will be given the following as input:\r\n\r\nB - damping of servomotor (viscous and friction elements)\r\n\r\nJ - inertia of servomotor\r\n\r\nK - gain of proportional controller\r\n\r\nK_v - velocity feedback constant of tachometer \r\n\r\nYou are to correctly classify the system by returning either ' _underdamped_ ', ' _critical_ ' or ' _overdamped_ '.","description_html":"\u003cp\u003eIn Control Engineering, servomotors with tachometer feedback can be modeled by the second order system\u003c/p\u003e\u003cpre\u003e K / [J*s^2 + (B + K*K_v)*s + K] \u003c/pre\u003e\u003cp\u003eDepending on the damping ratio of the servomotor, the system can be classified as underdamped, critically damped or overdamped. In this problem, you will be given the following as input:\u003c/p\u003e\u003cp\u003eB - damping of servomotor (viscous and friction elements)\u003c/p\u003e\u003cp\u003eJ - inertia of servomotor\u003c/p\u003e\u003cp\u003eK - gain of proportional controller\u003c/p\u003e\u003cp\u003eK_v - velocity feedback constant of tachometer\u003c/p\u003e\u003cp\u003eYou are to correctly classify the system by returning either ' \u003ci\u003eunderdamped\u003c/i\u003e ', ' \u003ci\u003ecritical\u003c/i\u003e ' or ' \u003ci\u003eoverdamped\u003c/i\u003e '.\u003c/p\u003e","function_template":"function damp = ServoDamp(B,J,K,K_v)\r\n % damp?   \r\n  switch B \u003e B_c     %Critical damping\r\n      case 1\r\n          'underdamped'\r\n      case 2\r\n          'critical'\r\n      case 3\r\n          'overdamped'\r\n  end\r\nend","test_suite":"%%\r\nB = 1; J = 1; K = 12.5; K_v = 0.1;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'underdamped'))\r\n\r\n%%\r\nB = 2; J = 1; K = 4; K_v = 0.5;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'critical'))\r\n\r\n%%\r\nB = 1; J = 1; K = 12.5; K_v = 0.5;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'overdamped'))\r\n\r\n%%\r\nB = 2; J = 2; K = 8; K_v = 0.75;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'critical'))\r\n\r\n%%\r\nB = 2; J = 2; K = 10; K_v = 0.75;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'overdamped'))\r\n\r\n%%\r\nB = 1; J = 2; K = 10; K_v = 0.75;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'underdamped'))\r\n\r\n%%\r\nB = rand; J = 2; K = 10; K_v = 0.75;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'underdamped'))\r\n\r\n%%\r\nB = rand; J = 2; K = 10; K_v = 1;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'overdamped'))\r\n\r\n%%\r\nB = rand; J = 1; K = 10; K_v = 1;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'overdamped'))\r\n\r\n%%\r\nB = 3; J = 3; K = 3; K_v = 1;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'critical'))\r\n\r\n%%\r\nB = 4; J = 4; K = 4; K_v = 1;\r\nassert(isequal(ServoDamp(B,J,K,K_v),'critical'))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":178544,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":42,"test_suite_updated_at":"2018-08-02T17:30:44.000Z","rescore_all_solutions":false,"group_id":67,"created_at":"2018-08-01T23:16:46.000Z","updated_at":"2025-12-07T05:40:58.000Z","published_at":"2018-08-02T08:43:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn Control Engineering, servomotors with tachometer feedback can be modeled by the second order system\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ K / [J*s^2 + (B + K*K_v)*s + K]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDepending on the damping ratio of the servomotor, the system can be classified as underdamped, critically damped or overdamped. In this problem, you will be given the following as input:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eB - damping of servomotor (viscous and friction elements)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eJ - inertia of servomotor\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eK - gain of proportional controller\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eK_v - velocity feedback constant of tachometer\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou are to correctly classify the system by returning either '\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eunderdamped\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:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecritical\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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eoverdamped\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\"},{\"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":42795,"title":" Fast 1-D Convolution (valid shape) ","description":"Pursuant to the first problem in the \u003chttp://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution fast 1-D convolution series\u003e, this problem asks for the fast algorithm to compute the 1-D convolution in its \"valid\" output shape.  \r\n\r\nThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in *conv* function invoked in the form *conv(u,v,'valid')*, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out. \r\n\r\n* Previous problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape Fast 1-D Convolution (same shape)\u003e.","description_html":"\u003cp\u003ePursuant to the first problem in the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\"\u003efast 1-D convolution series\u003c/a\u003e, this problem asks for the fast algorithm to compute the 1-D convolution in its \"valid\" output shape.\u003c/p\u003e\u003cp\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in \u003cb\u003econv\u003c/b\u003e function invoked in the form \u003cb\u003econv(u,v,'valid')\u003c/b\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/p\u003e\u003cul\u003e\u003cli\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape\"\u003eFast 1-D Convolution (same shape)\u003c/a\u003e.\u003c/li\u003e\u003c/ul\u003e","function_template":"function w = fconv1v(u,v)\r\n  % Extremely inefficient solution not guaranteed to pass all tests :-(\r\n  w = conv(u,v,'valid'); \r\nend","test_suite":"%%\r\n%{\r\n╔═════════════════════════════════════════════════════════════╗\r\n║ Please note that problems in this series are designed for   ║\r\n║ optimizing the code performance, rather than the usual Cody ║\r\n║ \"size\". We are achieving this goal by courtesy of LY Cao's  ║ \r\n║ new scoring function, which automatically grants a better   ║\r\n║ score to a faster solution. Kindly note that simply using   ║\r\n║ the conv function may result in a poor score or even failure║\r\n║ in one of the tests. Suggestions and comments are welcome.  ║\r\n║                                                             ║\r\n║ Thanks \u0026 have fun!                                          ║\r\n║ Peng                                                        ║\r\n╚═════════════════════════════════════════════════════════════╝\r\n%}\r\n\r\n%%\r\nfid = fopen('EvaluateSolution.p','wb'); \r\nfwrite(fid,uint8(sscanf('7630312E30307630302E3030000CF01CCC561FB1000000C30000012D000001D160E44E2EC6DB5CE66B30F9B560AF40D6A7226365293F6413AE84ABD44D4C7EE5C617DCDAC2521B24B2951C23F50BA9DAA4179B35DCED27A697FC9CA9A308698729973CACEC16670C077236F96E9D16612152B0C32FC57E4755E80E40AC876804B7835D9703BC5A1D6FC519FDEDE22237DC59455FF0014FEBCEF1CB2A840158E11CDD5D6C78D594F50B575A4DF9FB54705F2C6D40341F12CE207B892CBEDEC018A1F94CFA1D5FBB9E1912BA424CD5C6C422D6F3451A8BDD2543834B3FFAD3107D8F16C78D75DD9F3AD197D5591B1686E190D8DF4B5EF3AC28C641296E92FB02BC395D442C03480E156E48F8B61AA3C6F1526AA95C1C466C77A3803AF8523098B0A3ED10A07E2F93274DC8207B05A572988754AAC211A330C2FEC7928CFD51D3A6FBDD9FFA6036C948E0C4239A16','%2x')));\r\nfclose(fid);\r\n\r\n%%\r\nu = 1; v = 1;\r\ny_correct = 1;\r\nassert(isequal(fconv1v(u,v),y_correct))\r\n\r\n%%\r\nu = 1:10; v = 1:5;\r\ny_correct = conv(u,v,'valid');\r\nassert(all(abs(fconv1v(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = 1:5; v = 1:10;\r\ny_correct = zeros(1,0);\r\nassert(isequal(fconv1v(u,v),y_correct))\r\n\r\n%%\r\nu = rand(20,1); v = rand(10,1);\r\ny_correct = conv(u,v,'valid');\r\nassert(all(abs(fconv1v(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(10,1); v = rand(20,1);\r\ny_correct = zeros(0,1);\r\nassert(isequal(fconv1v(u,v),y_correct))\r\n\r\n%%\r\n% Large data size\r\nglobal sol_score\r\nAbsTol = 1e-6;   % Maximum absolute error tolerance\r\nuu = rand(5e6,15); vv = rand(2e5,15);\r\nfor iter = 15:-1:1\r\n    u = uu(:,iter); v = vv(:,iter);\r\n    t = builtin('tic');\r\n    y = fconv1v(u,v);\r\n    timeSpan(iter) = builtin('toc',t);\r\n    pass(iter) = EvaluateSolution(u,v,y,AbsTol);  \r\nend\r\nsol_score = sum(timeSpan);\r\nassert(all(pass));\r\n\r\n%%\r\n% New scoring function by LY Cao\r\nglobal sol_score\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\nscore(sol_score);","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2016-04-05T21:09:16.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2016-04-02T21:30:34.000Z","updated_at":"2025-12-21T14:08:51.000Z","published_at":"2016-04-04T01:47:39.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the first problem in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efast 1-D convolution series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, this problem asks for the fast algorithm to compute the 1-D convolution in its \\\"valid\\\" output shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econv\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function invoked in the form\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econv(u,v,'valid')\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (same shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44260,"title":"Multivariate polynomials - convert monomial form to array","description":"In \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44259-product-of-two-multidimensional-polynomials Problem 44259\u003e I asked you to multiply two multidimensional polynomials that were represented by an array that is a generalization of the way MATLAB handles one-variable polynomials. However, that representation has at least two problems:\r\n\r\n# Defining a polynomial is an indexing headache, with a high probability of errors.  \r\n# Polynomials often have a small number of terms, so if they are higher order there will be a lot of wasted storage.\r\n\r\nHere, we will represent a polynomial as a sum of monomials. For example, the polynomial |p(x,y) = 2*x^5*y + 3*x*y^5| is the sum of two monomials in |x| and |y|. We will represent this by |exponents|, a matrix of integers with each row representing the exponents of one monomial (including zeros); and a column vector |coefficients| for the coefficient of each monomial. For |p(x,y)|, these are\r\n\r\n  exponents = [5 1; 1 5];\r\ncoefficients = [2; 3];\r\n\r\nLet's hedge our bets, though, and create a function that converts this form to the array form. Your task is to create a function\r\n\r\n  function c = coeffArray(exponents,coefficients)\r\n\r\nthat inputs the exponents and coefficients and returns an array as defined in Problem 44259.","description_html":"\u003cp\u003eIn \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44259-product-of-two-multidimensional-polynomials\"\u003eProblem 44259\u003c/a\u003e I asked you to multiply two multidimensional polynomials that were represented by an array that is a generalization of the way MATLAB handles one-variable polynomials. However, that representation has at least two problems:\u003c/p\u003e\u003col\u003e\u003cli\u003eDefining a polynomial is an indexing headache, with a high probability of errors.\u003c/li\u003e\u003cli\u003ePolynomials often have a small number of terms, so if they are higher order there will be a lot of wasted storage.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eHere, we will represent a polynomial as a sum of monomials. For example, the polynomial \u003ctt\u003ep(x,y) = 2*x^5*y + 3*x*y^5\u003c/tt\u003e is the sum of two monomials in \u003ctt\u003ex\u003c/tt\u003e and \u003ctt\u003ey\u003c/tt\u003e. We will represent this by \u003ctt\u003eexponents\u003c/tt\u003e, a matrix of integers with each row representing the exponents of one monomial (including zeros); and a column vector \u003ctt\u003ecoefficients\u003c/tt\u003e for the coefficient of each monomial. For \u003ctt\u003ep(x,y)\u003c/tt\u003e, these are\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eexponents = [5 1; 1 5];\r\ncoefficients = [2; 3];\r\n\u003c/pre\u003e\u003cp\u003eLet's hedge our bets, though, and create a function that converts this form to the array form. Your task is to create a function\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003efunction c = coeffArray(exponents,coefficients)\r\n\u003c/pre\u003e\u003cp\u003ethat inputs the exponents and coefficients and returns an array as defined in Problem 44259.\u003c/p\u003e","function_template":"function c = coeffArray(exponents,coefficients)\r\nc = 0;\r\nend","test_suite":"%% test coeffArray\r\nfiletext = fileread('coeffArray.m');\r\nassert(~contains(filetext,'regexp'))\r\n\r\n%% No variables\r\nexponents = 0;\r\ncoefficients = randi(1000);\r\ncA = coefficients;\r\nassert(isequal(coeffArray(exponents,coefficients),cA))\r\n\r\n%% Single variable\r\ncoefficients = randi(1000,[10 1]);\r\nexponents = (9:-1:0)';\r\ncA = coefficients;\r\nassert(isequal(coeffArray(exponents,coefficients),cA))\r\n\r\n%% a*x^2+b*y\r\na = randi(1000);\r\nb = randi(1000);\r\nexponents = [2 0; 0 1];\r\ncoefficients = [a; b];\r\ncA = [0 a; 0 0; b 0];\r\nassert(isequal(coeffArray(exponents,coefficients),cA))\r\n\r\n%% a*x^2+b*y^2+c*z^2+d\r\na = randi(1000);\r\nb = randi(1000);\r\nc = randi(1000);\r\nd = randi(1000);\r\nexponents = [2 0 0; 0 2 0; 0 0 2; 0 0 0];\r\ncoefficients = [a; b; c; d];\r\ncA = zeros([3 3 3]);\r\ncA(1,3,3) = a;\r\ncA(3,1,3) = b;\r\ncA(3,3,1) = c;\r\ncA(3,3,3) = d;\r\nassert(isequal(coeffArray(exponents,coefficients),cA))\r\n\r\n%% Many variables\r\ncoefficients = randi(1000);\r\nnVars = randi(20)+1;\r\nexponents = ones(1,nVars);\r\ncA = zeros(2*ones(1,nVars));\r\ncA(1) = coefficients;\r\nassert(isequal(coeffArray(exponents,coefficients),cA))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":8,"created_by":1011,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":12,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-07-13T16:16:41.000Z","updated_at":"2025-12-22T13:09:01.000Z","published_at":"2017-07-13T16:26:38.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44259-product-of-two-multidimensional-polynomials\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44259\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e I asked you to multiply two multidimensional polynomials that were represented by an array that is a generalization of the way MATLAB handles one-variable polynomials. However, that representation has at least two problems:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDefining a polynomial is an indexing headache, with a high probability of errors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePolynomials often have a small number of terms, so if they are higher order there will be a lot of wasted storage.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHere, we will represent a polynomial as a sum of monomials. For example, the polynomial\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\u003ep(x,y) = 2*x^5*y + 3*x*y^5\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is the sum of two monomials in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. We will represent this by\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eexponents\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, a matrix of integers with each row representing the exponents of one monomial (including zeros); and a column vector\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\u003ecoefficients\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for the coefficient of each monomial. For\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ep(x,y)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, these are\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[exponents = [5 1; 1 5];\\ncoefficients = [2; 3];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet's hedge our bets, though, and create a function that converts this form to the array form. Your task is to create a function\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[function c = coeffArray(exponents,coefficients)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethat inputs the exponents and coefficients and returns an array as defined in Problem 44259.\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":44262,"title":"Multivariate polynomials - overload multiplication","description":"Problems \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44260-multivariate-polynomials-convert-monomial-form-to-array 44260\u003e and \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44261-sort-multivariate-monomials 44261\u003e work with a monomial representation of multivariate polynomials. This has two parts, a matrix |exponents| with a row of exponents for each monomial, and a column vector |coefficients| with a coefficient for each monomial.\r\n\r\nIt would be nice to define polynomials so they can be multiplied using simple notation:\r\n\r\n  p = p1*p2;\r\n\r\nThis can be done by \u003chttps://www.mathworks.com/help/matlab/matlab_oop/user-defined-classes.html defining a class\u003e |mPoly| with two properties, |exponents| and |coefficients|, and two methods: a \u003chttps://www.mathworks.com/help/matlab/matlab_oop/class-constructor-methods.html constructor\u003e with the syntax\r\n\r\n  p = mPoly(exponents, coefficients)\r\n\r\nand a method \u003chttps://www.mathworks.com/help/matlab/ref/mtimes.html?searchHighlight=mtimes\u0026s_tid=doc_srchtitle mtimes\u003e for multiplying two polynomials. You can assume that the polynomials being multiplied have the same number of variables.\r\n","description_html":"\u003cp\u003eProblems \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44260-multivariate-polynomials-convert-monomial-form-to-array\"\u003e44260\u003c/a\u003e and \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44261-sort-multivariate-monomials\"\u003e44261\u003c/a\u003e work with a monomial representation of multivariate polynomials. This has two parts, a matrix \u003ctt\u003eexponents\u003c/tt\u003e with a row of exponents for each monomial, and a column vector \u003ctt\u003ecoefficients\u003c/tt\u003e with a coefficient for each monomial.\u003c/p\u003e\u003cp\u003eIt would be nice to define polynomials so they can be multiplied using simple notation:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ep = p1*p2;\r\n\u003c/pre\u003e\u003cp\u003eThis can be done by \u003ca href = \"https://www.mathworks.com/help/matlab/matlab_oop/user-defined-classes.html\"\u003edefining a class\u003c/a\u003e \u003ctt\u003emPoly\u003c/tt\u003e with two properties, \u003ctt\u003eexponents\u003c/tt\u003e and \u003ctt\u003ecoefficients\u003c/tt\u003e, and two methods: a \u003ca href = \"https://www.mathworks.com/help/matlab/matlab_oop/class-constructor-methods.html\"\u003econstructor\u003c/a\u003e with the syntax\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ep = mPoly(exponents, coefficients)\r\n\u003c/pre\u003e\u003cp\u003eand a method \u003ca href = \"https://www.mathworks.com/help/matlab/ref/mtimes.html?searchHighlight=mtimes\u0026s_tid=doc_srchtitle\"\u003emtimes\u003c/a\u003e for multiplying two polynomials. You can assume that the polynomials being multiplied have the same number of variables.\u003c/p\u003e","function_template":"classdef mPoly \r\n    %MPOLY Class of multivariate polynomials\r\n    \r\n    properties\r\n        exponents\r\n        coefficients\r\n    end\r\n    \r\n    methods\r\n        function p = mPoly(ex,co)\r\n        end\r\n        function p = mtimes(p1,p2)\r\n        end\r\n    end\r\n    \r\nend\r\n","test_suite":"%% Test polyMult\r\nfiletext = fileread('mPoly.m');\r\nassert(~contains(filetext,'regexp'))\r\n\r\n%% p1 = A, p2 = B\r\nc1 = randi(1000); c2 = randi(1000);\r\ne = 0;\r\np1 = mPoly(e,c1);\r\np2 = mPoly(e,c2);\r\np = p1*p2;\r\nassert(isequal(c1*c2,p.coefficients))\r\nassert(isequal(e,p.exponents))\r\n\r\n%% p1 = y-x^2, p2 = x-2\r\ne1 = [2 0; 0 1];\r\nc1 = [-1; 1];\r\ne2 = [1 0; 0 0];\r\nc2 = [1; -2];\r\np1 = mPoly(e1,c1);\r\np2 = mPoly(e2,c2);\r\np = p1*p2;\r\n\r\n[e,idx] = unique(p.exponents,'rows');\r\nc = p.coefficients(idx);\r\nassert(isequal(e,[0 1; 1 1; 2 0; 3 0]))\r\nassert(isequal(c,[-2; 1; 2; -1]))\r\n\r\n%% p1 = y-x^2, p2 = z-2\r\ne1 = [0 1 0; 2 0 0];\r\nc1 = [1; -1];\r\ne2 = [0 0 1; 0 0 0];\r\nc2 = [1; -2];\r\np1 = mPoly(e1,c1);\r\np2 = mPoly(e2,c2);\r\np = p1*p2;\r\n\r\n[e,idx] = unique(p.exponents,'rows');\r\nc = p.coefficients(idx);\r\nassert(isequal(e,[0 1 0; 0 1 1; 2 0 0; 2 0 1]))\r\nassert(isequal(c,[-2; 1; 2; -1]))\r\n\r\n\r\n%% p1 = z-x^3, p2 = x^2+y^2+z^2-1\r\ne1 = [0 0 1; 3 0 0];\r\nc1 = [1; -1];\r\ne2 = [2 0 0; 0 2 0; 0 0 2; 0 0 0];\r\nc2 = [1; 1; 1; -1];\r\n\r\np1 = mPoly(e1,c1);\r\np2 = mPoly(e2,c2);\r\np = p1*p2;\r\n\r\n[e,idx] = unique(p.exponents,'rows');\r\nc = p.coefficients(idx);\r\nassert(isequal(e,[0 0 1; 0 0 3; 0 2 1; 2 0 1; 3 0 0; 3 0 2; 3 2 0; 5 0 0]))\r\nassert(isequal(c,[-1 1 1 1 1 -1 -1 -1]'))\r\n\r\n%% Commutative\r\nc1 = randi(1000,[2 1]);\r\ne1 = randi(1000,[2 2]);\r\nc2 = randi(1000,[3 1]);\r\ne2 = randi(1000,[3 2]);\r\np1 = mPoly(e1,c1);\r\np2 = mPoly(e2,c2);\r\np12 = p1*p2;\r\np21 = p2*p1;\r\n[e12,i12] = unique(p12.exponents,'rows');\r\n[e21,i21] = unique(p21.exponents,'rows');\r\nc12 = p12.coefficients(i12);\r\nc21 = p21.coefficients(i21);\r\nassert(isequal(e12,e21))\r\nassert(isequal(c12,c21))","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":1011,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-07-14T04:04:05.000Z","updated_at":"2025-12-22T13:16:38.000Z","published_at":"2017-07-14T04:04: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\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eProblems\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44260-multivariate-polynomials-convert-monomial-form-to-array\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e44260\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44261-sort-multivariate-monomials\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e44261\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e work with a monomial representation of multivariate polynomials. This has two parts, a matrix\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\u003eexponents\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with a row of exponents for each monomial, and a column vector\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\u003ecoefficients\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with a coefficient for each monomial.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt would be nice to define polynomials so they can be multiplied using simple notation:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[p = p1*p2;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis can be done by\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/help/matlab/matlab_oop/user-defined-classes.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edefining a class\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emPoly\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with two properties,\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\u003eexponents\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecoefficients\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and two methods: a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/help/matlab/matlab_oop/class-constructor-methods.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003econstructor\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e with the syntax\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[p = mPoly(exponents, coefficients)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eand a method\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/help/matlab/ref/mtimes.html?searchHighlight=mtimes\u0026amp;s_tid=doc_srchtitle\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emtimes\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e for multiplying two polynomials. You can assume that the polynomials being multiplied have the same number of variables.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42794,"title":" Fast 1-D Convolution (same shape) ","description":"Pursuant to the first problem in the \u003chttp://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution fast 1-D convolution series\u003e, this problem asks for the fast algorithm to compute the 1-D convolution with the same input-output shape.  \r\n\r\nThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in *conv* function invoked in the form *conv(u,v,'same')*, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out. \r\n\r\n* Previous problem:  \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42793-fast-1-d-convolution-full-shape Fast 1-D Convolution (full shape)\u003e\r\n* Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42795-fast-1-d-convolution-valid-shape Fast 1-D Convolution (valid shape)\u003e\r\n","description_html":"\u003cp\u003ePursuant to the first problem in the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\"\u003efast 1-D convolution series\u003c/a\u003e, this problem asks for the fast algorithm to compute the 1-D convolution with the same input-output shape.\u003c/p\u003e\u003cp\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in \u003cb\u003econv\u003c/b\u003e function invoked in the form \u003cb\u003econv(u,v,'same')\u003c/b\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/p\u003e\u003cul\u003e\u003cli\u003ePrevious problem:  \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42793-fast-1-d-convolution-full-shape\"\u003eFast 1-D Convolution (full shape)\u003c/a\u003e\u003c/li\u003e\u003cli\u003eNext problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42795-fast-1-d-convolution-valid-shape\"\u003eFast 1-D Convolution (valid shape)\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = fconv1s(u,v)\r\n  % Extremely inefficient solution not guaranteed to pass all tests :-(\r\n  y = conv(u,v,'same'); \r\nend","test_suite":"%%\r\n%{\r\n╔═════════════════════════════════════════════════════════════╗\r\n║ Please note that problems in this series are designed for   ║\r\n║ optimizing the code performance, rather than the usual Cody ║\r\n║ \"size\". We are achieving this goal by courtesy of LY Cao's  ║ \r\n║ new scoring function, which automatically grants a better   ║\r\n║ score to a faster solution. Kindly note that simply using   ║\r\n║ the conv function may result in a poor score or even failure║\r\n║ in one of the tests. Suggestions and comments are welcome.  ║\r\n║                                                             ║\r\n║ Thanks \u0026 have fun!                                          ║\r\n║ Peng                                                        ║\r\n╚═════════════════════════════════════════════════════════════╝\r\n%}\r\n\r\n%%\r\nfid = fopen('EvaluateSolution.p','wb'); \r\nfwrite(fid,uint8(sscanf('7630312E30307630302E3030000E201CC0225FB10000010B000001480000023C141D1F2F8C075F9CDC9AA9EE4F066DD1BE8B37851CBC980DC3CFCB6C55FAA40EAEED061766137EB39A214C865F6410AAF263010C3B9D012F499C4718371499BB689324D8892718476958CEAC4EE884BB215750071FA3AEE658AB639696B588AA35864A8AF99C9981E6AB14F1BE31F76F320D6F1EA110DE5A9E1C9F4597921FF711410412A4E9C4AA1026E997F054CBEF2A6FC2607C95B65D62747B293B8A86A0D33830E20CCB930D6986416727FFE5CB77FE03A0722EE2B47A07493392D53C4C7A0995EDFA31DB344F2C390E67574523D59403673E343AB6E1A5D83D0EE6B4E784AAA80184B8295937D1648E6A92E82360BE54C82D837FFBE28102BB1EF99FEB94473DB16240A68474D4E8DA84CD1B6DB5AA3FB2921D378C5D78A3A006E36169618AF0F4A18645472518E158E85BB81BC6CBEDCD7A861A67E1ECC712442F423199F4EB715F9493CA','%2x')));\r\nfclose(fid);\r\n\r\n%%\r\nu = 1; v = 1;\r\ny_correct = 1;\r\nassert(isequal(fconv1s(u,v),y_correct))\r\n\r\n%%\r\nu = 1:10; v = 1:5;\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = 1:5; v = 1:10;\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(20,1); v = rand(10,1);\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(10,1); v = rand(20,1);\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\n% Large data size\r\nglobal sol_score\r\nAbsTol = 1e-6;   % Maximum absolute error tolerance\r\nfor iter = 15:-1:1\r\n    u = rand(5e6,1); v = rand(2e5,1);\r\n    t = builtin('tic');\r\n    y = fconv1s(u,v);\r\n    timeSpan(iter) = builtin('toc',t);\r\n    pass(iter) = EvaluateSolution(u,v,y,AbsTol);  \r\nend\r\nsol_score = sum(timeSpan);\r\nassert(all(pass));\r\n\r\n%%\r\n% New scoring function by LY Cao\r\nglobal sol_score\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\nscore(sol_score);","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2016-04-05T20:53:23.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2016-04-02T21:30:23.000Z","updated_at":"2025-12-21T14:01:33.000Z","published_at":"2016-04-04T01:47:11.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the first problem in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efast 1-D convolution series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, this problem asks for the fast algorithm to compute the 1-D convolution with the same input-output shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econv\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function invoked in the form\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econv(u,v,'same')\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42793-fast-1-d-convolution-full-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (full shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNext problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42795-fast-1-d-convolution-valid-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (valid shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":44263,"title":"Multivariate polynomials - emulate symbolic form","description":"In \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44262-multivariate-polynomials-overload-multiplication Problem 44262\u003e I asked you to create a class |mPoly| with overloaded multiplication, so a product of two polynomials can be expressed in the form |p = p1*p2|. However, the method of constructing these polynomials is still somewhat unintuitive. In the \u003chttps://www.mathworks.com/products/symbolic.html Symbolic Math Toolbox\u003e, one can simply define some variables,\r\n\r\n  syms x y z\r\n\r\nand then create a polynomial:\r\n\r\n  p = 2*x*y + 3*x^5*z;\r\n\r\nWe would like to do something like that here. As a start, create a class |mPolySym| with properties |exponents| and |coefficients|, and |varnames|,  where the first two properties are the same as in previous problems and |varnames| is a \u003chttps://www.mathworks.com/help/matlab/characters-and-strings.html string array\u003e. The constructor should accept a numeric, char or string input, e.g.,\r\n\r\n  x = mPolySym('x')\r\n\r\n  x = \r\n\r\n  mPolySym with properties:\r\n\r\n        varnames: \"x\"\r\n       exponents: 1\r\n    coefficients: 1\r\n\r\n  r = mPolySym(pi)\r\n\r\n  r = \r\n\r\n  mPolySym with properties:\r\n\r\n        varnames: [0×0 string]\r\n       exponents: 1\r\n    coefficients: 3.1416\r\n\r\nAlso modify the method |mtimes| from the previous problem so it can multiply polynomials with different variable names.","description_html":"\u003cp\u003eIn \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44262-multivariate-polynomials-overload-multiplication\"\u003eProblem 44262\u003c/a\u003e I asked you to create a class \u003ctt\u003emPoly\u003c/tt\u003e with overloaded multiplication, so a product of two polynomials can be expressed in the form \u003ctt\u003ep = p1*p2\u003c/tt\u003e. However, the method of constructing these polynomials is still somewhat unintuitive. In the \u003ca href = \"https://www.mathworks.com/products/symbolic.html\"\u003eSymbolic Math Toolbox\u003c/a\u003e, one can simply define some variables,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003esyms x y z\r\n\u003c/pre\u003e\u003cp\u003eand then create a polynomial:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ep = 2*x*y + 3*x^5*z;\r\n\u003c/pre\u003e\u003cp\u003eWe would like to do something like that here. As a start, create a class \u003ctt\u003emPolySym\u003c/tt\u003e with properties \u003ctt\u003eexponents\u003c/tt\u003e and \u003ctt\u003ecoefficients\u003c/tt\u003e, and \u003ctt\u003evarnames\u003c/tt\u003e,  where the first two properties are the same as in previous problems and \u003ctt\u003evarnames\u003c/tt\u003e is a \u003ca href = \"https://www.mathworks.com/help/matlab/characters-and-strings.html\"\u003estring array\u003c/a\u003e. The constructor should accept a numeric, char or string input, e.g.,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = mPolySym('x')\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ex = \r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003emPolySym with properties:\r\n\u003c/pre\u003e\u003cpre\u003e        varnames: \"x\"\r\n       exponents: 1\r\n    coefficients: 1\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003er = mPolySym(pi)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003er = \r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003emPolySym with properties:\r\n\u003c/pre\u003e\u003cpre\u003e        varnames: [0×0 string]\r\n       exponents: 1\r\n    coefficients: 3.1416\u003c/pre\u003e\u003cp\u003eAlso modify the method \u003ctt\u003emtimes\u003c/tt\u003e from the previous problem so it can multiply polynomials with different variable names.\u003c/p\u003e","function_template":"classdef mPolySym\r\n    properties\r\n        varnames\r\n        exponents\r\n        coefficients\r\n    end\r\n    \r\n    methods\r\n        function p = mPolySym(s)\r\n        end\r\n        \r\n        function p = mtimes(p1,p2)\r\n        end            \r\n    end\r\n    \r\nend\r\n\r\n","test_suite":"%% Test mPolySym\r\nfiletext = fileread('mPolySym.m');\r\nassert(~contains(filetext,'regexp'))\r\n\r\n\r\n%%\r\nr = randi(1000);\r\nx = mPolySym(r);\r\nassert(isempty(x.varnames))\r\nassert(isequal(x.exponents,0))\r\nassert(isequal(x.coefficients,r))\r\n\r\n%%\r\nr = randi(1000);\r\nx = mPolySym('x');\r\ny = r*x;\r\nassert(isequal(y.varnames,\"x\"))\r\nassert(isequal(y.exponents,1))\r\nassert(isequal(y.coefficients,r))\r\nassert(isequal(r*x,x*r))\r\n\r\n%%\r\nx = mPolySym('x');\r\ny = mPolySym(\"y\");\r\nz = mPolySym('z');\r\nw = x*y*z;\r\nassert(isequal(w.varnames,[\"x\" \"y\" \"z\"]))\r\nassert(isequal(w.exponents,[1 1 1]))\r\nassert(isequal(w.coefficients,1))\r\n\r\n%%\r\nm = randi(5);\r\nn = randi(4);\r\nx = mPolySym(\"x\");\r\ny = mPolySym(\"y\");\r\np = [repmat(x,1,m) repmat(y,1,n)];\r\np = p(randperm(length(p)));\r\nr = randi(1000);\r\np_prod = r;\r\nfor ii=1:length(p)\r\n    p_prod = p_prod*p(ii);\r\nend\r\ns = randi(1000);\r\np_prod = p_prod*s;\r\nassert(isequal(p_prod.varnames,[\"x\" \"y\"]))\r\nassert(isequal(p_prod.exponents,[m n]))\r\nassert(isequal(p_prod.coefficients,r*s))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":1011,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-07-14T23:13:17.000Z","updated_at":"2025-12-22T13:23:36.000Z","published_at":"2017-07-14T23:13:34.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44262-multivariate-polynomials-overload-multiplication\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44262\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e I asked you to create a class\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\u003emPoly\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with overloaded multiplication, so a product of two polynomials can be expressed in the form\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\u003ep = p1*p2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. However, the method of constructing these polynomials is still somewhat unintuitive. In the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/products/symbolic.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSymbolic Math Toolbox\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, one can simply define some variables,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[syms x y z]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eand then create a polynomial:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[p = 2*x*y + 3*x^5*z;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWe would like to do something like that here. As a start, create a class\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\u003emPolySym\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with properties\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\u003eexponents\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecoefficients\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003evarnames\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, where the first two properties are the same as in previous problems and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003evarnames\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/help/matlab/characters-and-strings.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estring array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. The constructor should accept a numeric, char or string input, e.g.,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[x = mPolySym('x')\\n\\nx = \\n\\nmPolySym with properties:\\n\\n        varnames: \\\"x\\\"\\n       exponents: 1\\n    coefficients: 1\\n\\nr = mPolySym(pi)\\n\\nr = \\n\\nmPolySym with properties:\\n\\n        varnames: [0×0 string]\\n       exponents: 1\\n    coefficients: 3.1416]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAlso modify the method\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\u003emtimes\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e from the previous problem so it can multiply polynomials with different variable names.\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":1891,"title":"High Precision Square Root (Inspired by Project Euler 80)","description":"Given a positive integer n which is not a perfect square, write a MATLAB script that will calculate the square root of n truncated to k places after the decimal point.  Your output should be a string.  For example, the output of string_sqrt(1000,10) should be '31.6227766016'  Notice that the square root of 1000 is (according to MATLAB) 31.62277660168379, so we want the integer part complete, as well as the first k numbers after the decimal point without rounding.\r\n\r\nSeveral of the values of k will be larger than the usual precision shown by MATLAB, so you'll need to be inventive.  Good luck.","description_html":"\u003cp\u003eGiven a positive integer n which is not a perfect square, write a MATLAB script that will calculate the square root of n truncated to k places after the decimal point.  Your output should be a string.  For example, the output of string_sqrt(1000,10) should be '31.6227766016'  Notice that the square root of 1000 is (according to MATLAB) 31.62277660168379, so we want the integer part complete, as well as the first k numbers after the decimal point without rounding.\u003c/p\u003e\u003cp\u003eSeveral of the values of k will be larger than the usual precision shown by MATLAB, so you'll need to be inventive.  Good luck.\u003c/p\u003e","function_template":"function y = string_sqrt(n,k)\r\n  y = sqrt(n);\r\nend","test_suite":"%%\r\nassert(strcmp(string_sqrt(1000,10),'31.6227766016'))\r\n%%\r\nassert(strcmp(string_sqrt(10,11),'3.16227766016'))\r\n%%\r\nassert(strcmp(string_sqrt(3,100),'1.7320508075688772935274463415058723669428052538103806280558069794519330169088000370811461867572485756'))\r\n%%\r\nassert(strcmp(string_sqrt(314159,314),'560.49888492306565872479934293941633491101288779142813321911971670725840486880541273457870660258696202335374555140881778649205224589390756076993240996126057385009263605818384161945745399159720436585888004381611637660905033452884843995010613320008027334007622507916692664539613518278405454926834945753785814159773889523'))\r\n%%\r\na=2:50;\r\na(sqrt(a)==floor(sqrt(a)))=[];\r\nna=numel(a);\r\nb=zeros(na,100);\r\nfor flag=1:na\r\n    temp=string_sqrt(a(flag),101);\r\n    t2=regexprep(temp,'\\.','')-'0';\r\n    b(flag,:)=t2(1:100);\r\nend\r\ny_correct=sum(sum(b))\r\nassert(isequal(19543,y_correct))\r\n%%\r\nassert(strcmp(string_sqrt(12345,1),'111.1'))","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":32,"test_suite_updated_at":"2018-06-07T19:02:44.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2013-09-25T17:51:53.000Z","updated_at":"2026-01-11T21:55:54.000Z","published_at":"2013-09-25T17:51:53.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a positive integer n which is not a perfect square, write a MATLAB script that will calculate the square root of n truncated to k places after the decimal point. Your output should be a string. For example, the output of string_sqrt(1000,10) should be '31.6227766016' Notice that the square root of 1000 is (according to MATLAB) 31.62277660168379, so we want the integer part complete, as well as the first k numbers after the decimal point without rounding.\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\u003eSeveral of the values of k will be larger than the usual precision shown by MATLAB, so you'll need to be inventive. Good luck.\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":44788,"title":"Find the right number make the equation","description":"Given positive integer number n, find the right positive integer number a, b , so that\r\n\r\n(1) sqrt(a + n * b) is a positive integer number\r\n\r\n(2) sqrt(hypot(a,b)) is a positive integer number\r\n\r\nNote: the output must be char array!\r\n\r\nHave fun!","description_html":"\u003cp\u003eGiven positive integer number n, find the right positive integer number a, b , so that\u003c/p\u003e\u003cp\u003e(1) sqrt(a + n * b) is a positive integer number\u003c/p\u003e\u003cp\u003e(2) sqrt(hypot(a,b)) is a positive integer number\u003c/p\u003e\u003cp\u003eNote: the output must be char array!\u003c/p\u003e\u003cp\u003eHave fun!\u003c/p\u003e","function_template":"function y = find_right_number_for_F(x)\r\n  y = x;\r\nend","test_suite":"%% 1\r\nfid = fopen('exact_sqrt.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E3030000CD01C075E1FB1000000F50000013F000002084A6250378D76402208455D72089B6355C54CE41DAC5E5D8129D83CBBAA1298A3BE0AFCD19ECC54791798C1E7C908661803C1E84CE1A34089045C234BBA103F7F21225744CD37C61C65D6FE689DCBA50D9A70776FEA59EC224810665D53FDAEF2D71449ECE6BABA1B97F1070DBBBB7ACDF5C88F8746488D240C547290A48071B3B492C3ADEE8AEDA6D726D76AC58C7BAAB8B6EEB627053173E88789D827D53FFA23337CE20BDD3DE6DFA095DED77BB8CB39C2A19D01D19598138320A2005B359B41990D2056B0F58DAA63A7CD89DB3E986F894F2F4798965E19ACE7B495E38FE1F1B836A3052787B54FD1662FD63F8AA1136D1D92BA3992E68837ACE9C7D1FD906D9C50B45409E0B8605994EF31A6D8AFFE676ACB24F9485643451A5565A9A515D7772D35B07198F84F45095F77985BE91C7A7CB54245F80C26DC1DC1FFB8FC','%2x'));\r\nfclose(fid);\r\n\r\n%% 2\r\nfor n = 1 : 3\r\n    [a, b] = find_right_number_for_F(n);\r\n    assert(ischar(a));\r\n    assert(ischar(b));\r\n    a = java.math.BigInteger(a);\r\n    b = java.math.BigInteger(b);\r\n    c = a.add(b.multiply(java.math.BigInteger(int2str(n))));\r\n    [~, r] = exact_sqrt(char(c));\r\n    assert(isequal(r,'0'));\r\n    d = a.pow(2).add(b.pow(2));\r\n    [e,r1] = exact_sqrt(char(d));\r\n    assert(isequal(r1,'0'));\r\n    [~,r2] = exact_sqrt(char(e));\r\n    assert(isequal(r2,'0'));\r\nend\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":10,"created_by":3668,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":"2018-11-19T07:42:50.000Z","rescore_all_solutions":false,"group_id":67,"created_at":"2018-11-14T07:44:42.000Z","updated_at":"2025-12-20T13:17:01.000Z","published_at":"2018-11-14T07:45:12.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven positive integer number n, find the right positive integer number a, b , so that\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\u003e(1) sqrt(a + n * b) is a positive integer number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(2) sqrt(hypot(a,b)) is a positive integer number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote: the output must be char array!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHave fun!\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":44249,"title":"Pipeline - Variable-length Input","description":"Design the |gt|(\u003e) method of |function_handle| so that:\r\n\r\n  \u003e\u003e 1 \u003e @sin \u003e @cos\r\nans =\r\n         0.666366745392881\r\n\u003e\u003e cos(sin(1))\r\nans =\r\n         0.666366745392881\r\n\u003e\u003e {1, 3, 3} \u003e @linspace\r\nans =\r\n     1     2     3\r\n\u003e\u003e linspace(1, 3, 3)\r\nans =\r\n     1     2     3\r\n\r\nThe |gt.m| you submitted will be moved to the class folder |@function_handle|:\r\n  \r\n  mkdir @function_handle\r\n  movefile submission/gt.m @function_handle\r\n\r\n*See Also:* \u003chttps://www.mathworks.com/matlabcentral/cody/problems/42817-pipeline Problem 42817. Pipeline\u003e","description_html":"\u003cp\u003eDesign the \u003ctt\u003egt\u003c/tt\u003e(\u0026gt;) method of \u003ctt\u003efunction_handle\u003c/tt\u003e so that:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u0026gt;\u0026gt; 1 \u0026gt; @sin \u0026gt; @cos\r\nans =\r\n       0.666366745392881\r\n\u0026gt;\u0026gt; cos(sin(1))\r\nans =\r\n       0.666366745392881\r\n\u0026gt;\u0026gt; {1, 3, 3} \u0026gt; @linspace\r\nans =\r\n   1     2     3\r\n\u0026gt;\u0026gt; linspace(1, 3, 3)\r\nans =\r\n   1     2     3\r\n\u003c/pre\u003e\u003cp\u003eThe \u003ctt\u003egt.m\u003c/tt\u003e you submitted will be moved to the class folder \u003ctt\u003e@function_handle\u003c/tt\u003e:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003emkdir @function_handle\r\nmovefile submission/gt.m @function_handle\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eSee Also:\u003c/b\u003e \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/42817-pipeline\"\u003eProblem 42817. Pipeline\u003c/a\u003e\u003c/p\u003e","function_template":"function varargout = gt(a, b)\r\n\r\nend","test_suite":"mkdir @function_handle\r\nmovefile submission/gt.m @function_handle\r\n\r\n%%\r\nassert(isequal(cos(sin(1)), 1 \u003e @sin \u003e @cos))\r\n\r\n%%\r\nisequal(linspace(1, 3), {1, 3} \u003e @linspace) \u003e @assert\r\n\r\n%%\r\na = rand(1,5);\r\n[b, s] = {a, 'descend'} \u003e @sort\r\n[c, t] = sort(a, 'descend');\r\n{isequal(b, c) \u0026\u0026 isequal(s, t)} \u003e @assert\r\n\r\n%%\r\n{sum(sin(cos(magic(5).^2+1))), magic(5) \u003e @(x)x.^2+1 \u003e @cos \u003e @sin \u003e @sum} \u003e @isequal \u003e @assert\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":1434,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-07-05T05:22:01.000Z","updated_at":"2025-11-30T23:34:07.000Z","published_at":"2017-07-05T05:22:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDesign the\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\u003egt\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(\u0026gt;) method of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003efunction_handle\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e so that:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[\u003e\u003e 1 \u003e @sin \u003e @cos\\nans =\\n       0.666366745392881\\n\u003e\u003e cos(sin(1))\\nans =\\n       0.666366745392881\\n\u003e\u003e {1, 3, 3} \u003e @linspace\\nans =\\n   1     2     3\\n\u003e\u003e linspace(1, 3, 3)\\nans =\\n   1     2     3]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\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\u003egt.m\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e you submitted will be moved to the class folder\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\u003e@function_handle\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\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[mkdir @function_handle\\nmovefile submission/gt.m @function_handle]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSee Also:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/42817-pipeline\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42817. Pipeline\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":"group:\"Functions II\"","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":"group:\"Functions II\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Functions II\"","","\"","Functions II","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f74df4daca0\u003e":["Functions II"],"#\u003cMathWorks::Search::Field:0x00007f74df4daac0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f74df4d48a0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f74df4db060\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f74df4dae80\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f74df4dade0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f74df4dad40\u003e":"group:\"Functions II\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f74df4dad40\u003e":"group:\"Functions II\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007f74df4daca0\u003e":["Functions II"]}},"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":"group:\"Functions II\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Functions II\"","","\"","Functions II","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f74df4daca0\u003e":["Functions II"],"#\u003cMathWorks::Search::Field:0x00007f74df4daac0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f74df4d48a0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f74df4db060\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f74df4dae80\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f74df4dade0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f74df4dad40\u003e":"group:\"Functions II\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f74df4dad40\u003e":"group:\"Functions II\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007f74df4daca0\u003e":["Functions II"]}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":44245,"difficulty_rating":"easy"},{"id":2892,"difficulty_rating":"easy"},{"id":44259,"difficulty_rating":"easy-medium"},{"id":42848,"difficulty_rating":"easy-medium"},{"id":44083,"difficulty_rating":"easy-medium"},{"id":42793,"difficulty_rating":"easy-medium"},{"id":44324,"difficulty_rating":"easy-medium"},{"id":44704,"difficulty_rating":"easy-medium"},{"id":42795,"difficulty_rating":"medium"},{"id":44260,"difficulty_rating":"medium"},{"id":44262,"difficulty_rating":"medium"},{"id":42794,"difficulty_rating":"medium"},{"id":44263,"difficulty_rating":"medium-hard"},{"id":1891,"difficulty_rating":"medium-hard"},{"id":44788,"difficulty_rating":"hard"},{"id":44249,"difficulty_rating":"hard"}]}}