{"id":203373,"date":"2024-05-10T04:09:07","date_gmt":"2024-05-09T20:09:07","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/203373.html"},"modified":"2024-05-10T04:09:10","modified_gmt":"2024-05-09T20:09:10","slug":"matlab-%e8%92%99%e7%89%b9%e5%8d%a1%e6%b4%9b%e6%b3%95%e8%ae%a1%e7%ae%97%e5%9c%86%e5%91%a8%e7%8e%87%e6%80%8e%e4%b9%88%e5%86%99%e6%9c%80%e5%bf%ab","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/203373.html","title":{"rendered":"Matlab \u8499\u7279\u5361\u6d1b\u6cd5\u8ba1\u7b97\u5706\u5468\u7387\u600e\u4e48\u5199\u6700\u5feb"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24142401\/bf3866e3-915c-4efd-9efc-5726cd3f5c96.webp\" alt=\"Matlab \u8499\u7279\u5361\u6d1b\u6cd5\u8ba1\u7b97\u5706\u5468\u7387\u600e\u4e48\u5199\u6700\u5feb\" \/><\/p>\n<p><p>\u5229\u7528MATLAB\u5b9e\u73b0\u8499\u7279\u5361\u7f57\u6cd5\u8ba1\u7b97\u5706\u5468\u7387\u7684\u6700\u5feb\u65b9\u6cd5\u4e3b\u8981\u4f9d\u8d56\u4e8e<strong>\u751f\u6210\u5927\u91cf\u968f\u673a\u70b9\u3001\u5224\u65ad\u8fd9\u4e9b\u70b9\u662f\u5426\u843d\u5728\u5355\u4f4d\u5706\u5185<\/strong>\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u8be5\u65b9\u6cd5\u4f9d\u6258MATLAB\u5f3a\u5927\u7684\u77e9\u9635\u64cd\u4f5c\u548c\u5411\u91cf\u5316\u8ba1\u7b97\u7279\u6027\u6765\u63d0\u9ad8\u8ba1\u7b97\u7684\u6548\u7387\u3002<strong>\u5411\u91cf\u5316\u8ba1\u7b97<\/strong>\u662f\u6211\u4eec\u5c55\u5f00\u63cf\u8ff0\u7684\u91cd\u70b9\u3002\u901a\u8fc7\u5c06\u4f20\u7edf\u7684\u5faa\u73af\u8ba1\u6570\u6539\u4e3a\u77e9\u9635\u8fd0\u7b97\uff0c\u53ef\u4ee5\u663e\u8457\u51cf\u5c11\u8ba1\u7b97\u65f6\u95f4\uff0c\u8fd9\u662f\u56e0\u4e3aMATLAB\u5728\u5bf9\u77e9\u9635\u548c\u6570\u7ec4\u64cd\u4f5c\u65b9\u9762\u8fdb\u884c\u4e86\u4f18\u5316\uff0c\u4f7f\u5f97\u540c\u6837\u7684\u8ba1\u7b97\u4efb\u52a1\uff0c\u4f7f\u7528\u5411\u91cf\u5316\u65b9\u6cd5\u8981\u6bd4\u5faa\u73af\u5feb\u5f97\u591a\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u7406\u89e3\u8499\u7279\u5361\u6d1b\u6cd5<\/h3>\n<\/p>\n<p><p>\u8499\u7279\u5361\u7f57\u6cd5\u662f\u4e00\u79cd\u57fa\u4e8e\u968f\u673a\u6570\u7684\u8ba1\u7b97\u65b9\u6cd5\uff0c\u7528\u4e8e\u8fd1\u4f3c\u89e3\u51b3\u5404\u79cd\u6570\u5b66\u95ee\u9898\u3002\u5728\u8ba1\u7b97\u5706\u5468\u7387\u7684\u573a\u666f\u4e0b\uff0c\u8be5\u65b9\u6cd5\u901a\u8fc7\u968f\u673a\u751f\u6210\u70b9\u5e76\u5224\u65ad\u8fd9\u4e9b\u70b9\u662f\u5426\u4f4d\u4e8e\u5355\u4f4d\u5706\u5185\u6765\u8fd1\u4f3c\u8ba1\u7b97\u5706\u7684\u9762\u79ef\uff0c\u4ece\u800c\u5f97\u5230\u5706\u5468\u7387\u7684\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u521d\u59cb\u5316\u968f\u673a\u70b9<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u751f\u6210\u5927\u91cf\u968f\u673a\u70b9\uff0c\u5e76\u4e14\u8fd9\u4e9b\u70b9\u5e94\u8be5\u5747\u5300\u5206\u5e03\u5728\u5305\u542b\u5355\u4f4d\u5706\u7684\u6b63\u65b9\u5f62\u5185\u3002MATLAB\u4e2d\u53ef\u4ee5\u4f7f\u7528<code>rand<\/code>\u51fd\u6570\u6765\u521b\u5efa\u8fd9\u4e9b\u968f\u673a\u70b9\uff0c\u63d0\u9ad8\u4efb\u52a1\u7684\u6267\u884c\u6548\u7387\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-matlab\">N = 1e6; % \u968f\u673a\u70b9\u7684\u6570\u91cf<\/p>\n<p>x = rand(N, 1); % \u751f\u6210x\u5750\u6807<\/p>\n<p>y = rand(N, 1); % \u751f\u6210y\u5750\u6807<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u5224\u65ad\u70b9\u662f\u5426\u5728\u5706\u5185<\/h3>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6839\u636e\u5706\u7684\u65b9\u7a0b\u5f0f(x^2 + y^2 = r^2)\u6765\u5224\u65ad\u8fd9\u4e9b\u968f\u673a\u70b9\u662f\u5426\u4f4d\u4e8e\u5355\u4f4d\u5706\u5185\u90e8\uff08\u6b64\u5904(r=1)\uff09\u3002\u901a\u8fc7\u5411\u91cf\u5316\u7684\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u540c\u65f6\u8ba1\u7b97\u6240\u6709\u70b9\u7684\u4f4d\u7f6e\uff0c\u800c\u4e0d\u662f\u4e00\u6b21\u8ba1\u7b97\u4e00\u4e2a\u70b9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-matlab\">r = sqrt(x.^2 + y.^2); % \u8ba1\u7b97\u70b9\u5230\u539f\u70b9\u7684\u8ddd\u79bb<\/p>\n<p>insideCircle = r &lt;= 1; % \u5224\u65ad\u662f\u5426\u5728\u5706\u5185<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u8ba1\u7b97\u5706\u5468\u7387<\/h3>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u5229\u7528\u5355\u4f4d\u5706\u5185\u70b9\u7684\u6bd4\u4f8b\u548c\u6b63\u65b9\u5f62\u7684\u9762\u79ef\u5173\u7cfb\u6765<a href=\"https:\/\/docs.pingcode.com\/agile\/project-management\/estimation\" target=\"_blank\">\u4f30\u7b97<\/a>\u5706\u5468\u7387\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5355\u4f4d\u5706\u7684\u9762\u79ef\u4e3a(\\pi*r^2)\uff0c\u800c\u5305\u542b\u5355\u4f4d\u5706\u7684\u6b63\u65b9\u5f62\u9762\u79ef\u4e3a(4r^2)\u3002\u56e0\u6b64\uff0c\u843d\u5728\u5355\u4f4d\u5706\u5185\u90e8\u7684\u70b9\u6570\u5360\u603b\u70b9\u6570\u7684\u6bd4\u4f8b\u5e94\u8be5\u63a5\u8fd1\u4e8e(\\pi\/4)\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-matlab\">piEstimate = 4 * sum(insideCircle) \/ N; % \u4f30\u8ba1\u5706\u5468\u7387<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u975e\u5e38\u5feb\u901f\u4e14\u6709\u6548\u5730\u4f7f\u7528MATLAB\u548c\u8499\u7279\u5361\u6d1b\u6cd5\u6765\u8ba1\u7b97\u5706\u5468\u7387\u3002<strong>\u5411\u91cf\u5316\u8ba1\u7b97<\/strong>\u663e\u8457\u63d0\u9ad8\u4e86\u6548\u7387\uff0c\u662fMATLAB\u5904\u7406\u6b64\u7c7b\u95ee\u9898\u7684\u5173\u952e\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387<\/h3>\n<\/p>\n<p><p>\u5c3d\u7ba1\u8499\u7279\u5361\u6d1b\u6cd5\u7684\u57fa\u672c\u6b65\u9aa4\u76f8\u5bf9\u7b80\u5355\uff0c\u4f46\u8ba1\u7b97\u6548\u7387\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u53d6\u51b3\u4e8e\u751f\u6210\u968f\u673a\u70b9\u7684\u6570\u91cf\u548cMATLAB\u4ee3\u7801\u7684\u4f18\u5316\u7a0b\u5ea6\u3002\u4e3a\u4e86\u5b9e\u73b0\u6700\u5feb\u7684\u8ba1\u7b97\u8fc7\u7a0b\uff0c\u8003\u8651\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u589e\u52a0\u968f\u673a\u70b9\u7684\u6570\u91cf<\/strong>\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5706\u5468\u7387\u7684\u8ba1\u7b97\u7cbe\u5ea6\uff0c\u4f46\u540c\u65f6\u4e5f\u589e\u52a0\u4e86\u8ba1\u7b97\u91cf\u3002\u9700\u8981\u5728\u8ba1\u7b97\u65f6\u95f4\u548c\u7cbe\u5ea6\u4e4b\u95f4\u627e\u5230\u5e73\u8861\u70b9\u3002<\/li>\n<li>\u5229\u7528<strong>\u5e76\u884c\u8ba1\u7b97<\/strong>\u3002MATLAB\u63d0\u4f9b\u4e86\u5e76\u884c\u8ba1\u7b97\u5de5\u5177\u7bb1\uff0c\u5141\u8bb8\u5728\u591a\u4e2aCPU\u6838\u5fc3\u4e0a\u5e76\u884c\u6267\u884c\u4ee3\u7801\uff0c\u8fd9\u80fd\u8fdb\u4e00\u6b65\u52a0\u5feb\u8ba1\u7b97\u8fc7\u7a0b\u3002<\/li>\n<li><strong>\u4ee3\u7801\u77e2\u91cf\u5316<\/strong>\u3002\u5c3d\u91cf\u907f\u514d\u4f7f\u7528\u5faa\u73af\uff0c\u8f6c\u800c\u4f7f\u7528\u77e2\u91cf\u548c\u77e9\u9635\u8fd0\u7b97\uff0c\u8fd9\u662f\u63d0\u9ad8MATLAB\u4ee3\u7801\u6267\u884c\u901f\u5ea6\u7684\u5173\u952e\u3002<\/li>\n<\/ul>\n<p><h3>\u516d\u3001\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u8499\u7279\u5361\u6d1b\u6cd5\u662f\u4e00\u79cd\u7b80\u4fbf\u6709\u6548\u7684\u6570\u503c\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u4f17\u591a\u590d\u6742\u95ee\u9898\u7684\u8fd1\u4f3c\u89e3\u3002\u5728\u4f7f\u7528MATLAB\u5b9e\u73b0\u8ba1\u7b97\u5706\u5468\u7387\u7684\u4efb\u52a1\u4e2d\uff0c\u901a\u8fc7\u4f18\u5316\u6570\u636e\u5904\u7406\u6d41\u7a0b\u548c\u5229\u7528MATLAB\u7684\u5411\u91cf\u5316\u8ba1\u7b97\u80fd\u529b\uff0c\u53ef\u4ee5\u5b9e\u73b0\u9ad8\u6548\u7684\u8ba1\u7b97\u3002\u5c3d\u7ba1\u8fd9\u79cd\u65b9\u6cd5\u7684\u7cbe\u5ea6\u53d7\u5230\u968f\u673a\u70b9\u6570\u91cf\u7684\u9650\u5236\uff0c\u4f46\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u65e2\u7b80\u5355\u53c8\u5f3a\u5927\u7684\u9014\u5f84\uff0c\u7528\u4e8e\u5904\u7406\u90a3\u4e9b\u96be\u4ee5\u76f4\u63a5\u6c42\u89e3\u7684\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u5982\u4f55\u5728Matlab\u4e2d\u4f7f\u7528\u8499\u7279\u5361\u6d1b\u6cd5\u5feb\u901f\u8ba1\u7b97\u5706\u5468\u7387\uff1f<\/strong><\/p>\n<p>\u8499\u7279\u5361\u6d1b\u6cd5\u662f\u4e00\u79cd\u57fa\u4e8e\u968f\u673a\u62bd\u6837\u7684\u6570\u503c\u8ba1\u7b97\u65b9\u6cd5\uff0c\u53ef\u4ee5\u7528\u6765\u4f30\u7b97\u5706\u5468\u7387\u3002\u5728Matlab\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u6765\u5feb\u901f\u8ba1\u7b97\u5706\u5468\u7387\uff1a<\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u6b63\u65b9\u5f62\u533a\u57df\uff0c\u5e76\u5c06\u5176\u8fb9\u957f\u8bbe\u7f6e\u4e3a2\u3002<\/li>\n<li>\u751f\u6210\u5927\u91cf\u7684\u968f\u673a\u70b9\uff0c\u843d\u5728\u6b63\u65b9\u5f62\u533a\u57df\u5185\u90e8\u3002<\/li>\n<li>\u7edf\u8ba1\u843d\u5728\u6b63\u65b9\u5f62\u533a\u57df\u5185\u7684\u70b9\u4e2d\u6709\u591a\u5c11\u4e2a\u4f4d\u4e8e\u4e00\u4e2a\u534a\u5f84\u4e3a1\u7684\u5706\u5f62\u533a\u57df\u5185\u90e8\u3002<\/li>\n<li>\u8ba1\u7b97\u843d\u5728\u5706\u5f62\u533a\u57df\u5185\u7684\u70b9\u5360\u603b\u70b9\u6570\u7684\u6bd4\u4f8b\uff0c\u7136\u540e\u4e58\u4ee54\uff0c\u5373\u53ef\u5f97\u5230\u8fd1\u4f3c\u7684\u5706\u5468\u7387\u3002<\/li>\n<\/ul>\n<p><strong>2. \u5728Matlab\u4e2d\u4f7f\u7528\u8499\u7279\u5361\u6d1b\u6cd5\u8ba1\u7b97\u5706\u5468\u7387\u7684\u901f\u5ea6\u5982\u4f55\u4f18\u5316\uff1f<\/strong><\/p>\n<p>\u8981\u5728Matlab\u4e2d\u4f7f\u7528\u8499\u7279\u5361\u6d1b\u6cd5\u5feb\u901f\u8ba1\u7b97\u5706\u5468\u7387\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u4f18\u5316\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528\u5411\u91cf\u5316\u7684\u4ee3\u7801\u6765\u751f\u6210\u968f\u673a\u70b9\uff0c\u4ee5\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u3002<\/li>\n<li>\u589e\u52a0\u62bd\u6837\u70b9\u7684\u6570\u91cf\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4f30\u8ba1\u7ed3\u679c\u7684\u7cbe\u5ea6\uff0c\u4f46\u4e5f\u4f1a\u589e\u52a0\u8ba1\u7b97\u65f6\u95f4\u3002<\/li>\n<li>\u4f7f\u7528\u5e76\u884c\u8ba1\u7b97\u6280\u672f\uff0c\u5982\u4f7f\u7528parfor\u5faa\u73af\u6216\u4f7f\u7528Matlab\u7684\u5e76\u884c\u8ba1\u7b97\u5de5\u5177\u7bb1\uff0c\u4ee5\u52a0\u5feb\u8ba1\u7b97\u901f\u5ea6\u3002<\/li>\n<li>\u5c06\u8ba1\u7b97\u4efb\u52a1\u5206\u89e3\u4e3a\u591a\u4e2a\u5b50\u4efb\u52a1\uff0c\u5229\u7528\u591a\u6838\u5904\u7406\u5668\u6765\u5e76\u884c\u8ba1\u7b97\uff0c\u4ee5\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u3002<\/li>\n<\/ul>\n<p><strong>3. Matlab\u4e2d\u5176\u4ed6\u8ba1\u7b97\u5706\u5468\u7387\u7684\u65b9\u6cd5\u6709\u54ea\u4e9b\uff1f<\/strong><\/p>\n<p>\u9664\u4e86\u8499\u7279\u5361\u6d1b\u6cd5\u5916\uff0cMatlab\u8fd8\u63d0\u4f9b\u4e86\u5176\u4ed6\u8ba1\u7b97\u5706\u5468\u7387\u7684\u65b9\u6cd5\u3002\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u5229\u7528\u5706\u7684\u9762\u79ef\u516c\u5f0f\u6765\u8ba1\u7b97\u5706\u5468\u7387\uff0c\u5373 pi = \u5706\u9762\u79ef \/ \u534a\u5f84^2\u3002\u53ef\u4ee5\u901a\u8fc7\u8ba1\u7b97\u6b63\u591a\u8fb9\u5f62\u7684\u9762\u79ef\u6765\u903c\u8fd1\u5706\u7684\u9762\u79ef\uff0c\u4ece\u800c\u5f97\u5230\u5706\u5468\u7387\u7684\u4f30\u8ba1\u503c\u3002<\/li>\n<li>\u4f7f\u7528\u725b\u987f\u6cd5\u6216\u4e8c\u5206\u6cd5\u7b49\u6570\u503c\u6c42\u6839\u65b9\u6cd5\uff0c\u6c42\u89e3\u5706\u7684\u65b9\u7a0b x^2 + y^2 = r^2 \u7684\u6839\uff0c\u5e76\u4ece\u4e2d\u5f97\u5230\u5706\u5468\u7387\u7684\u4f30\u8ba1\u503c\u3002<\/li>\n<li>\u5229\u7528\u7ea7\u6570\u5c55\u5f00\u516c\u5f0f\u5982\u83b1\u5e03\u5c3c\u8328\u7ea7\u6570\u6216\u9a6c\u9752\u5e38\u6570\u7b49\uff0c\u5c06\u5706\u5468\u7387\u8868\u8fbe\u4e3a\u65e0\u7a77\u7ea7\u6570\u7684\u5f62\u5f0f\u6765\u8ba1\u7b97\u3002\u53ef\u4ee5\u901a\u8fc7\u9010\u6b65\u589e\u52a0\u7ea7\u6570\u9879\u7684\u6570\u91cf\uff0c\u6765\u903c\u8fd1\u5706\u5468\u7387\u7684\u51c6\u786e\u503c\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u5229\u7528MATLAB\u5b9e\u73b0\u8499\u7279\u5361\u7f57\u6cd5\u8ba1\u7b97\u5706\u5468\u7387\u7684\u6700\u5feb\u65b9\u6cd5\u4e3b\u8981\u4f9d\u8d56\u4e8e\u751f\u6210\u5927\u91cf\u968f\u673a\u70b9\u3001\u5224\u65ad\u8fd9\u4e9b\u70b9\u662f\u5426\u843d\u5728\u5355\u4f4d\u5706\u5185\u3002\u5177\u4f53\u6765 [&hellip;]","protected":false},"author":3,"featured_media":203377,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/203373"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=203373"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/203373\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/203377"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=203373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=203373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=203373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}