{"id":1156439,"date":"2025-01-13T18:16:06","date_gmt":"2025-01-13T10:16:06","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1156439.html"},"modified":"2025-01-13T18:16:09","modified_gmt":"2025-01-13T10:16:09","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e8%ae%a1%e7%ae%97%e6%ad%a3%e5%bc%a6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1156439.html","title":{"rendered":"\u5982\u4f55\u7528python\u8ba1\u7b97\u6b63\u5f26"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25194849\/b8f17ced-4435-4fd6-a41d-c4555abbd85b.webp\" alt=\"\u5982\u4f55\u7528python\u8ba1\u7b97\u6b63\u5f26\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528Python\u8ba1\u7b97\u6b63\u5f26\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528Python\u7684\u6807\u51c6\u5e93math\u6a21\u5757\u4e2d\u7684sin\u51fd\u6570\u6765\u5b9e\u73b0\u3001\u901a\u8fc7numpy\u5e93\u6765\u5904\u7406\u6570\u7ec4\u548c\u5411\u91cf\u5316\u8ba1\u7b97\u3001\u5229\u7528sympy\u5e93\u8fdb\u884c\u7b26\u53f7\u8ba1\u7b97\u3002<\/strong> \u5176\u4e2d\uff0c<strong>math\u6a21\u5757<\/strong>\u9002\u5408\u5904\u7406\u5355\u4e2a\u6570\u503c\u7684\u8ba1\u7b97\uff0c<strong>numpy\u5e93<\/strong>\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u7ec4\u548c\u77e9\u9635\u8fd0\u7b97\u65f6\u8868\u73b0\u51fa\u8272\uff0c<strong>sympy\u5e93<\/strong>\u5219\u9002\u7528\u4e8e\u7b26\u53f7\u8ba1\u7b97\u548c\u89e3\u6790\u6c42\u89e3\u3002\u5728\u4e0b\u9762\u7684\u5185\u5bb9\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e09\u79cd\u65b9\u6cd5\uff0c\u5e76\u5c55\u793a\u4e00\u4e9b\u5177\u4f53\u7684\u793a\u4f8b\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528math\u6a21\u5757\u8ba1\u7b97\u6b63\u5f26<\/p>\n<\/p>\n<p><p>Python\u7684\u6807\u51c6\u5e93math\u6a21\u5757\u63d0\u4f9b\u4e86\u8bb8\u591a\u6570\u5b66\u51fd\u6570\uff0c\u5305\u62ec\u8ba1\u7b97\u6b63\u5f26\u7684sin\u51fd\u6570\u3002math.sin\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\uff0c\u8be5\u53c2\u6570\u662f\u4e00\u4e2a\u4ee5\u5f27\u5ea6\u8868\u793a\u7684\u89d2\u5ea6\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<h2><strong>\u8ba1\u7b9730\u5ea6\u7684\u6b63\u5f26\u503c<\/strong><\/h2>\n<p>angle_degrees = 30<\/p>\n<p>angle_radians = math.radians(angle_degrees)  # \u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6<\/p>\n<p>sine_value = math.sin(angle_radians)<\/p>\n<p>print(f&quot;sin({angle_degrees}\u00b0) = {sine_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\uff08\u56e0\u4e3amath.sin\u51fd\u6570\u63a5\u53d7\u5f27\u5ea6\u4f5c\u4e3a\u8f93\u5165\uff09\uff0c\u7136\u540e\u8c03\u7528math.sin\u51fd\u6570\u8ba1\u7b97\u6b63\u5f26\u503c\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528numpy\u5e93\u8ba1\u7b97\u6b63\u5f26<\/p>\n<\/p>\n<p><p>numpy\u5e93\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u503c\u8ba1\u7b97\u5e93\uff0c\u7279\u522b\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u6570\u7ec4\u548c\u77e9\u9635\u8fd0\u7b97\u3002numpy\u63d0\u4f9b\u4e86numpy.sin\u51fd\u6570\u6765\u8ba1\u7b97\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u6b63\u5f26\u503c\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u5b9a\u4e49\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u89d2\u5ea6\u7684\u6570\u7ec4\uff08\u4ee5\u5ea6\u6570\u8868\u793a\uff09<\/strong><\/h2>\n<p>angles_degrees = np.array([0, 30, 45, 60, 90])<\/p>\n<p>angles_radians = np.radians(angles_degrees)  # \u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6<\/p>\n<p>sine_values = np.sin(angles_radians)<\/p>\n<p>print(f&quot;Angles (degrees): {angles_degrees}&quot;)<\/p>\n<p>print(f&quot;Sine values: {sine_values}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528numpy\u6570\u7ec4\u6765\u5b58\u50a8\u591a\u4e2a\u89d2\u5ea6\uff0c\u5e76\u4f7f\u7528numpy.radians\u51fd\u6570\u5c06\u5b83\u4eec\u8f6c\u6362\u4e3a\u5f27\u5ea6\u3002\u7136\u540e\uff0c\u6211\u4eec\u8c03\u7528numpy.sin\u51fd\u6570\u8ba1\u7b97\u6bcf\u4e2a\u89d2\u5ea6\u7684\u6b63\u5f26\u503c\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528sympy\u5e93\u8ba1\u7b97\u6b63\u5f26<\/p>\n<\/p>\n<p><p>sympy\u5e93\u662f\u4e00\u4e2a\u7b26\u53f7\u8ba1\u7b97\u5e93\uff0c\u9002\u7528\u4e8e\u89e3\u6790\u6c42\u89e3\u548c\u7b26\u53f7\u8ba1\u7b97\u3002sympy\u63d0\u4f9b\u4e86\u8bb8\u591a\u7b26\u53f7\u6570\u5b66\u51fd\u6570\uff0c\u5305\u62ec\u8ba1\u7b97\u6b63\u5f26\u7684sin\u51fd\u6570\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sympy as sp<\/p>\n<h2><strong>\u5b9a\u4e49\u4e00\u4e2a\u7b26\u53f7\u53d8\u91cf<\/strong><\/h2>\n<p>x = sp.symbols(&#39;x&#39;)<\/p>\n<h2><strong>\u5b9a\u4e49\u4e00\u4e2a\u8868\u8fbe\u5f0f<\/strong><\/h2>\n<p>expression = sp.sin(x)<\/p>\n<h2><strong>\u8ba1\u7b97\u7279\u5b9a\u89d2\u5ea6\u7684\u6b63\u5f26\u503c<\/strong><\/h2>\n<p>angle_degrees = 30<\/p>\n<p>angle_radians = sp.rad(angle_degrees)  # \u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6<\/p>\n<p>sine_value = expression.subs(x, angle_radians)<\/p>\n<p>print(f&quot;sin({angle_degrees}\u00b0) = {sine_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528sympy\u5b9a\u4e49\u4e00\u4e2a\u7b26\u53f7\u53d8\u91cf\u548c\u4e00\u4e2a\u6b63\u5f26\u8868\u8fbe\u5f0f\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528subs\u65b9\u6cd5\u5c06\u7b26\u53f7\u53d8\u91cf\u66ff\u6362\u4e3a\u7279\u5b9a\u7684\u5f27\u5ea6\u89d2\u5ea6\uff0c\u4ee5\u8ba1\u7b97\u8be5\u89d2\u5ea6\u7684\u6b63\u5f26\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u6b63\u5f26\u51fd\u6570\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u6b63\u5f26\u51fd\u6570\u5728\u8bb8\u591a\u9886\u57df\u4e2d\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\uff0c\u5305\u62ec\u7269\u7406\u3001\u5de5\u7a0b\u3001\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5177\u4f53\u7684\u5e94\u7528\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u6ce2\u52a8\u73b0\u8c61\u6a21\u62df<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u7269\u7406\u5b66\u4e2d\uff0c\u6b63\u5f26\u51fd\u6570\u5e38\u7528\u4e8e\u63cf\u8ff0\u6ce2\u52a8\u73b0\u8c61\uff0c\u5982\u58f0\u6ce2\u3001\u7535\u78c1\u6ce2\u548c\u673a\u68b0\u6ce2\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u6b63\u5f26\u51fd\u6570\u6a21\u62df\u4e00\u4e2a\u7b80\u5355\u7684\u6ce2\u52a8\u73b0\u8c61\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u5b9a\u4e49\u6ce2\u7684\u53c2\u6570<\/strong><\/h2>\n<p>amplitude = 1<\/p>\n<p>frequency = 1<\/p>\n<p>phase = 0<\/p>\n<p>time = np.linspace(0, 2 * np.pi, 1000)<\/p>\n<h2><strong>\u8ba1\u7b97\u6ce2\u7684\u6b63\u5f26\u503c<\/strong><\/h2>\n<p>wave = amplitude * np.sin(2 * np.pi * frequency * time + phase)<\/p>\n<h2><strong>\u7ed8\u5236\u6ce2\u5f62\u56fe<\/strong><\/h2>\n<p>plt.plot(time, wave)<\/p>\n<p>plt.title(&#39;Sine Wave&#39;)<\/p>\n<p>plt.xlabel(&#39;Time&#39;)<\/p>\n<p>plt.ylabel(&#39;Amplitude&#39;)<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u6ce2\u7684\u632f\u5e45\u3001\u9891\u7387\u548c\u76f8\u4f4d\uff0c\u5e76\u4f7f\u7528numpy\u8ba1\u7b97\u6ce2\u7684\u6b63\u5f26\u503c\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528matplotlib\u5e93\u7ed8\u5236\u6ce2\u5f62\u56fe\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4fe1\u53f7\u5904\u7406<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u4fe1\u53f7\u5904\u7406\u9886\u57df\uff0c\u6b63\u5f26\u51fd\u6570\u7528\u4e8e\u751f\u6210\u548c\u5206\u6790\u5404\u79cd\u4fe1\u53f7\uff0c\u5982\u6b63\u5f26\u6ce2\u3001\u4f59\u5f26\u6ce2\u548c\u5085\u91cc\u53f6\u53d8\u6362\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u751f\u6210\u4e00\u4e2a\u6b63\u5f26\u6ce2\u4fe1\u53f7\u5e76\u8fdb\u884c\u5085\u91cc\u53f6\u53d8\u6362\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u751f\u6210\u6b63\u5f26\u6ce2\u4fe1\u53f7<\/strong><\/h2>\n<p>sampling_rate = 1000  # \u91c7\u6837\u7387<\/p>\n<p>duration = 1  # \u4fe1\u53f7\u6301\u7eed\u65f6\u95f4\uff08\u79d2\uff09<\/p>\n<p>frequency = 5  # \u4fe1\u53f7\u9891\u7387\uff08\u8d6b\u5179\uff09<\/p>\n<p>t = np.linspace(0, duration, sampling_rate * duration, endpoint=False)<\/p>\n<p>signal = np.sin(2 * np.pi * frequency * t)<\/p>\n<h2><strong>\u8fdb\u884c\u5085\u91cc\u53f6\u53d8\u6362<\/strong><\/h2>\n<p>fft_result = np.fft.fft(signal)<\/p>\n<p>fft_magnitude = np.abs(fft_result)<\/p>\n<p>fft_frequency = np.fft.fftfreq(len(signal), 1 \/ sampling_rate)<\/p>\n<h2><strong>\u7ed8\u5236\u65f6\u57df\u548c\u9891\u57df\u56fe\u50cf<\/strong><\/h2>\n<p>plt.figure(figsize=(12, 6))<\/p>\n<p>plt.subplot(2, 1, 1)<\/p>\n<p>plt.plot(t, signal)<\/p>\n<p>plt.title(&#39;Time Dom<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n Signal&#39;)<\/p>\n<p>plt.xlabel(&#39;Time [s]&#39;)<\/p>\n<p>plt.ylabel(&#39;Amplitude&#39;)<\/p>\n<p>plt.subplot(2, 1, 2)<\/p>\n<p>plt.plot(fft_frequency, fft_magnitude)<\/p>\n<p>plt.title(&#39;Frequency Domain Signal&#39;)<\/p>\n<p>plt.xlabel(&#39;Frequency [Hz]&#39;)<\/p>\n<p>plt.ylabel(&#39;Magnitude&#39;)<\/p>\n<p>plt.xlim(0, 20)  # \u4ec5\u663e\u793a0\u523020\u8d6b\u5179\u7684\u9891\u7387\u8303\u56f4<\/p>\n<p>plt.tight_layout()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e86\u4e00\u4e2a\u9891\u7387\u4e3a5\u8d6b\u5179\u7684\u6b63\u5f26\u6ce2\u4fe1\u53f7\uff0c\u5e76\u4f7f\u7528numpy\u8fdb\u884c\u5085\u91cc\u53f6\u53d8\u6362\u3002\u7136\u540e\uff0c\u6211\u4eec\u7ed8\u5236\u4e86\u4fe1\u53f7\u7684\u65f6\u57df\u548c\u9891\u57df\u56fe\u50cf\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u4e2d\uff0c\u6b63\u5f26\u51fd\u6570\u7528\u4e8e\u521b\u5efa\u5e73\u6ed1\u7684\u52a8\u753b\u548c\u89c6\u89c9\u6548\u679c\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5f26\u51fd\u6570\u751f\u6210\u5468\u671f\u6027\u8fd0\u52a8\uff0c\u5982\u6446\u52a8\u548c\u6ce2\u52a8\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u6b63\u5f26\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u52a8\u753b\uff1a<\/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>import matplotlib.animation as animation<\/p>\n<h2><strong>\u5b9a\u4e49\u52a8\u753b\u53c2\u6570<\/strong><\/h2>\n<p>amplitude = 1<\/p>\n<p>frequency = 1<\/p>\n<p>phase = 0<\/p>\n<p>duration = 2  # \u52a8\u753b\u6301\u7eed\u65f6\u95f4\uff08\u79d2\uff09<\/p>\n<p>fps = 30  # \u6bcf\u79d2\u5e27\u6570<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u5f62\u548c\u8f74<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<p>x = np.linspace(0, 2 * np.pi, 1000)<\/p>\n<p>line, = ax.plot(x, amplitude * np.sin(2 * np.pi * frequency * x + phase))<\/p>\n<h2><strong>\u66f4\u65b0\u51fd\u6570<\/strong><\/h2>\n<p>def update(frame):<\/p>\n<p>    phase = 2 * np.pi * frame \/ (fps * duration)<\/p>\n<p>    line.set_ydata(amplitude * np.sin(2 * np.pi * frequency * x + phase))<\/p>\n<p>    return line,<\/p>\n<h2><strong>\u521b\u5efa\u52a8\u753b<\/strong><\/h2>\n<p>ani = animation.FuncAnimation(fig, update, frames=fps * duration, blit=True)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528matplotlib\u7684animation\u6a21\u5757\u521b\u5efa\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u52a8\u753b\uff0c\u5c55\u793a\u4e86\u4e00\u4e2a\u6b63\u5f26\u6ce2\u7684\u5468\u671f\u6027\u8fd0\u52a8\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u6b63\u5f26\u51fd\u6570\u7684\u6027\u8d28\u548c\u7279\u6027<\/h3>\n<\/p>\n<p><p>\u6b63\u5f26\u51fd\u6570\u5177\u6709\u8bb8\u591a\u91cd\u8981\u7684\u6027\u8d28\u548c\u7279\u6027\uff0c\u8fd9\u4e9b\u7279\u6027\u5728\u6570\u5b66\u3001\u7269\u7406\u548c\u5de5\u7a0b\u4e2d\u5177\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5173\u952e\u7279\u6027\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u5468\u671f\u6027<\/strong><\/li>\n<\/ol>\n<p><p>\u6b63\u5f26\u51fd\u6570\u662f\u4e00\u4e2a\u5468\u671f\u51fd\u6570\uff0c\u5176\u5468\u671f\u4e3a2\u03c0\u3002\u5373\u5bf9\u4e8e\u4efb\u4f55\u5b9e\u6570x\uff0csin(x + 2\u03c0) = sin(x)\u3002\u8fd9\u610f\u5473\u7740\u6b63\u5f26\u51fd\u6570\u7684\u56fe\u50cf\u5728\u6bcf\u4e2a2\u03c0\u7684\u533a\u95f4\u5185\u91cd\u590d\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5947\u51fd\u6570<\/strong><\/li>\n<\/ol>\n<p><p>\u6b63\u5f26\u51fd\u6570\u662f\u4e00\u4e2a\u5947\u51fd\u6570\uff0c\u5373\u5bf9\u4e8e\u4efb\u4f55\u5b9e\u6570x\uff0csin(-x) = -sin(x)\u3002\u8fd9\u610f\u5473\u7740\u6b63\u5f26\u51fd\u6570\u5173\u4e8e\u539f\u70b9\u5bf9\u79f0\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5e45\u503c\u548c\u76f8\u4f4d<\/strong><\/li>\n<\/ol>\n<p><p>\u6b63\u5f26\u51fd\u6570\u7684\u5e45\u503c\u662f\u5176\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u7684\u5dee\u7684\u4e00\u534a\u3002\u5bf9\u4e8e\u6807\u51c6\u6b63\u5f26\u51fd\u6570sin(x)\uff0c\u5176\u5e45\u503c\u4e3a1\u3002\u76f8\u4f4d\u8868\u793a\u6b63\u5f26\u51fd\u6570\u7684\u6c34\u5e73\u504f\u79fb\u91cf\u3002\u4f8b\u5982\uff0csin(x + \u03c0\/2)\u8868\u793a\u4e00\u4e2a\u76f8\u4f4d\u4e3a\u03c0\/2\u7684\u6b63\u5f26\u51fd\u6570\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u5085\u91cc\u53f6\u7ea7\u6570<\/strong><\/li>\n<\/ol>\n<p><p>\u6b63\u5f26\u51fd\u6570\u53ef\u4ee5\u7528\u6765\u8868\u793a\u5085\u91cc\u53f6\u7ea7\u6570\uff0c\u5373\u5c06\u4e00\u4e2a\u5468\u671f\u51fd\u6570\u8868\u793a\u4e3a\u4e00\u7cfb\u5217\u6b63\u5f26\u548c\u4f59\u5f26\u51fd\u6570\u7684\u548c\u3002\u8fd9\u5728\u4fe1\u53f7\u5904\u7406\u548c\u5206\u6790\u4e2d\u5177\u6709\u91cd\u8981\u610f\u4e49\u3002<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u5085\u91cc\u53f6\u7ea7\u6570\u8868\u793a\u4e00\u4e2a\u65b9\u6ce2\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u5b9a\u4e49\u65b9\u6ce2\u51fd\u6570<\/strong><\/h2>\n<p>def square_wave(t, harmonics=10):<\/p>\n<p>    result = np.zeros_like(t)<\/p>\n<p>    for n in range(1, harmonics + 1, 2):<\/p>\n<p>        result += (4 \/ (np.pi * n)) * np.sin(n * t)<\/p>\n<p>    return result<\/p>\n<h2><strong>\u751f\u6210\u65f6\u95f4\u5e8f\u5217<\/strong><\/h2>\n<p>t = np.linspace(0, 2 * np.pi, 1000)<\/p>\n<h2><strong>\u8ba1\u7b97\u65b9\u6ce2<\/strong><\/h2>\n<p>square_wave_signal = square_wave(t, harmonics=10)<\/p>\n<h2><strong>\u7ed8\u5236\u65b9\u6ce2<\/strong><\/h2>\n<p>plt.plot(t, square_wave_signal)<\/p>\n<p>plt.title(&#39;Square Wave (10 Harmonics)&#39;)<\/p>\n<p>plt.xlabel(&#39;Time&#39;)<\/p>\n<p>plt.ylabel(&#39;Amplitude&#39;)<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u5085\u91cc\u53f6\u7ea7\u6570\u8868\u793a\u4e86\u4e00\u4e2a\u65b9\u6ce2\uff0c\u5e76\u7ed8\u5236\u4e86\u5176\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u6b63\u5f26\u51fd\u6570\u7684\u5bfc\u6570\u548c\u79ef\u5206<\/h3>\n<\/p>\n<p><p>\u6b63\u5f26\u51fd\u6570\u7684\u5bfc\u6570\u548c\u79ef\u5206\u5728\u5fae\u79ef\u5206\u4e2d\u5177\u6709\u91cd\u8981\u610f\u4e49\u3002\u4ee5\u4e0b\u662f\u6b63\u5f26\u51fd\u6570\u7684\u5bfc\u6570\u548c\u79ef\u5206\u7684\u57fa\u672c\u516c\u5f0f\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u5bfc\u6570<\/strong><\/li>\n<\/ol>\n<p><p>\u6b63\u5f26\u51fd\u6570sin(x)\u7684\u5bfc\u6570\u662f\u4f59\u5f26\u51fd\u6570cos(x)\uff1a<\/p>\n<p>[ \\frac{d}{dx} \\sin(x) = \\cos(x) ]<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u79ef\u5206<\/strong><\/li>\n<\/ol>\n<p><p>\u6b63\u5f26\u51fd\u6570sin(x)\u7684\u4e0d\u5b9a\u79ef\u5206\u662f\u8d1f\u4f59\u5f26\u51fd\u6570\u52a0\u4e00\u4e2a\u79ef\u5206\u5e38\u6570C\uff1a<\/p>\n<p>[ \\int \\sin(x) , dx = -\\cos(x) + C ]<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528sympy\u5e93\u8ba1\u7b97\u6b63\u5f26\u51fd\u6570\u7684\u5bfc\u6570\u548c\u79ef\u5206\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sympy as sp<\/p>\n<h2><strong>\u5b9a\u4e49\u7b26\u53f7\u53d8\u91cf<\/strong><\/h2>\n<p>x = sp.symbols(&#39;x&#39;)<\/p>\n<h2><strong>\u5b9a\u4e49\u6b63\u5f26\u51fd\u6570<\/strong><\/h2>\n<p>sin_x = sp.sin(x)<\/p>\n<h2><strong>\u8ba1\u7b97\u5bfc\u6570<\/strong><\/h2>\n<p>derivative = sp.diff(sin_x, x)<\/p>\n<p>print(f&quot;Derivative of sin(x): {derivative}&quot;)<\/p>\n<h2><strong>\u8ba1\u7b97\u4e0d\u5b9a\u79ef\u5206<\/strong><\/h2>\n<p>integral = sp.integrate(sin_x, x)<\/p>\n<p>print(f&quot;Indefinite integral of sin(x): {integral}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528sympy\u5e93\u8ba1\u7b97\u4e86\u6b63\u5f26\u51fd\u6570\u7684\u5bfc\u6570\u548c\u4e0d\u5b9a\u79ef\u5206\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u6b63\u5f26\u51fd\u6570\u7684\u6570\u503c\u89e3\u6cd5<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u6570\u503c\u6c42\u89e3\u6b63\u5f26\u51fd\u6570\u7684\u65b9\u7a0b\u3002\u4f8b\u5982\uff0c\u6c42\u89e3\u65b9\u7a0bsin(x) = 0.5\u7684\u89e3\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528scipy\u5e93\u7684optimize\u6a21\u5757\u6570\u503c\u6c42\u89e3\u6b63\u5f26\u51fd\u6570\u7684\u65b9\u7a0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>from scipy.optimize import fsolve<\/p>\n<h2><strong>\u5b9a\u4e49\u65b9\u7a0b<\/strong><\/h2>\n<p>def equation(x):<\/p>\n<p>    return np.sin(x) - 0.5<\/p>\n<h2><strong>\u6c42\u89e3\u65b9\u7a0b<\/strong><\/h2>\n<p>initial_guess = np.pi \/ 4  # \u521d\u59cb\u731c\u6d4b\u503c<\/p>\n<p>solution = fsolve(equation, initial_guess)<\/p>\n<p>print(f&quot;Solution of sin(x) = 0.5: x = {solution[0]}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u65b9\u7a0bsin(x) &#8211; 0.5\uff0c\u5e76\u4f7f\u7528fsolve\u51fd\u6570\u6570\u503c\u6c42\u89e3\u8be5\u65b9\u7a0b\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u6b63\u5f26\u51fd\u6570\u7684\u56fe\u50cf\u548c\u6027\u8d28<\/h3>\n<\/p>\n<p><p>\u6b63\u5f26\u51fd\u6570\u7684\u56fe\u50cf\u662f\u4e00\u4e2a\u5e73\u6ed1\u7684\u6ce2\u5f62\uff0c\u5177\u6709\u4ee5\u4e0b\u4e3b\u8981\u7279\u6027\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u6ce2\u5cf0\u548c\u6ce2\u8c37<\/strong><\/li>\n<\/ol>\n<p><p>\u6b63\u5f26\u51fd\u6570\u7684\u6ce2\u5cf0\uff08\u6700\u5927\u503c\uff09\u548c\u6ce2\u8c37\uff08\u6700\u5c0f\u503c\uff09\u5206\u522b\u53d1\u751f\u5728x = (2k+1)\u03c0\/2\u548cx = k\u03c0\uff08k\u4e3a\u6574\u6570\uff09\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u96f6\u70b9<\/strong><\/li>\n<\/ol>\n<p><p>\u6b63\u5f26\u51fd\u6570\u7684\u96f6\u70b9\u53d1\u751f\u5728x = k\u03c0\uff08k\u4e3a\u6574\u6570\uff09\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5bf9\u79f0\u6027<\/strong><\/li>\n<\/ol>\n<p><p>\u6b63\u5f26\u51fd\u6570\u5173\u4e8e\u539f\u70b9\u5bf9\u79f0\uff08\u5947\u51fd\u6570\uff09\uff0c\u5176\u56fe\u50cf\u5173\u4e8ey\u8f74\u5bf9\u79f0\u3002<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u7ed8\u5236\u6b63\u5f26\u51fd\u6570\u7684\u56fe\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u751f\u6210x\u8f74\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(-2 * np.pi, 2 * np.pi, 1000)<\/p>\n<h2><strong>\u8ba1\u7b97\u6b63\u5f26\u503c<\/strong><\/h2>\n<p>y = np.sin(x)<\/p>\n<h2><strong>\u7ed8\u5236\u6b63\u5f26\u51fd\u6570\u56fe\u50cf<\/strong><\/h2>\n<p>plt.plot(x, y)<\/p>\n<p>plt.title(&#39;Sine Function&#39;)<\/p>\n<p>plt.xlabel(&#39;x&#39;)<\/p>\n<p>plt.ylabel(&#39;sin(x)&#39;)<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.axhline(0, color=&#39;black&#39;,linewidth=0.5)<\/p>\n<p>plt.axvline(0, color=&#39;black&#39;,linewidth=0.5)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e86x\u8f74\u6570\u636e\uff0c\u5e76\u8ba1\u7b97\u4e86\u76f8\u5e94\u7684\u6b63\u5f26\u503c\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528matplotlib\u7ed8\u5236\u4e86\u6b63\u5f26\u51fd\u6570\u7684\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u6b63\u5f26\u51fd\u6570\u5728<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u4e2d\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u6b63\u5f26\u51fd\u6570\u5728\u673a\u5668\u5b66\u4e60\u4e2d\u4e5f\u6709\u4e00\u4e9b\u5e94\u7528\u3002\u4f8b\u5982\uff0c\u5728\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u548c\u9884\u6d4b\u4e2d\uff0c\u6b63\u5f26\u51fd\u6570\u53ef\u4ee5\u7528\u6765\u751f\u6210\u5468\u671f\u6027\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u6b63\u5f26\u51fd\u6570\u751f\u6210\u4e00\u4e2a\u7b80\u5355\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u751f\u6210\u65f6\u95f4\u6570\u636e<\/strong><\/h2>\n<p>time = np.linspace(0, 10, 1000)<\/p>\n<h2><strong>\u751f\u6210\u6b63\u5f26\u6ce2\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/strong><\/h2>\n<p>amplitude = 1<\/p>\n<p>frequency = 0.5<\/p>\n<p>data = amplitude * np.sin(2 * np.pi * frequency * time)<\/p>\n<h2><strong>\u7ed8\u5236\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/strong><\/h2>\n<p>plt.plot(time, data)<\/p>\n<p>plt.title(&#39;Sine Wave Time Series&#39;)<\/p>\n<p>plt.xlabel(&#39;Time&#39;)<\/p>\n<p>plt.ylabel(&#39;Value&#39;)<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e86\u4e00\u4e2a\u9891\u7387\u4e3a0.5\u8d6b\u5179\u7684\u6b63\u5f26\u6ce2\u65f6\u95f4\u5e8f\u5217\u6570\u636e\uff0c\u5e76\u7ed8\u5236\u4e86\u5176\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u3001\u6b63\u5f26\u51fd\u6570\u7684\u6269\u5c55\u548c\u53d8\u79cd<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u6807\u51c6\u7684\u6b63\u5f26\u51fd\u6570\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u6269\u5c55\u548c\u53d8\u79cd\u3002\u4f8b\u5982\uff0c\u53cc\u66f2\u6b63\u5f26\u51fd\u6570\uff08sinh\uff09\u548c\u632f\u5e45\u8c03\u5236\u6b63\u5f26\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u53cc\u66f2\u6b63\u5f26\u51fd\u6570<\/strong><\/li>\n<\/ol>\n<p><p>\u53cc\u66f2\u6b63\u5f26\u51fd\u6570sinh(x)\u7684\u5b9a\u4e49\u4e3a\uff1a<\/p>\n<p>[ \\sinh(x) = \\frac{e^x &#8211; e^{-x}}{2} ]<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u8ba1\u7b97\u53cc\u66f2\u6b63\u5f26\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u8ba1\u7b97\u53cc\u66f2\u6b63\u5f26\u503c<\/strong><\/h2>\n<p>x = np.linspace(-2 * np.pi, 2 * np.pi, 1000)<\/p>\n<p>sinh_x = np.sinh(x)<\/p>\n<h2><strong>\u7ed8\u5236\u53cc\u66f2\u6b63\u5f26\u51fd\u6570\u56fe\u50cf<\/strong><\/h2>\n<p>import matplotlib.pyplot as plt<\/p>\n<p>plt.plot(x, sinh_x)<\/p>\n<p>plt.title(&#39;Hyperbolic Sine Function&#39;)<\/p>\n<p>plt.xlabel(&#39;x&#39;)<\/p>\n<p>plt.ylabel(&#39;sinh(x)&#39;)<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u8ba1\u7b97\u4e86\u53cc\u66f2\u6b63\u5f26\u51fd\u6570\u7684\u503c\uff0c\u5e76\u7ed8\u5236\u4e86\u5176\u56fe\u50cf\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u632f\u5e45\u8c03\u5236\u6b63\u5f26\u51fd\u6570<\/strong><\/li>\n<\/ol>\n<p><p>\u632f\u5e45\u8c03\u5236\u6b63\u5f26\u51fd\u6570\u662f\u4e00\u79cd\u5728\u4fe1\u53f7\u5904\u7406\u4e2d\u5e38\u7528\u7684\u6280\u672f\uff0c\u7528\u4e8e\u8c03\u5236\u4fe1\u53f7\u7684\u5e45\u5ea6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u751f\u6210\u4e00\u4e2a\u632f\u5e45\u8c03\u5236\u6b63\u5f26\u4fe1\u53f7\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u751f\u6210\u65f6\u95f4\u6570\u636e<\/strong><\/h2>\n<p>time = np.linspace(0, 1, 1000)<\/p>\n<h2><strong>\u751f\u6210\u8f7d\u6ce2\u4fe1\u53f7\u548c\u8c03\u5236\u4fe1\u53f7<\/strong><\/h2>\n<p>carrier_frequency = 50<\/p>\n<p>modulating_frequency = 5<\/p>\n<p>carrier_signal = np.sin(2 * np.pi * carrier_frequency * time)<\/p>\n<p>modulating_signal = np.sin(2 * np.pi * modulating_frequency * time)<\/p>\n<h2><strong>\u751f\u6210\u632f\u5e45\u8c03\u5236\u4fe1\u53f7<\/strong><\/h2>\n<p>am_signal = (1 + modulating_signal) * carrier_signal<\/p>\n<h2><strong>\u7ed8\u5236\u632f\u5e45\u8c03\u5236\u4fe1\u53f7<\/strong><\/h2>\n<p>plt.plot(time, am_signal)<\/p>\n<p>plt.title(&#39;Amplitude Modulated Sine Wave&#39;)<\/p>\n<p>plt.xlabel(&#39;Time&#39;)<\/p>\n<p>plt.ylabel(&#39;Amplitude&#39;)<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e86\u4e00\u4e2a\u8f7d\u6ce2\u4fe1\u53f7\u548c\u4e00\u4e2a\u8c03\u5236\u4fe1\u53f7\uff0c\u5e76\u751f\u6210\u4e86\u4e00\u4e2a\u632f\u5e45\u8c03\u5236\u6b63\u5f26\u4fe1\u53f7\u3002<\/p>\n<\/p>\n<p><h3>\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u8be6\u7ec6\u63a2\u8ba8\u4e86\u5982\u4f55\u4f7f\u7528Python\u8ba1\u7b97\u6b63\u5f26\u503c\uff0c\u4ee5\u53ca\u6b63\u5f26\u51fd\u6570\u7684\u5e7f\u6cdb\u5e94\u7528\u3002\u6211\u4eec\u8ba8\u8bba\u4e86\u4f7f\u7528math\u6a21\u5757\u3001numpy\u5e93\u548csympy\u5e93\u8ba1\u7b97\u6b63\u5f26\u503c\u7684\u65b9\u6cd5\uff0c\u5e76\u5c55\u793a\u4e86\u6b63\u5f26\u51fd\u6570\u5728\u6ce2\u52a8\u73b0\u8c61\u6a21\u62df\u3001\u4fe1\u53f7\u5904\u7406\u3001\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u3001\u673a\u5668\u5b66\u4e60\u7b49\u9886\u57df\u7684\u5e94\u7528\u3002\u6b63\u5f26\u51fd\u6570\u5177\u6709\u91cd\u8981\u7684\u6570\u5b66<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528\u6b63\u5f26\u51fd\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>math<\/code>\u6a21\u5757\u6765\u8ba1\u7b97\u6b63\u5f26\u503c\u3002\u9996\u5148\u9700\u8981\u5bfc\u5165\u8be5\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528<code>math.sin()<\/code>\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u5f27\u5ea6\u503c\u4f5c\u4e3a\u53c2\u6570\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u60f3\u8ba1\u7b9730\u5ea6\u7684\u6b63\u5f26\u503c\uff0c\u53ef\u4ee5\u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6\uff0830\u5ea6 = \u03c0\/6\u5f27\u5ea6\uff09\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import math\nsine_value = math.sin(math.pi \/ 6)\nprint(sine_value)  # \u8f93\u51fa 0.5\n<\/code><\/pre>\n<p><strong>Python\u4e2d\u5982\u4f55\u5904\u7406\u89d2\u5ea6\u4e0e\u5f27\u5ea6\u7684\u8f6c\u6362\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u89d2\u5ea6\u548c\u5f27\u5ea6\u4e4b\u95f4\u7684\u8f6c\u6362\u662f\u5e38\u89c1\u7684\u9700\u6c42\u3002\u53ef\u4ee5\u4f7f\u7528<code>math.radians()<\/code>\u51fd\u6570\u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6\u3002\u53cd\u4e4b\uff0c\u53ef\u4ee5\u4f7f\u7528<code>math.degrees()<\/code>\u5c06\u5f27\u5ea6\u8f6c\u6362\u4e3a\u89d2\u5ea6\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">angle_degrees = 30\nangle_radians = math.radians(angle_degrees)\nsine_value = math.sin(angle_radians)\nprint(sine_value)  # \u8f93\u51fa 0.5\n<\/code><\/pre>\n<p><strong>\u5728Python\u4e2d\u80fd\u5426\u8ba1\u7b97\u6b63\u5f26\u7684\u53cd\u51fd\u6570\uff1f<\/strong><br \/>\u5f53\u7136\u53ef\u4ee5\u3002\u5728Python\u4e2d\uff0c\u8ba1\u7b97\u6b63\u5f26\u7684\u53cd\u51fd\u6570\u53ef\u4ee5\u4f7f\u7528<code>math.asin()<\/code>\u51fd\u6570\u3002\u6b64\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u4ecb\u4e8e-1\u548c1\u4e4b\u95f4\u7684\u503c\uff0c\u5e76\u8fd4\u56de\u8be5\u503c\u5bf9\u5e94\u7684\u5f27\u5ea6\u3002\u8981\u5c06\u7ed3\u679c\u8f6c\u6362\u4e3a\u89d2\u5ea6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>math.degrees()<\/code>\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">sine_value = 0.5\nangle_radians = math.asin(sine_value)\nangle_degrees = math.degrees(angle_radians)\nprint(angle_degrees)  # \u8f93\u51fa 30.0\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u8ba1\u7b97\u6b63\u5f26\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528Python\u7684\u6807\u51c6\u5e93math\u6a21\u5757\u4e2d\u7684sin\u51fd\u6570\u6765\u5b9e\u73b0\u3001\u901a\u8fc7numpy\u5e93\u6765 [&hellip;]","protected":false},"author":3,"featured_media":1156446,"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\/1156439"}],"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=1156439"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1156439\/revisions"}],"predecessor-version":[{"id":1156447,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1156439\/revisions\/1156447"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1156446"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1156439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1156439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1156439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}