{"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":57635,"title":"Compute the average precipitation for a watershed using the Thiessen polygon method","description":"Several methods are available for estimating the average precipitation for a watershed from a few observations at rain gauges. The Thiessen polygon method involves forming polygons around the gauges, assigning the gauge’s observed precipitation to each point in the polygon, and computing the weighted average precipitation using the areas of the polygons as weights. \r\nThe polygons can be determined by connecting the gauges with lines, drawing the perpendicular bisectors of the connecting lines, and finding the intersections of the bisectors to form the polygons. An example is shown below. \r\nWrite a function that takes the precipitation amounts and the (, ) coordinates of the boundary and the gauges and compute the average precipitation for the watershed. ","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: 186px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 93px; transform-origin: 407px 93px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 84px; 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 42px; text-align: left; transform-origin: 384px 42px; 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: 366.425px 8px; transform-origin: 366.425px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSeveral methods are available for estimating the average precipitation for a watershed from a few observations at rain gauges. The Thiessen polygon method involves forming polygons around the gauges, assigning the gauge’s observed precipitation to each point in the polygon, and computing the weighted average precipitation using the areas of the polygons as weights. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe polygons can be determined by connecting the gauges with lines, drawing the perpendicular bisectors of the connecting lines, and finding the intersections of the bisectors to form the polygons. An example is shown below. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 190.458px 8px; transform-origin: 190.458px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes the precipitation amounts and the (\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003ex\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: 3.88333px 8px; transform-origin: 3.88333px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003ey\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: 156.767px 8px; transform-origin: 156.767px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e) coordinates of the boundary and the gauges and compute the average precipitation for the watershed. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function Pavg = spatial_average(xd,yd,P,xb,yb)\r\n%  (xd, yd) = coordinates of the precipitation gauges\r\n%  P = precipitation values\r\n%  (xb,yb) = coordinates of the boundary of the watershed\r\n\r\n   Pavg = integral(P*dx*dy)/integral(dx*dy);","test_suite":"%% Rectangular catchment with simple gauge placement and values\r\nxb = [0 5 5 0 0];    % km\r\nyb = [0 0 10 10 0];  % km\r\nxd = [-1 6 6 -1];\r\nyd = [-1 -1 11 11];\r\nP  = [20 20 40 40];  % cm\r\nPavg_correct = 30;   % cm\r\nPavg = spatial_average(xd,yd,P,xb,yb);\r\nassert(abs(Pavg-Pavg_correct)\u003c0.05);\r\n\r\n%% Example 3 from dreamcivil.com\r\nxb = [0 10 10 0 0]; % km\r\nyb = [0 0 5 5 0];   % km\r\nxd = xb(1:end-1);\r\nyd = yb(1:end-1);\r\nP  = [11 15 12 10]; % cm\r\nPavg_correct = 12;  % cm\r\nPavg = spatial_average(xd,yd,P,xb,yb);\r\nassert(abs(Pavg-Pavg_correct)\u003c0.01);\r\n\r\n%% Rectangular catchment with more complicated gauge locations \r\nxb = [0 10 10 0 0];\r\nyb = [0 0 30 30 0];\r\nxd = [-3 8  4 13  1 9];\r\nyd = [-2 2 12 21 25 33];\r\nP  = 132+3*(yd-33);\r\nPavg_correct = 77.65;\r\nPavg = spatial_average(xd,yd,P,xb,yb);\r\nassert(abs(Pavg-Pavg_correct)/Pavg_correct\u003c0.01)\r\n\r\n%% More complicated boundary\r\nxb = 10*[0.5497 0.4705 0.3840 0.3214 0.2937 0.2882 0.3379 0.4632 0.6271 0.7284 0.7947 0.8241 0.8039 0.8039 0.7689 0.7302 0.6452 0.5497];   % km\r\nyb = 10*[0.1857 0.2512 0.3867 0.5152 0.6717 0.7909 0.9007 0.9591 0.9498 0.8797 0.7605 0.6320 0.4708 0.4708 0.3914 0.2745 0.2194 0.1857];   % km\r\nxd = 10*[0.4 0.63 0.5 0.7 0.8];\r\nyd = 10*[0.9 0.6 0.35 0.8 0.32];\r\nP  = [113 166 140 183 125]; % mm\r\nPavg_correct = 148.271; % mm\r\nPavg = spatial_average(xd,yd,P,xb,yb);\r\nassert(abs(Pavg-Pavg_correct)\u003c0.01)\r\n\r\n%% Example 5.5 from Chin\r\nxb = [2.0084 2.4293 2.8156 3.0028 3.2368 3.4126 3.6713 3.8467 4.0235 4.2117 4.3540 4.5197 4.7338 4.9362 5.0688 5.2611 5.4307 5.5418 5.6399 5.7033 5.7094 5.6167 5.4566 5.3269 5.2170 5.1962 5.2033 5.2325 5.2838 5.3351 5.3630 5.3672 5.3594 5.2956 5.1854 5.0638 4.9172 4.7914 4.5239 4.2432 4.0206 3.9153 3.7154 3.4805 3.3047 3.1412 2.9657 2.6980 2.4305 2.1494 1.9034 1.6444 1.3955 1.1317 0.9849 0.8611 0.7998 0.7605 0.6858 0.5893 0.4919 0.3519 0.2515 0.1265 0.0875 0.0801 0.1796 0.3474 0.5154 0.6832 0.7618 0.8867 1.0592 1.2773 1.4249 1.5055 1.5835 1.5910 1.5914 1.6825 1.8099 1.9151 2.0084];\r\nyb = [6.4122 6.4364 6.4348 6.4401 6.4466 6.4391 6.3966 6.4015 6.3566 6.3246 6.2539 6.1839 6.0530 5.9218 5.7761 5.5824 5.3632 5.1423 4.9708 4.7859 4.5496 4.0617 3.4599 3.0456 2.7688 2.6686 2.3950 2.1719 1.9991 1.8263 1.6529 1.4912 1.3416 1.0910 0.8266 0.5494 0.3337 0.2182 0.1485 0.1406 0.1468 0.1439 0.1756 0.2064 0.2139 0.1969 0.1920 0.1347 0.0650 0.0695 0.0751 0.1301 0.2475 0.4890 0.7338 0.9917 1.5500 1.7106 1.8828 1.9921 2.1387 2.5703 2.8288 3.1364 3.2847 3.5707 3.7975 4.1008 4.3918 4.6951 4.8218 4.9746 5.0914 5.2593 5.4377 5.4897 5.6412 5.8032 6.2388 6.3409 6.3942 6.3972 6.4122];\r\nxd = [1.3 1.0 4.2 3.5 2.1];\r\nyd = [7.0 3.7 4.9 1.4 -1.0];\r\nP  = [60 90 65 35 20];\r\nPavg_correct = 59.301;\r\nPavg = spatial_average(xd,yd,P,xb,yb);\r\nassert(abs(Pavg-Pavg_correct)\u003c0.01)\r\n\r\n%% C E 372 problem 11\r\nxb = [33.6241 31.3609 26.3820 25.3635 24.0062 22.8754 21.4057 19.4844 18.2414 17.5648 15.1930 15.1935 15.5336 15.8735 15.8742 15.3089 13.6128 12.9347 12.0319 11.4673 10.2237 8.8694 8.0782 7.7400 7.4023 7.4049 7.7466 8.2004 9.6732 11.4838 14.6517 15.7834 16.4627 16.8027 16.8037 15.5614 14.0926 13.0759 12.3981 12.5118 14.5502 15.4557 16.7001 19.1891 22.2439 24.2812 26.3185 27.5654 27.9054 29.1500 30.9595 32.7690 34.5782 36.2742 38.0830 39.1005 40.6836 41.9275 46.9026 47.6937 49.5021 49.8399 49.8383 49.1574 48.2507 46.8905 45.1911 44.5108 44.0567 43.4877 43.0343 42.5763 42.4619 41.2167 39.1791 38.8389 38.8379 38.3850 37.2537 36.0095 35.5567 34.6511 35.2149 35.4394 35.5514 35.5496 35.3221 35.2082 33.7370]; % mi\r\nyb = [5.2159 3.9673 1.3564 0.6755 0.5609 0.7865 1.4650 2.9363 4.1815 6.2206 9.7311 10.2976 11.2045 11.7714 12.5646 12.7907 13.1290 13.6949 15.8471 16.7530 17.3184 20.3766 20.9425 22.0753 23.7747 26.6075 29.1008 30.5743 33.2952 34.3168 35.4529 36.1339 36.9277 37.6079 38.7411 40.6662 42.2512 43.4967 44.4026 44.9693 47.6908 48.4848 48.8259 49.6215 50.7575 52.3458 53.9342 56.8815 57.5617 58.1295 58.0179 57.9063 57.4547 56.8898 56.0983 55.6460 55.3075 55.0821 53.6137 53.0479 51.6898 50.1037 48.4040 46.0238 43.9832 40.8092 37.7481 35.9344 34.1209 30.4943 29.3608 23.4680 22.1081 20.9738 19.0455 18.1387 17.0055 16.5518 16.2108 16.0963 15.6427 14.8486 13.0361 11.2233 10.0903 8.1639 6.8039 5.8973 4.9894]; % mi\r\nxd = [15.9758 6.0340 4.0115 15.4546 38.1999 50.7358 40.6553 33.7370 31.4005 19.7352 28.4331]; % mi\r\nyd = [0.3267 12.1020 26.1511 47.3517 60.0644 40.6995 25.2792 4.9894 45.8937 28.9988 17.5623]; % mi\r\nP  = [29.79 34.97 25.60 24.27 24.60 42.61 42.35 15.51 39.99 43.04 28.41]; % in\r\nPavg_correct = 35.011;\r\nPavg = spatial_average(xd,yd,P,xb,yb);\r\nassert(abs(Pavg-Pavg_correct)\u003c0.01)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":3,"created_by":46909,"edited_by":46909,"edited_at":"2023-02-04T01:17:57.000Z","deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":"2023-02-04T01:17:57.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2023-02-01T17:01:04.000Z","updated_at":"2023-02-04T01:17:57.000Z","published_at":"2023-02-01T17:03:39.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSeveral methods are available for estimating the average precipitation for a watershed from a few observations at rain gauges. The Thiessen polygon method involves forming polygons around the gauges, assigning the gauge’s observed precipitation to each point in the polygon, and computing the weighted average precipitation using the areas of the polygons as weights. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe polygons can be determined by connecting the gauges with lines, drawing the perpendicular bisectors of the connecting lines, and finding the intersections of the bisectors to form the polygons. An example is shown below. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that takes the precipitation amounts and the (\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"x\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"y\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e) coordinates of the boundary and the gauges and compute the average precipitation for the watershed. \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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":57635,"title":"Compute the average precipitation for a watershed using the Thiessen polygon method","description":"Several methods are available for estimating the average precipitation for a watershed from a few observations at rain gauges. The Thiessen polygon method involves forming polygons around the gauges, assigning the gauge’s observed precipitation to each point in the polygon, and computing the weighted average precipitation using the areas of the polygons as weights. \r\nThe polygons can be determined by connecting the gauges with lines, drawing the perpendicular bisectors of the connecting lines, and finding the intersections of the bisectors to form the polygons. An example is shown below. \r\nWrite a function that takes the precipitation amounts and the (, ) coordinates of the boundary and the gauges and compute the average precipitation for the watershed. ","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: 186px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 93px; transform-origin: 407px 93px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 84px; 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 42px; text-align: left; transform-origin: 384px 42px; 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: 366.425px 8px; transform-origin: 366.425px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSeveral methods are available for estimating the average precipitation for a watershed from a few observations at rain gauges. The Thiessen polygon method involves forming polygons around the gauges, assigning the gauge’s observed precipitation to each point in the polygon, and computing the weighted average precipitation using the areas of the polygons as weights. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe polygons can be determined by connecting the gauges with lines, drawing the perpendicular bisectors of the connecting lines, and finding the intersections of the bisectors to form the polygons. An example is shown below. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 190.458px 8px; transform-origin: 190.458px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes the precipitation amounts and the (\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003ex\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: 3.88333px 8px; transform-origin: 3.88333px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003ey\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: 156.767px 8px; transform-origin: 156.767px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e) coordinates of the boundary and the gauges and compute the average precipitation for the watershed. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function Pavg = spatial_average(xd,yd,P,xb,yb)\r\n%  (xd, yd) = coordinates of the precipitation gauges\r\n%  P = precipitation values\r\n%  (xb,yb) = coordinates of the boundary of the watershed\r\n\r\n   Pavg = integral(P*dx*dy)/integral(dx*dy);","test_suite":"%% Rectangular catchment with simple gauge placement and values\r\nxb = [0 5 5 0 0];    % km\r\nyb = [0 0 10 10 0];  % km\r\nxd = [-1 6 6 -1];\r\nyd = [-1 -1 11 11];\r\nP  = [20 20 40 40];  % cm\r\nPavg_correct = 30;   % cm\r\nPavg = spatial_average(xd,yd,P,xb,yb);\r\nassert(abs(Pavg-Pavg_correct)\u003c0.05);\r\n\r\n%% Example 3 from dreamcivil.com\r\nxb = [0 10 10 0 0]; % km\r\nyb = [0 0 5 5 0];   % km\r\nxd = xb(1:end-1);\r\nyd = yb(1:end-1);\r\nP  = [11 15 12 10]; % cm\r\nPavg_correct = 12;  % cm\r\nPavg = spatial_average(xd,yd,P,xb,yb);\r\nassert(abs(Pavg-Pavg_correct)\u003c0.01);\r\n\r\n%% Rectangular catchment with more complicated gauge locations \r\nxb = [0 10 10 0 0];\r\nyb = [0 0 30 30 0];\r\nxd = [-3 8  4 13  1 9];\r\nyd = [-2 2 12 21 25 33];\r\nP  = 132+3*(yd-33);\r\nPavg_correct = 77.65;\r\nPavg = spatial_average(xd,yd,P,xb,yb);\r\nassert(abs(Pavg-Pavg_correct)/Pavg_correct\u003c0.01)\r\n\r\n%% More complicated boundary\r\nxb = 10*[0.5497 0.4705 0.3840 0.3214 0.2937 0.2882 0.3379 0.4632 0.6271 0.7284 0.7947 0.8241 0.8039 0.8039 0.7689 0.7302 0.6452 0.5497];   % km\r\nyb = 10*[0.1857 0.2512 0.3867 0.5152 0.6717 0.7909 0.9007 0.9591 0.9498 0.8797 0.7605 0.6320 0.4708 0.4708 0.3914 0.2745 0.2194 0.1857];   % km\r\nxd = 10*[0.4 0.63 0.5 0.7 0.8];\r\nyd = 10*[0.9 0.6 0.35 0.8 0.32];\r\nP  = [113 166 140 183 125]; % mm\r\nPavg_correct = 148.271; % mm\r\nPavg = spatial_average(xd,yd,P,xb,yb);\r\nassert(abs(Pavg-Pavg_correct)\u003c0.01)\r\n\r\n%% Example 5.5 from Chin\r\nxb = [2.0084 2.4293 2.8156 3.0028 3.2368 3.4126 3.6713 3.8467 4.0235 4.2117 4.3540 4.5197 4.7338 4.9362 5.0688 5.2611 5.4307 5.5418 5.6399 5.7033 5.7094 5.6167 5.4566 5.3269 5.2170 5.1962 5.2033 5.2325 5.2838 5.3351 5.3630 5.3672 5.3594 5.2956 5.1854 5.0638 4.9172 4.7914 4.5239 4.2432 4.0206 3.9153 3.7154 3.4805 3.3047 3.1412 2.9657 2.6980 2.4305 2.1494 1.9034 1.6444 1.3955 1.1317 0.9849 0.8611 0.7998 0.7605 0.6858 0.5893 0.4919 0.3519 0.2515 0.1265 0.0875 0.0801 0.1796 0.3474 0.5154 0.6832 0.7618 0.8867 1.0592 1.2773 1.4249 1.5055 1.5835 1.5910 1.5914 1.6825 1.8099 1.9151 2.0084];\r\nyb = [6.4122 6.4364 6.4348 6.4401 6.4466 6.4391 6.3966 6.4015 6.3566 6.3246 6.2539 6.1839 6.0530 5.9218 5.7761 5.5824 5.3632 5.1423 4.9708 4.7859 4.5496 4.0617 3.4599 3.0456 2.7688 2.6686 2.3950 2.1719 1.9991 1.8263 1.6529 1.4912 1.3416 1.0910 0.8266 0.5494 0.3337 0.2182 0.1485 0.1406 0.1468 0.1439 0.1756 0.2064 0.2139 0.1969 0.1920 0.1347 0.0650 0.0695 0.0751 0.1301 0.2475 0.4890 0.7338 0.9917 1.5500 1.7106 1.8828 1.9921 2.1387 2.5703 2.8288 3.1364 3.2847 3.5707 3.7975 4.1008 4.3918 4.6951 4.8218 4.9746 5.0914 5.2593 5.4377 5.4897 5.6412 5.8032 6.2388 6.3409 6.3942 6.3972 6.4122];\r\nxd = [1.3 1.0 4.2 3.5 2.1];\r\nyd = [7.0 3.7 4.9 1.4 -1.0];\r\nP  = [60 90 65 35 20];\r\nPavg_correct = 59.301;\r\nPavg = spatial_average(xd,yd,P,xb,yb);\r\nassert(abs(Pavg-Pavg_correct)\u003c0.01)\r\n\r\n%% C E 372 problem 11\r\nxb = [33.6241 31.3609 26.3820 25.3635 24.0062 22.8754 21.4057 19.4844 18.2414 17.5648 15.1930 15.1935 15.5336 15.8735 15.8742 15.3089 13.6128 12.9347 12.0319 11.4673 10.2237 8.8694 8.0782 7.7400 7.4023 7.4049 7.7466 8.2004 9.6732 11.4838 14.6517 15.7834 16.4627 16.8027 16.8037 15.5614 14.0926 13.0759 12.3981 12.5118 14.5502 15.4557 16.7001 19.1891 22.2439 24.2812 26.3185 27.5654 27.9054 29.1500 30.9595 32.7690 34.5782 36.2742 38.0830 39.1005 40.6836 41.9275 46.9026 47.6937 49.5021 49.8399 49.8383 49.1574 48.2507 46.8905 45.1911 44.5108 44.0567 43.4877 43.0343 42.5763 42.4619 41.2167 39.1791 38.8389 38.8379 38.3850 37.2537 36.0095 35.5567 34.6511 35.2149 35.4394 35.5514 35.5496 35.3221 35.2082 33.7370]; % mi\r\nyb = [5.2159 3.9673 1.3564 0.6755 0.5609 0.7865 1.4650 2.9363 4.1815 6.2206 9.7311 10.2976 11.2045 11.7714 12.5646 12.7907 13.1290 13.6949 15.8471 16.7530 17.3184 20.3766 20.9425 22.0753 23.7747 26.6075 29.1008 30.5743 33.2952 34.3168 35.4529 36.1339 36.9277 37.6079 38.7411 40.6662 42.2512 43.4967 44.4026 44.9693 47.6908 48.4848 48.8259 49.6215 50.7575 52.3458 53.9342 56.8815 57.5617 58.1295 58.0179 57.9063 57.4547 56.8898 56.0983 55.6460 55.3075 55.0821 53.6137 53.0479 51.6898 50.1037 48.4040 46.0238 43.9832 40.8092 37.7481 35.9344 34.1209 30.4943 29.3608 23.4680 22.1081 20.9738 19.0455 18.1387 17.0055 16.5518 16.2108 16.0963 15.6427 14.8486 13.0361 11.2233 10.0903 8.1639 6.8039 5.8973 4.9894]; % mi\r\nxd = [15.9758 6.0340 4.0115 15.4546 38.1999 50.7358 40.6553 33.7370 31.4005 19.7352 28.4331]; % mi\r\nyd = [0.3267 12.1020 26.1511 47.3517 60.0644 40.6995 25.2792 4.9894 45.8937 28.9988 17.5623]; % mi\r\nP  = [29.79 34.97 25.60 24.27 24.60 42.61 42.35 15.51 39.99 43.04 28.41]; % in\r\nPavg_correct = 35.011;\r\nPavg = spatial_average(xd,yd,P,xb,yb);\r\nassert(abs(Pavg-Pavg_correct)\u003c0.01)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":3,"created_by":46909,"edited_by":46909,"edited_at":"2023-02-04T01:17:57.000Z","deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":"2023-02-04T01:17:57.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2023-02-01T17:01:04.000Z","updated_at":"2023-02-04T01:17:57.000Z","published_at":"2023-02-01T17:03:39.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSeveral methods are available for estimating the average precipitation for a watershed from a few observations at rain gauges. The Thiessen polygon method involves forming polygons around the gauges, assigning the gauge’s observed precipitation to each point in the polygon, and computing the weighted average precipitation using the areas of the polygons as weights. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe polygons can be determined by connecting the gauges with lines, drawing the perpendicular bisectors of the connecting lines, and finding the intersections of the bisectors to form the polygons. An example is shown below. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that takes the precipitation amounts and the (\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"x\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"y\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e) coordinates of the boundary and the gauges and compute the average precipitation for the watershed. \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\"}]}"}],"term":"tag:\"nearest neighbor\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"nearest neighbor\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"nearest neighbor\"","","\"","nearest neighbor","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f45e654f500\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f45e654f460\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f45e654eba0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f45e654f780\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f45e654f6e0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f45e654f640\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f45e654f5a0\u003e":"tag:\"nearest neighbor\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f45e654f5a0\u003e":"tag:\"nearest neighbor\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"nearest neighbor\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"nearest neighbor\"","","\"","nearest neighbor","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f45e654f500\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f45e654f460\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f45e654eba0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f45e654f780\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f45e654f6e0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f45e654f640\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f45e654f5a0\u003e":"tag:\"nearest neighbor\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f45e654f5a0\u003e":"tag:\"nearest neighbor\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":57635,"difficulty_rating":"medium-hard"}]}}