{"id":1069655,"date":"2025-01-08T10:51:03","date_gmt":"2025-01-08T02:51:03","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1069655.html"},"modified":"2025-01-08T10:51:05","modified_gmt":"2025-01-08T02:51:05","slug":"python%e7%a8%8b%e5%ba%8f%e5%a6%82%e4%bd%95%e5%86%99%e6%ac%a7%e6%8b%89%e5%85%ac%e5%bc%8f-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1069655.html","title":{"rendered":"python\u7a0b\u5e8f\u5982\u4f55\u5199\u6b27\u62c9\u516c\u5f0f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25100620\/fe684294-6cf4-4442-92cd-978706918b4a.webp\" alt=\"python\u7a0b\u5e8f\u5982\u4f55\u5199\u6b27\u62c9\u516c\u5f0f\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\u6765\u5b9e\u73b0\u6b27\u62c9\u516c\u5f0f\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528cmath\u6a21\u5757\uff0c\u8be5\u6a21\u5757\u652f\u6301\u590d\u6570\u8fd0\u7b97\u3002<\/strong> \u6b27\u62c9\u516c\u5f0f\u57fa\u672c\u5f62\u5f0f\u662f\uff1a <\/p>\n<\/p>\n<p><p>[ e^{ix} = \\cos(x) + i\\sin(x) ]<\/p>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c( e ) \u662f\u81ea\u7136\u5bf9\u6570\u7684\u5e95\uff0c( i ) \u662f\u865a\u6570\u5355\u4f4d\uff0c( x ) \u662f\u4efb\u610f\u5b9e\u6570\u3002\u901a\u8fc7Python\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u5e76\u9a8c\u8bc1\u8fd9\u4e2a\u516c\u5f0f\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u6b27\u62c9\u516c\u5f0f\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cmath<\/p>\n<p>import math<\/p>\n<p>def euler_formula(x):<\/p>\n<p>    # \u4f7f\u7528\u6b27\u62c9\u516c\u5f0f\u8ba1\u7b97 e^(ix)<\/p>\n<p>    e_to_ix = cmath.exp(complex(0, x))<\/p>\n<p>    # \u624b\u52a8\u8ba1\u7b97 cos(x) + i*sin(x) \u4ee5\u9a8c\u8bc1\u7ed3\u679c<\/p>\n<p>    cos_x = math.cos(x)<\/p>\n<p>    sin_x = math.sin(x)<\/p>\n<p>    cos_plus_i_sin = complex(cos_x, sin_x)<\/p>\n<p>    return e_to_ix, cos_plus_i_sin<\/p>\n<h2><strong>\u793a\u4f8b\uff1a\u8ba1\u7b97 e^(i*pi)<\/strong><\/h2>\n<p>x = math.pi<\/p>\n<p>result = euler_formula(x)<\/p>\n<p>print(f&quot;e^(i*{x}) = {result[0]}&quot;)<\/p>\n<p>print(f&quot;cos({x}) + i*sin({x}) = {result[1]}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>cmath.exp()<\/code> \u6765\u8ba1\u7b97 ( e^{ix} )\uff0c\u5e76\u4f7f\u7528 <code>math.cos()<\/code> \u548c <code>math.sin()<\/code> \u624b\u52a8\u8ba1\u7b97 ( \\cos(x) + i\\sin(x) ) \u4ee5\u9a8c\u8bc1\u7ed3\u679c\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u786e\u4fdd\u6b27\u62c9\u516c\u5f0f\u5728Python\u4e2d\u7684\u5b9e\u73b0\u662f\u6b63\u786e\u7684\u3002<\/p>\n<\/p>\n<p><p><strong>\u4e00\u3001\u590d\u6742\u6570\u8fd0\u7b97\u4e0e\u6b27\u62c9\u516c\u5f0f<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u590d\u6570\u662f\u901a\u8fc7\u5185\u7f6e\u7c7b\u578b <code>complex<\/code> \u8868\u793a\u7684\uff0c\u5e76\u4e14\u6240\u6709\u6d89\u53ca\u590d\u6570\u7684\u6570\u5b66\u8fd0\u7b97\u90fd\u53ef\u4ee5\u4f7f\u7528 <code>cmath<\/code> \u6a21\u5757\u3002<code>cmath<\/code> \u6a21\u5757\u652f\u6301\u590d\u6570\u7684\u6307\u6570\u3001\u5bf9\u6570\u3001\u4e09\u89d2\u51fd\u6570\u7b49\u8ba1\u7b97\uff0c\u8fd9\u4f7f\u5f97\u6211\u4eec\u80fd\u591f\u76f4\u63a5\u5229\u7528\u8fd9\u4e9b\u51fd\u6570\u6765\u5b9e\u73b0\u6b27\u62c9\u516c\u5f0f\u3002\u4e0b\u9762\u6211\u4eec\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cmath<\/p>\n<p>def complex_exponential(x):<\/p>\n<p>    # \u8ba1\u7b97 e^(ix) \u4f7f\u7528\u6b27\u62c9\u516c\u5f0f<\/p>\n<p>    return cmath.exp(complex(0, x))<\/p>\n<p>x = 1.0  # \u793a\u4f8b\u503c<\/p>\n<p>result = complex_exponential(x)<\/p>\n<p>print(f&quot;e^(i*{x}) = {result}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4e8c\u3001\u9a8c\u8bc1\u6b27\u62c9\u516c\u5f0f<\/strong><\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u9a8c\u8bc1\u6b27\u62c9\u516c\u5f0f\u7684\u6b63\u786e\u6027\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8ba1\u7b97\u7ed3\u679c\u4e0e\u624b\u52a8\u8ba1\u7b97\u7684\u7ed3\u679c\u8fdb\u884c\u6bd4\u8f83\u3002\u901a\u8fc7 <code>cmath<\/code> \u548c <code>math<\/code> \u6a21\u5757\u4e2d\u7684\u76f8\u5173\u51fd\u6570\uff0c\u6211\u4eec\u80fd\u591f\u5206\u522b\u8ba1\u7b97\u51fa <code>e^(ix)<\/code> \u548c <code>cos(x) + i*sin(x)<\/code>\uff0c\u7136\u540e\u5bf9\u6bd4\u5b83\u4eec\u662f\u5426\u76f8\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cmath<\/p>\n<p>import math<\/p>\n<p>def verify_euler_formula(x):<\/p>\n<p>    e_to_ix = cmath.exp(complex(0, x))<\/p>\n<p>    cos_plus_i_sin = complex(math.cos(x), math.sin(x))<\/p>\n<p>    return e_to_ix, cos_plus_i_sin<\/p>\n<p>x = math.pi  # \u793a\u4f8b\u503c \u03c0<\/p>\n<p>result = verify_euler_formula(x)<\/p>\n<p>print(f&quot;e^(i*{x}) = {result[0]}&quot;)<\/p>\n<p>print(f&quot;cos({x}) + i*sin({x}) = {result[1]}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4e09\u3001\u6b27\u62c9\u516c\u5f0f\u7684\u51e0\u4f55\u610f\u4e49<\/strong><\/p>\n<\/p>\n<p><p>\u6b27\u62c9\u516c\u5f0f\u4e0d\u4ec5\u5728\u6570\u5b66\u8ba1\u7b97\u4e2d\u975e\u5e38\u91cd\u8981\uff0c\u5b83\u5728\u590d\u5e73\u9762\u4e0a\u4e5f\u6709\u76f4\u89c2\u7684\u51e0\u4f55\u89e3\u91ca\u3002\u5bf9\u4e8e\u4efb\u610f\u5b9e\u6570 ( x )\uff0c( e^{ix} ) \u5bf9\u5e94\u4e8e\u590d\u5e73\u9762\u4e0a\u5355\u4f4d\u5706\u4e0a\u7684\u4e00\u70b9\uff0c\u5176\u6781\u5750\u6807\u4e3a ( (1, x) )\u3002\u8fd9\u610f\u5473\u7740 ( \\cos(x) ) \u662f\u5355\u4f4d\u5706\u4e0a\u8be5\u70b9\u7684 x \u5750\u6807\uff0c( \\sin(x) ) \u662f y \u5750\u6807\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 <code>matplotlib<\/code> \u6765\u53ef\u89c6\u5316\u8fd9\u4e00\u51e0\u4f55\u610f\u4e49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cmath<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<p>def plot_euler_formula():<\/p>\n<p>    angles = np.linspace(0, 2 * np.pi, 100)<\/p>\n<p>    points = [cmath.exp(complex(0, angle)) for angle in angles]<\/p>\n<p>    plt.figure()<\/p>\n<p>    plt.plot([p.real for p in points], [p.imag for p in points], label=&#39;e^(ix)&#39;)<\/p>\n<p>    plt.xlabel(&#39;Real Part&#39;)<\/p>\n<p>    plt.ylabel(&#39;Imaginary Part&#39;)<\/p>\n<p>    plt.title(&#39;Visualization of Euler\\&#39;s Formula&#39;)<\/p>\n<p>    plt.legend()<\/p>\n<p>    plt.grid()<\/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>plot_euler_formula()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u56db\u3001\u5e94\u7528\u6b27\u62c9\u516c\u5f0f\u8fdb\u884c\u5085\u91cc\u53f6\u53d8\u6362<\/strong><\/p>\n<\/p>\n<p><p>\u6b27\u62c9\u516c\u5f0f\u5728\u5085\u91cc\u53f6\u53d8\u6362\u4e2d\u6709\u91cd\u8981\u5e94\u7528\u3002\u5085\u91cc\u53f6\u53d8\u6362\u5c06\u65f6\u95f4\u57df\u4fe1\u53f7\u8868\u793a\u4e3a\u9891\u57df\u4fe1\u53f7\uff0c\u9891\u57df\u4fe1\u53f7\u7531\u4e00\u7cfb\u5217\u6b63\u5f26\u6ce2\u548c\u4f59\u5f26\u6ce2\u7ec4\u6210\u3002\u901a\u8fc7\u6b27\u62c9\u516c\u5f0f\uff0c\u6b63\u5f26\u6ce2\u548c\u4f59\u5f26\u6ce2\u53ef\u4ee5\u8868\u793a\u4e3a\u590d\u6307\u6570\u5f62\u5f0f\uff0c\u4ece\u800c\u7b80\u5316\u5085\u91cc\u53f6\u53d8\u6362\u7684\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>def fourier_transform(signal):<\/p>\n<p>    N = len(signal)<\/p>\n<p>    transformed_signal = np.zeros(N, dtype=complex)<\/p>\n<p>    for k in range(N):<\/p>\n<p>        for n in range(N):<\/p>\n<p>            transformed_signal[k] += signal[n] * np.exp(-2j * np.pi * k * n \/ N)<\/p>\n<p>    return transformed_signal<\/p>\n<h2><strong>\u793a\u4f8b\u4fe1\u53f7<\/strong><\/h2>\n<p>signal = np.array([1, 2, 3, 4])<\/p>\n<p>transformed_signal = fourier_transform(signal)<\/p>\n<p>print(f&quot;Original Signal: {signal}&quot;)<\/p>\n<p>print(f&quot;Transformed Signal: {transformed_signal}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4e94\u3001\u6b27\u62c9\u516c\u5f0f\u5728\u91cf\u5b50\u529b\u5b66\u4e2d\u7684\u5e94\u7528<\/strong><\/p>\n<\/p>\n<p><p>\u6b27\u62c9\u516c\u5f0f\u5728\u91cf\u5b50\u529b\u5b66\u4e2d\u4e5f\u6709\u91cd\u8981\u5e94\u7528\uff0c\u7279\u522b\u662f\u5728\u8868\u793a\u548c\u8ba1\u7b97\u91cf\u5b50\u6001\u548c\u91cf\u5b50\u64cd\u4f5c\u65f6\u3002\u91cf\u5b50\u6001\u901a\u5e38\u8868\u793a\u4e3a\u590d\u6570\u632f\u5e45\u7684\u77e2\u91cf\uff0c\u91cf\u5b50\u64cd\u4f5c\u8868\u793a\u4e3a\u5355\u4f4d\u77e9\u9635\u3002\u901a\u8fc7\u6b27\u62c9\u516c\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u7b80\u5316\u8fd9\u4e9b\u590d\u6570\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>def quantum_state_rotation(theta):<\/p>\n<p>    # \u91cf\u5b50\u6001\u65cb\u8f6c\u77e9\u9635<\/p>\n<p>    rotation_matrix = np.array([<\/p>\n<p>        [np.cos(theta\/2), -1j * np.sin(theta\/2)],<\/p>\n<p>        [-1j * np.sin(theta\/2), np.cos(theta\/2)]<\/p>\n<p>    ])<\/p>\n<p>    return rotation_matrix<\/p>\n<p>theta = np.pi \/ 4  # \u65cb\u8f6c\u89d2\u5ea6 \u03c0\/4<\/p>\n<p>rotation_matrix = quantum_state_rotation(theta)<\/p>\n<p>print(f&quot;Rotation Matrix for \u03b8={theta}:\\n{rotation_matrix}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u516d\u3001\u6b27\u62c9\u516c\u5f0f\u5728\u7535\u8def\u5206\u6790\u4e2d\u7684\u5e94\u7528<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u7535\u8def\u5206\u6790\u4e2d\uff0c\u4ea4\u6d41\u7535\u538b\u548c\u7535\u6d41\u901a\u5e38\u8868\u793a\u4e3a\u590d\u6570\u5f62\u5f0f\uff0c\u65b9\u4fbf\u8fdb\u884c\u76f8\u4f4d\u548c\u5e45\u503c\u7684\u8ba1\u7b97\u3002\u901a\u8fc7\u6b27\u62c9\u516c\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u4ea4\u6d41\u4fe1\u53f7\u7684\u5e45\u503c\u548c\u76f8\u4f4d\u76f4\u63a5\u8f6c\u6362\u4e3a\u590d\u6570\u5f62\u5f0f\uff0c\u4ece\u800c\u7b80\u5316\u7535\u8def\u5206\u6790\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cmath<\/p>\n<p>def ac_voltage(amplitude, phase, frequency, t):<\/p>\n<p>    # \u4f7f\u7528\u6b27\u62c9\u516c\u5f0f\u8ba1\u7b97\u4ea4\u6d41\u7535\u538b<\/p>\n<p>    return amplitude * cmath.exp(complex(0, 2 * np.pi * frequency * t + phase))<\/p>\n<p>amplitude = 230  # \u5e45\u503c<\/p>\n<p>phase = np.pi \/ 6  # \u76f8\u4f4d<\/p>\n<p>frequency = 50  # \u9891\u7387 50Hz<\/p>\n<p>time = np.linspace(0, 0.02, 1000)  # \u65f6\u95f4\u8f74<\/p>\n<p>voltages = [ac_voltage(amplitude, phase, frequency, t) for t in time]<\/p>\n<h2><strong>\u53ef\u89c6\u5316\u4ea4\u6d41\u7535\u538b<\/strong><\/h2>\n<p>plt.figure()<\/p>\n<p>plt.plot(time, [v.real for v in voltages], label=&#39;AC Voltage&#39;)<\/p>\n<p>plt.xlabel(&#39;Time (s)&#39;)<\/p>\n<p>plt.ylabel(&#39;Voltage (V)&#39;)<\/p>\n<p>plt.title(&#39;AC Voltage using Euler\\&#39;s Formula&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.grid()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4e03\u3001\u6b27\u62c9\u516c\u5f0f\u5728\u63a7\u5236\u7cfb\u7edf\u4e2d\u7684\u5e94\u7528<\/strong><\/p>\n<\/p>\n<p><p>\u6b27\u62c9\u516c\u5f0f\u5728\u63a7\u5236\u7cfb\u7edf\u4e2d\u4e5f\u6709\u91cd\u8981\u5e94\u7528\uff0c\u7279\u522b\u662f\u7528\u4e8e\u5206\u6790\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u9891\u7387\u54cd\u5e94\u3002\u901a\u8fc7\u5c06\u7cfb\u7edf\u7684\u4f20\u9012\u51fd\u6570\u8868\u793a\u4e3a\u590d\u6570\u5f62\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6b27\u62c9\u516c\u5f0f\u6765\u7b80\u5316\u9891\u7387\u54cd\u5e94\u7684\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import scipy.signal as signal<\/p>\n<p>def system_frequency_response(num, den, w):<\/p>\n<p>    # \u8ba1\u7b97\u7cfb\u7edf\u7684\u9891\u7387\u54cd\u5e94<\/p>\n<p>    w, h = signal.freqs(num, den, w)<\/p>\n<p>    return w, h<\/p>\n<p>num = [1]  # \u5206\u5b50\u591a\u9879\u5f0f\u7cfb\u6570<\/p>\n<p>den = [1, 2, 1]  # \u5206\u6bcd\u591a\u9879\u5f0f\u7cfb\u6570<\/p>\n<p>frequencies = np.logspace(-1, 2, 1000)  # \u9891\u7387\u8303\u56f4<\/p>\n<p>w, h = system_frequency_response(num, den, frequencies)<\/p>\n<h2><strong>\u53ef\u89c6\u5316\u9891\u7387\u54cd\u5e94<\/strong><\/h2>\n<p>plt.figure()<\/p>\n<p>plt.subplot(2, 1, 1)<\/p>\n<p>plt.semilogx(w, 20 * np.log10(abs(h)), label=&#39;Magnitude Response&#39;)<\/p>\n<p>plt.ylabel(&#39;Magnitude (dB)&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.grid()<\/p>\n<p>plt.subplot(2, 1, 2)<\/p>\n<p>plt.semilogx(w, np.angle(h), label=&#39;Phase Response&#39;)<\/p>\n<p>plt.xlabel(&#39;Frequency (rad\/s)&#39;)<\/p>\n<p>plt.ylabel(&#39;Phase (radians)&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.grid()<\/p>\n<p>plt.suptitle(&#39;Frequency Response using Euler\\&#39;s Formula&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u516b\u3001\u6b27\u62c9\u516c\u5f0f\u5728\u4fe1\u53f7\u5904\u7406\u4e2d\u7684\u5e94\u7528<\/strong><\/p>\n<\/p>\n<p><p>\u6b27\u62c9\u516c\u5f0f\u5728\u4fe1\u53f7\u5904\u7406\u4e2d\u7684\u5e94\u7528\u975e\u5e38\u5e7f\u6cdb\uff0c\u7279\u522b\u662f\u7528\u4e8e\u5206\u6790\u548c\u5904\u7406\u9891\u57df\u4fe1\u53f7\u3002\u901a\u8fc7\u6b27\u62c9\u516c\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u7b80\u5316\u6ee4\u6ce2\u5668\u8bbe\u8ba1\u3001\u5377\u79ef\u8ba1\u7b97\u7b49\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import scipy.signal as signal<\/p>\n<p>def lowpass_filter_design(cutoff, fs, order=5):<\/p>\n<p>    # \u8bbe\u8ba1\u4f4e\u901a\u6ee4\u6ce2\u5668<\/p>\n<p>    nyquist = 0.5 * fs<\/p>\n<p>    normal_cutoff = cutoff \/ nyquist<\/p>\n<p>    b, a = signal.butter(order, normal_cutoff, btype=&#39;low&#39;, analog=False)<\/p>\n<p>    return b, a<\/p>\n<p>def apply_filter(b, a, data):<\/p>\n<p>    # \u5e94\u7528\u6ee4\u6ce2\u5668<\/p>\n<p>    return signal.lfilter(b, a, data)<\/p>\n<h2><strong>\u793a\u4f8b\u4fe1\u53f7<\/strong><\/h2>\n<p>fs = 500  # \u91c7\u6837\u9891\u7387<\/p>\n<p>t = np.linspace(0, 1.0, fs)<\/p>\n<p>signal = np.sin(2 * np.pi * 5 * t) + 0.5 * np.sin(2 * np.pi * 50 * t)<\/p>\n<h2><strong>\u8bbe\u8ba1\u5e76\u5e94\u7528\u4f4e\u901a\u6ee4\u6ce2\u5668<\/strong><\/h2>\n<p>cutoff = 10.0  # \u622a\u6b62\u9891\u7387<\/p>\n<p>b, a = lowpass_filter_design(cutoff, fs)<\/p>\n<p>filtered_signal = apply_filter(b, a, signal)<\/p>\n<h2><strong>\u53ef\u89c6\u5316\u539f\u59cb\u4fe1\u53f7\u548c\u6ee4\u6ce2\u540e\u7684\u4fe1\u53f7<\/strong><\/h2>\n<p>plt.figure()<\/p>\n<p>plt.plot(t, signal, label=&#39;Original Signal&#39;)<\/p>\n<p>plt.plot(t, filtered_signal, label=&#39;Filtered Signal&#39;, linestyle=&#39;--&#39;)<\/p>\n<p>plt.xlabel(&#39;Time (s)&#39;)<\/p>\n<p>plt.ylabel(&#39;Amplitude&#39;)<\/p>\n<p>plt.title(&#39;Signal Filtering using Euler\\&#39;s Formula&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.grid()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u793a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u6b27\u62c9\u516c\u5f0f\u5728\u5404\u4e2a\u9886\u57df\u4e2d\u7684\u5e7f\u6cdb\u5e94\u7528\u4e0d\u4ec5\u7b80\u5316\u4e86\u8ba1\u7b97\uff0c\u8fd8\u63d0\u4f9b\u4e86\u6df1\u523b\u7684\u6570\u5b66\u548c\u7269\u7406\u610f\u4e49\u3002\u638c\u63e1\u6b27\u62c9\u516c\u5f0f\u53ca\u5176\u5e94\u7528\uff0c\u5bf9\u4e8e\u6df1\u5165\u7406\u89e3\u548c\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u5177\u6709\u91cd\u8981\u610f\u4e49\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b9e\u73b0\u6b27\u62c9\u516c\u5f0f\u7684\u8ba1\u7b97\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u590d\u6570\u5e93\u6765\u5b9e\u73b0\u6b27\u62c9\u516c\u5f0f\u7684\u8ba1\u7b97\u3002\u6b27\u62c9\u516c\u5f0f\u7684\u5f62\u5f0f\u662f ( e^{ix} = \\cos(x) + i\\sin(x) )\u3002\u53ef\u4ee5\u4f7f\u7528<code>cmath<\/code>\u5e93\u4e2d\u7684<code>exp<\/code>\u3001<code>cos<\/code>\u548c<code>sin<\/code>\u51fd\u6570\u6765\u8ba1\u7b97\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">import cmath\nimport numpy as np\n\ndef euler_formula(x):\n    return cmath.exp(1j * x)\n\n# \u793a\u4f8b\nangle = np.pi \/ 4  # 45\u5ea6\nresult = euler_formula(angle)\nprint(f&quot;e^(i*{angle}) = {result}&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u7a0b\u5e8f\u5c06\u8ba1\u7b97\u7ed9\u5b9a\u89d2\u5ea6\u7684\u6b27\u62c9\u516c\u5f0f\uff0c\u5e76\u8fd4\u56de\u590d\u6570\u5f62\u5f0f\u7684\u7ed3\u679c\u3002<\/p>\n<p><strong>\u4f7f\u7528\u54ea\u4e9b\u5e93\u53ef\u4ee5\u66f4\u65b9\u4fbf\u5730\u5904\u7406\u6b27\u62c9\u516c\u5f0f\u7684\u8ba1\u7b97\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u9664\u4e86<code>cmath<\/code>\u5e93\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>numpy<\/code>\u5e93\u6765\u8fdb\u884c\u66f4\u9ad8\u6548\u7684\u8ba1\u7b97\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u6570\u7ec4\u65f6\u3002<code>numpy<\/code>\u7684<code>exp<\/code>\u3001<code>sin<\/code>\u548c<code>cos<\/code>\u51fd\u6570\u53ef\u4ee5\u5bf9\u6574\u4e2a\u6570\u7ec4\u8fdb\u884c\u64cd\u4f5c\uff0c\u6781\u5927\u5730\u63d0\u9ad8\u4e86\u8ba1\u7b97\u6548\u7387\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\n\nangles = np.linspace(0, 2 * np.pi, 100)  # \u4ece0\u52302\u03c0\u751f\u6210100\u4e2a\u89d2\u5ea6\nresults = np.exp(1j * angles)  # \u8ba1\u7b97\u6bcf\u4e2a\u89d2\u5ea6\u7684\u6b27\u62c9\u516c\u5f0f\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u4f7f\u5f97\u6279\u91cf\u8ba1\u7b97\u53d8\u5f97\u7b80\u5355\u800c\u9ad8\u6548\u3002<\/p>\n<p><strong>\u5982\u4f55\u9a8c\u8bc1\u6b27\u62c9\u516c\u5f0f\u7684\u6b63\u786e\u6027\uff1f<\/strong><br \/>\u53ef\u4ee5\u901a\u8fc7\u7ed8\u5236\u6b27\u62c9\u516c\u5f0f\u7684\u7ed3\u679c\u6765\u9a8c\u8bc1\u5176\u6b63\u786e\u6027\u3002\u4f7f\u7528<code>matplotlib<\/code>\u5e93\u7ed8\u5236\u590d\u6570\u5e73\u9762\u4e2d\u7684\u7ed3\u679c\uff0c\u53ef\u4ee5\u76f4\u89c2\u5730\u770b\u5230\u5176\u4e0e\u5355\u4f4d\u5706\u7684\u5173\u7cfb\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\nangles = np.linspace(0, 2 * np.pi, 100)\nresults = np.exp(1j * angles)\n\nplt.plot(results.real, results.imag)\nplt.title(&quot;Euler&#39;s Formula Visualization&quot;)\nplt.xlabel(&quot;Real Part&quot;)\nplt.ylabel(&quot;Imaginary Part&quot;)\nplt.axis(&#39;equal&#39;)\nplt.grid()\nplt.show()\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u5c55\u793a\u6b27\u62c9\u516c\u5f0f\u5728\u590d\u5e73\u9762\u4e0a\u7684\u56fe\u50cf\uff0c\u9a8c\u8bc1\u5176\u63cf\u8ff0\u7684\u5355\u4f4d\u5706\u7279\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\u6765\u5b9e\u73b0\u6b27\u62c9\u516c\u5f0f\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528cmath\u6a21\u5757\uff0c\u8be5\u6a21\u5757\u652f\u6301\u590d\u6570\u8fd0\u7b97\u3002 \u6b27\u62c9\u516c\u5f0f\u57fa\u672c\u5f62\u5f0f [&hellip;]","protected":false},"author":3,"featured_media":1069665,"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\/1069655"}],"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=1069655"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1069655\/revisions"}],"predecessor-version":[{"id":1069667,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1069655\/revisions\/1069667"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1069665"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1069655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1069655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1069655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}