{"id":1087688,"date":"2025-01-08T13:37:28","date_gmt":"2025-01-08T05:37:28","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1087688.html"},"modified":"2025-01-08T13:37:30","modified_gmt":"2025-01-08T05:37:30","slug":"python%e5%a6%82%e4%bd%95%e4%b8%89%e8%a7%92%e5%87%bd%e6%95%b0%e6%b1%82%e8%a7%a3-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1087688.html","title":{"rendered":"python\u5982\u4f55\u4e09\u89d2\u51fd\u6570\u6c42\u89e3"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24200456\/3b627733-375c-47d5-991f-40be11125b2a.webp\" alt=\"python\u5982\u4f55\u4e09\u89d2\u51fd\u6570\u6c42\u89e3\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6\u5e93\u4e2d\u7684math\u6a21\u5757\u6765\u8ba1\u7b97\u4e09\u89d2\u51fd\u6570\u3002\u4e3b\u8981\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528math.sin()\u3001math.cos()\u548cmath.tan()\u6765\u8ba1\u7b97\u6b63\u5f26\u3001\u4f59\u5f26\u548c\u6b63\u5207\u51fd\u6570\u3002<\/strong><\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528math\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u3001\u7406\u89e3\u89d2\u5ea6\u4e0e\u5f27\u5ea6\u8f6c\u6362\u3001\u5904\u7406\u5f02\u5e38\u60c5\u51b5\u3001\u4f18\u5316\u8ba1\u7b97\u6027\u80fd\u3002<\/strong><\/p>\n<\/p>\n<p><p>Python\u7684math\u6a21\u5757\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u5b66\u51fd\u6570\uff0c\u5305\u62ec\u4e09\u89d2\u51fd\u6570\u3002\u901a\u8fc7math\u6a21\u5757\u4e2d\u7684sin()\u3001cos()\u548ctan()\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u8ba1\u7b97\u7ed9\u5b9a\u89d2\u5ea6\u7684\u6b63\u5f26\u3001\u4f59\u5f26\u548c\u6b63\u5207\u503c\u3002\u8fd9\u4e9b\u51fd\u6570\u7684\u8f93\u5165\u662f\u5f27\u5ea6\uff0c\u56e0\u6b64\u5728\u4f7f\u7528\u4e4b\u524d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6\u3002\u53ef\u4ee5\u4f7f\u7528math.radians()\u51fd\u6570\u6765\u5b8c\u6210\u8fd9\u4e2a\u8f6c\u6362\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\uff0c\u4ee5\u53ca\u5728\u5b9e\u9645\u7f16\u7a0b\u4e2d\u53ef\u80fd\u9047\u5230\u7684\u4e00\u4e9b\u95ee\u9898\u548c\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528math\u6a21\u5757\u4e2d\u7684\u4e09\u89d2\u51fd\u6570<\/h3>\n<\/p>\n<p><p>Python\u7684math\u6a21\u5757\u63d0\u4f9b\u4e86\u7528\u4e8e\u8ba1\u7b97\u4e09\u89d2\u51fd\u6570\u7684\u57fa\u672c\u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u4e09\u89d2\u51fd\u6570\u53ca\u5176\u4f7f\u7528\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u8ba1\u7b97\u6b63\u5f26\u503c<\/h4>\n<\/p>\n<p><p>\u6b63\u5f26\u51fd\u6570sin(x)\u8fd4\u56de\u89d2\u5ea6x\u7684\u6b63\u5f26\u503c\u3002x\u7684\u5355\u4f4d\u662f\u5f27\u5ea6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>angle_in_degrees = 30<\/p>\n<p>angle_in_radians = math.radians(angle_in_degrees)<\/p>\n<p>sin_value = math.sin(angle_in_radians)<\/p>\n<p>print(f&quot;The sine of {angle_in_degrees} degrees is {sin_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5c06\u89d2\u5ea6\u4ece\u5ea6\u6570\u8f6c\u6362\u4e3a\u5f27\u5ea6\uff0c\u7136\u540e\u4f7f\u7528math.sin()\u51fd\u6570\u8ba1\u7b97\u5176\u6b63\u5f26\u503c\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u8ba1\u7b97\u4f59\u5f26\u503c<\/h4>\n<\/p>\n<p><p>\u4f59\u5f26\u51fd\u6570cos(x)\u8fd4\u56de\u89d2\u5ea6x\u7684\u4f59\u5f26\u503c\u3002x\u7684\u5355\u4f4d\u662f\u5f27\u5ea6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>angle_in_degrees = 45<\/p>\n<p>angle_in_radians = math.radians(angle_in_degrees)<\/p>\n<p>cos_value = math.cos(angle_in_radians)<\/p>\n<p>print(f&quot;The cosine of {angle_in_degrees} degrees is {cos_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u91cc\u540c\u6837\u5148\u5c06\u89d2\u5ea6\u4ece\u5ea6\u6570\u8f6c\u6362\u4e3a\u5f27\u5ea6\uff0c\u518d\u4f7f\u7528math.cos()\u51fd\u6570\u8ba1\u7b97\u5176\u4f59\u5f26\u503c\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u8ba1\u7b97\u6b63\u5207\u503c<\/h4>\n<\/p>\n<p><p>\u6b63\u5207\u51fd\u6570tan(x)\u8fd4\u56de\u89d2\u5ea6x\u7684\u6b63\u5207\u503c\u3002x\u7684\u5355\u4f4d\u662f\u5f27\u5ea6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>angle_in_degrees = 60<\/p>\n<p>angle_in_radians = math.radians(angle_in_degrees)<\/p>\n<p>tan_value = math.tan(angle_in_radians)<\/p>\n<p>print(f&quot;The tangent of {angle_in_degrees} degrees is {tan_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u540c\u6837\uff0c\u5148\u5c06\u89d2\u5ea6\u4ece\u5ea6\u6570\u8f6c\u6362\u4e3a\u5f27\u5ea6\uff0c\u7136\u540e\u4f7f\u7528math.tan()\u51fd\u6570\u8ba1\u7b97\u5176\u6b63\u5207\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u7406\u89e3\u89d2\u5ea6\u4e0e\u5f27\u5ea6\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528\u4e09\u89d2\u51fd\u6570\u65f6\uff0c\u89d2\u5ea6\u4e0e\u5f27\u5ea6\u7684\u8f6c\u6362\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002Python\u7684math\u6a21\u5757\u63d0\u4f9b\u4e86\u4e24\u4e2a\u51fd\u6570\u6765\u5e2e\u52a9\u5b8c\u6210\u8fd9\u4e9b\u8f6c\u6362\uff1amath.radians()\u548cmath.degrees()\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528math.radians()\u51fd\u6570\u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>angle_in_degrees = 90<\/p>\n<p>angle_in_radians = math.radians(angle_in_degrees)<\/p>\n<p>print(f&quot;{angle_in_degrees} degrees is {angle_in_radians} radians&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5f27\u5ea6\u8f6c\u6362\u4e3a\u89d2\u5ea6<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528math.degrees()\u51fd\u6570\u5c06\u5f27\u5ea6\u8f6c\u6362\u4e3a\u89d2\u5ea6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>angle_in_radians = math.pi \/ 2<\/p>\n<p>angle_in_degrees = math.degrees(angle_in_radians)<\/p>\n<p>print(f&quot;{angle_in_radians} radians is {angle_in_degrees} degrees&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u5904\u7406\u5f02\u5e38\u60c5\u51b5<\/h3>\n<\/p>\n<p><p>\u5728\u8ba1\u7b97\u4e09\u89d2\u51fd\u6570\u65f6\uff0c\u6709\u65f6\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5f02\u5e38\u60c5\u51b5\uff0c\u4f8b\u5982\u8f93\u5165\u503c\u8d85\u51fa\u51fd\u6570\u7684\u5b9a\u4e49\u57df\u3002\u6211\u4eec\u9700\u8981\u5bf9\u8fd9\u4e9b\u60c5\u51b5\u8fdb\u884c\u5904\u7406\uff0c\u4ee5\u786e\u4fdd\u7a0b\u5e8f\u7684\u5065\u58ee\u6027\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5904\u7406\u6570\u5b66\u57df\u9519\u8bef<\/h4>\n<\/p>\n<p><p>\u5f53\u8f93\u5165\u503c\u8d85\u51fa\u51fd\u6570\u7684\u5b9a\u4e49\u57df\u65f6\uff0cmath\u6a21\u5757\u53ef\u80fd\u4f1a\u5f15\u53d1ValueError\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528try-except\u8bed\u53e5\u6765\u6355\u83b7\u5e76\u5904\u7406\u5f02\u5e38\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>try:<\/p>\n<p>    angle_in_degrees = 90<\/p>\n<p>    angle_in_radians = math.radians(angle_in_degrees)<\/p>\n<p>    tan_value = math.tan(angle_in_radians)<\/p>\n<p>    print(f&quot;The tangent of {angle_in_degrees} degrees is {tan_value}&quot;)<\/p>\n<p>except ValueError as e:<\/p>\n<p>    print(f&quot;Error: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5904\u7406\u96f6\u503c\u5f02\u5e38<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u6b63\u5207\u51fd\u6570\uff0c\u5f53\u89d2\u5ea6\u4e3a90\u5ea6\u6216270\u5ea6\u65f6\uff0c\u6b63\u5207\u503c\u4f1a\u8d8b\u5411\u4e8e\u65e0\u7a77\u5927\u3002\u6211\u4eec\u9700\u8981\u5904\u7406\u8fd9\u4e9b\u7279\u6b8a\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>angle_in_degrees = 90<\/p>\n<p>angle_in_radians = math.radians(angle_in_degrees)<\/p>\n<p>if angle_in_degrees % 180 == 90:<\/p>\n<p>    print(f&quot;The tangent of {angle_in_degrees} degrees is undefined&quot;)<\/p>\n<p>else:<\/p>\n<p>    tan_value = math.tan(angle_in_radians)<\/p>\n<p>    print(f&quot;The tangent of {angle_in_degrees} degrees is {tan_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u4f18\u5316\u8ba1\u7b97\u6027\u80fd<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u5e94\u7528\u4e2d\uff0c\u4f8b\u5982\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u548c\u7269\u7406\u4eff\u771f\u4e2d\uff0c\u8ba1\u7b97\u4e09\u89d2\u51fd\u6570\u7684\u6027\u80fd\u53ef\u80fd\u975e\u5e38\u91cd\u8981\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f18\u5316\u8ba1\u7b97\u6027\u80fd\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528numpy\u5e93<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u9700\u8981\u8fdb\u884c\u5927\u91cf\u4e09\u89d2\u51fd\u6570\u8ba1\u7b97\u7684\u5e94\u7528\uff0c\u4f7f\u7528numpy\u5e93\u53ef\u4ee5\u63d0\u9ad8\u8ba1\u7b97\u6027\u80fd\u3002numpy\u5e93\u63d0\u4f9b\u4e86\u77e2\u91cf\u5316\u7684\u6570\u5b66\u51fd\u6570\uff0c\u53ef\u4ee5\u5bf9\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u8fdb\u884c\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>angles_in_degrees = np.array([0, 30, 45, 60, 90])<\/p>\n<p>angles_in_radians = np.radians(angles_in_degrees)<\/p>\n<p>sin_values = np.sin(angles_in_radians)<\/p>\n<p>cos_values = np.cos(angles_in_radians)<\/p>\n<p>tan_values = np.tan(angles_in_radians)<\/p>\n<p>print(f&quot;Sine values: {sin_values}&quot;)<\/p>\n<p>print(f&quot;Cosine values: {cos_values}&quot;)<\/p>\n<p>print(f&quot;Tangent values: {tan_values}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528\u9884\u8ba1\u7b97\u503c<\/h4>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u89d2\u5ea6\u7684\u8303\u56f4\u662f\u56fa\u5b9a\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u9884\u5148\u8ba1\u7b97\u4e09\u89d2\u51fd\u6570\u503c\u5e76\u5b58\u50a8\u5728\u67e5\u627e\u8868\u4e2d\u3002\u8fd9\u6837\u5728\u8fd0\u884c\u65f6\u53ef\u4ee5\u901a\u8fc7\u67e5\u627e\u8868\u5feb\u901f\u83b7\u53d6\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<h2><strong>\u9884\u8ba1\u7b97\u4e09\u89d2\u51fd\u6570\u503c<\/strong><\/h2>\n<p>lookup_table = {}<\/p>\n<p>for angle in range(0, 361):<\/p>\n<p>    radians = math.radians(angle)<\/p>\n<p>    lookup_table[angle] = {<\/p>\n<p>        &#39;sin&#39;: math.sin(radians),<\/p>\n<p>        &#39;cos&#39;: math.cos(radians),<\/p>\n<p>        &#39;tan&#39;: math.tan(radians) if angle % 180 != 90 else None<\/p>\n<p>    }<\/p>\n<h2><strong>\u4f7f\u7528\u67e5\u627e\u8868<\/strong><\/h2>\n<p>angle_in_degrees = 45<\/p>\n<p>sin_value = lookup_table[angle_in_degrees][&#39;sin&#39;]<\/p>\n<p>cos_value = lookup_table[angle_in_degrees][&#39;cos&#39;]<\/p>\n<p>tan_value = lookup_table[angle_in_degrees][&#39;tan&#39;]<\/p>\n<p>print(f&quot;Sine of {angle_in_degrees} degrees: {sin_value}&quot;)<\/p>\n<p>print(f&quot;Cosine of {angle_in_degrees} degrees: {cos_value}&quot;)<\/p>\n<p>print(f&quot;Tangent of {angle_in_degrees} degrees: {tan_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u4e09\u89d2\u51fd\u6570\u7684\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><p>\u4e09\u89d2\u51fd\u6570\u5728\u79d1\u5b66\u8ba1\u7b97\u3001\u5de5\u7a0b\u3001\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u548c\u7269\u7406\u4eff\u771f\u7b49\u9886\u57df\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66<\/h4>\n<\/p>\n<p><p>\u5728\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u4e2d\uff0c\u4e09\u89d2\u51fd\u6570\u88ab\u5e7f\u6cdb\u7528\u4e8e\u65cb\u8f6c\u3001\u7f29\u653e\u548c\u53d8\u6362\u4e8c\u7ef4\u548c\u4e09\u7ef4\u56fe\u5f62\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5f26\u548c\u4f59\u5f26\u51fd\u6570\u6765\u8ba1\u7b97\u56fe\u5f62\u65cb\u8f6c\u540e\u7684\u65b0\u5750\u6807\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>def rotate_point(x, y, angle_in_degrees):<\/p>\n<p>    angle_in_radians = math.radians(angle_in_degrees)<\/p>\n<p>    new_x = x * math.cos(angle_in_radians) - y * math.sin(angle_in_radians)<\/p>\n<p>    new_y = x * math.sin(angle_in_radians) + y * math.cos(angle_in_radians)<\/p>\n<p>    return new_x, new_y<\/p>\n<p>x, y = 1, 0<\/p>\n<p>angle = 45<\/p>\n<p>new_x, new_y = rotate_point(x, y, angle)<\/p>\n<p>print(f&quot;Original point: ({x}, {y})&quot;)<\/p>\n<p>print(f&quot;Rotated point: ({new_x}, {new_y})&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7269\u7406\u4eff\u771f<\/h4>\n<\/p>\n<p><p>\u5728\u7269\u7406\u4eff\u771f\u4e2d\uff0c\u4e09\u89d2\u51fd\u6570\u7528\u4e8e\u8ba1\u7b97\u7269\u4f53\u7684\u8fd0\u52a8\u8f68\u8ff9\u3001\u529b\u7684\u5206\u89e3\u548c\u5408\u6210\u7b49\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5f26\u548c\u4f59\u5f26\u51fd\u6570\u6765\u8ba1\u7b97\u659c\u629b\u8fd0\u52a8\u7684\u5206\u901f\u5ea6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>def calculate_trajectory(v0, angle_in_degrees, t):<\/p>\n<p>    angle_in_radians = math.radians(angle_in_degrees)<\/p>\n<p>    vx = v0 * math.cos(angle_in_radians)<\/p>\n<p>    vy = v0 * math.sin(angle_in_radians)<\/p>\n<p>    g = 9.81  # \u91cd\u529b\u52a0\u901f\u5ea6<\/p>\n<p>    x = vx * t<\/p>\n<p>    y = vy * t - 0.5 * g * t2<\/p>\n<p>    return x, y<\/p>\n<p>v0 = 20  # \u521d\u901f\u5ea6\uff0cm\/s<\/p>\n<p>angle = 45  # \u53d1\u5c04\u89d2\u5ea6\uff0c\u5ea6<\/p>\n<p>t = 2  # \u65f6\u95f4\uff0cs<\/p>\n<p>x, y = calculate_trajectory(v0, angle, t)<\/p>\n<p>print(f&quot;At time {t}s, the object is at ({x}, {y})&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u4fe1\u53f7\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u5728\u4fe1\u53f7\u5904\u7406\u548c\u901a\u4fe1\u9886\u57df\uff0c\u4e09\u89d2\u51fd\u6570\u7528\u4e8e\u751f\u6210\u548c\u5206\u6790\u4fe1\u53f7\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5f26\u51fd\u6570\u751f\u6210\u6b63\u5f26\u6ce2\u4fe1\u53f7\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p>def generate_sine_wave(frequency, duration, sampling_rate):<\/p>\n<p>    t = np.linspace(0, duration, int(sampling_rate * duration), endpoint=False)<\/p>\n<p>    signal = np.sin(2 * np.pi * frequency * t)<\/p>\n<p>    return t, signal<\/p>\n<p>frequency = 5  # \u9891\u7387\uff0cHz<\/p>\n<p>duration = 1  # \u6301\u7eed\u65f6\u95f4\uff0cs<\/p>\n<p>sampling_rate = 1000  # \u91c7\u6837\u7387\uff0cHz<\/p>\n<p>t, signal = generate_sine_wave(frequency, duration, sampling_rate)<\/p>\n<p>plt.plot(t, signal)<\/p>\n<p>plt.title(&#39;Sine Wave&#39;)<\/p>\n<p>plt.xlabel(&#39;Time [s]&#39;)<\/p>\n<p>plt.ylabel(&#39;Amplitude&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\uff0c\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528math\u6a21\u5757\u8ba1\u7b97\u4e09\u89d2\u51fd\u6570\uff0c\u5305\u62ec\u6b63\u5f26\u3001\u4f59\u5f26\u548c\u6b63\u5207\u51fd\u6570\u3002\u6211\u4eec\u8fd8\u8ba8\u8bba\u4e86\u89d2\u5ea6\u4e0e\u5f27\u5ea6\u7684\u8f6c\u6362\u3001\u5f02\u5e38\u60c5\u51b5\u7684\u5904\u7406\u4ee5\u53ca\u4f18\u5316\u8ba1\u7b97\u6027\u80fd\u7684\u65b9\u6cd5\u3002\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u4ecb\u7ecd\u4e86\u4e09\u89d2\u51fd\u6570\u5728\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u3001\u7269\u7406\u4eff\u771f\u548c\u4fe1\u53f7\u5904\u7406\u7b49\u9886\u57df\u7684\u5e94\u7528\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u80fd\u591f\u5e2e\u52a9\u60a8\u5728\u5b9e\u9645\u7f16\u7a0b\u4e2d\u66f4\u597d\u5730\u4f7f\u7528\u4e09\u89d2\u51fd\u6570\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>1. \u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528\u4e09\u89d2\u51fd\u6570\u5e93\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5185\u7f6e\u7684<code>math<\/code>\u6a21\u5757\u8f7b\u677e\u4f7f\u7528\u4e09\u89d2\u51fd\u6570\u3002\u53ea\u9700\u5bfc\u5165\u8be5\u6a21\u5757\u540e\uff0c\u5373\u53ef\u4f7f\u7528\u5982<code>math.sin()<\/code>\u3001<code>math.cos()<\/code>\u548c<code>math.tan()<\/code>\u7b49\u51fd\u6570\u6765\u8ba1\u7b97\u6b63\u5f26\u3001\u4f59\u5f26\u548c\u6b63\u5207\u503c\u3002\u786e\u4fdd\u8f93\u5165\u7684\u89d2\u5ea6\u662f\u4ee5\u5f27\u5ea6\u4e3a\u5355\u4f4d\uff0c\u82e5\u9700\u8981\u4ee5\u5ea6\u4e3a\u5355\u4f4d\u8fdb\u884c\u8ba1\u7b97\uff0c\u53ef\u4ee5\u4f7f\u7528<code>math.radians()<\/code>\u51fd\u6570\u5c06\u5ea6\u6570\u8f6c\u6362\u4e3a\u5f27\u5ea6\u3002<\/p>\n<p><strong>2. Python\u4e2d\u5982\u4f55\u5904\u7406\u4e09\u89d2\u51fd\u6570\u7684\u53cd\u51fd\u6570\uff1f<\/strong><br \/>Python\u7684<code>math<\/code>\u6a21\u5757\u4e5f\u63d0\u4f9b\u4e86\u4e09\u89d2\u51fd\u6570\u7684\u53cd\u51fd\u6570\uff0c\u4f8b\u5982<code>math.asin()<\/code>\u3001<code>math.acos()<\/code>\u548c<code>math.atan()<\/code>\u3002\u8fd9\u4e9b\u51fd\u6570\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u6839\u636e\u5df2\u77e5\u7684\u4e09\u89d2\u51fd\u6570\u503c\u8ba1\u7b97\u51fa\u76f8\u5e94\u7684\u89d2\u5ea6\u3002\u6ce8\u610f\uff0c\u8fd9\u4e9b\u53cd\u51fd\u6570\u8fd4\u56de\u7684\u7ed3\u679c\u540c\u6837\u662f\u4ee5\u5f27\u5ea6\u4e3a\u5355\u4f4d\u7684\uff0c\u56e0\u6b64\u5728\u9700\u8981\u5ea6\u6570\u65f6\uff0c\u4f7f\u7528<code>math.degrees()<\/code>\u51fd\u6570\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n<p><strong>3. \u5728Python\u4e2d\u5982\u4f55\u7ed8\u5236\u4e09\u89d2\u51fd\u6570\u56fe\u5f62\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>matplotlib<\/code>\u5e93\u6765\u7ed8\u5236\u4e09\u89d2\u51fd\u6570\u7684\u56fe\u5f62\u3002\u901a\u8fc7\u751f\u6210\u4e00\u7cfb\u5217\u89d2\u5ea6\u503c\u5e76\u8ba1\u7b97\u76f8\u5e94\u7684\u4e09\u89d2\u51fd\u6570\u503c\uff0c\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u6b63\u5f26\u3001\u4f59\u5f26\u6216\u6b63\u5207\u66f2\u7ebf\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\u5bfc\u5165<code>matplotlib.pyplot<\/code>\u548c<code>numpy<\/code>\u5e93\uff0c\u751f\u6210\u89d2\u5ea6\u6570\u7ec4\uff0c\u5e76\u4f7f\u7528<code>plt.plot()<\/code>\u51fd\u6570\u7ed8\u5236\u56fe\u5f62\u3002\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>plt.title()<\/code>\u3001<code>plt.xlabel()<\/code>\u548c<code>plt.ylabel()<\/code>\u6765\u6dfb\u52a0\u56fe\u8868\u6807\u9898\u548c\u5750\u6807\u8f74\u6807\u7b7e\uff0c\u589e\u5f3a\u56fe\u5f62\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6\u5e93\u4e2d\u7684math\u6a21\u5757\u6765\u8ba1\u7b97\u4e09\u89d2\u51fd\u6570\u3002\u4e3b\u8981\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528math.sin()\u3001math [&hellip;]","protected":false},"author":3,"featured_media":1087697,"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\/1087688"}],"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=1087688"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1087688\/revisions"}],"predecessor-version":[{"id":1087698,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1087688\/revisions\/1087698"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1087697"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1087688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1087688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1087688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}