{"id":18305,"date":"2022-07-09T13:17:01","date_gmt":"2022-07-09T05:17:01","guid":{"rendered":"http:\/\/www.jdcui.com\/?p=18305"},"modified":"2026-02-20T21:57:09","modified_gmt":"2026-02-20T13:57:09","slug":"python%e7%bc%96%e7%a8%8b%e7%ac%94%e8%ae%b0-python%e7%ac%a6%e5%8f%b7%e8%ae%a1%e7%ae%97-%e6%b1%82%e5%81%8f%e5%be%ae%e5%88%86%e6%96%b9%e7%a8%8b-python-symbolic-computation-solv","status":"publish","type":"post","link":"http:\/\/www.jdcui.com\/?p=18305","title":{"rendered":"[\u7f16\u7a0b\u7b14\u8bb0] Python\u7b26\u53f7\u8ba1\u7b97\u2014\u2014\u6c42\u504f\u5fae\u5206\u65b9\u7a0b (Python symbolic computation &#8212; solving partial differential equations)"},"content":{"rendered":"<p><script id=\"MathJax-script\" src=\"http:\/\/www.jdcui.com\/wp-content\/MathJax_3_1_2\/MathJax-master\/es5\/tex-mml-chtml.js\" async=\"\"><\/script><\/p>\n<p><span style=\"color: #ff00ff; background-color: #ccffcc;\"><strong>\u5b9e\u5e72\u3001\u5b9e\u8df5\u3001\u79ef\u7d2f\u3001\u601d\u8003\u3001\u521b\u65b0\u3002<\/strong><\/span><\/p>\n<hr \/>\n<p>\u6700\u8fd1\u5fd9\uff0c\u653e\u677e\u65f6\u95f4\u5b66\u5b66python\u3002<\/p>\n<p>python\u4e2d\u7684 sympy\u5e93\u662f\u4e00\u6b3e\u7b26\u53f7\u8fd0\u7b97\u5e93\uff0c\u529f\u80fd\u5f3a\u5927\u3002\u8fd9\u91cc\u6d4b\u8bd5\u5176\u6c42\u5fae\u5206\u65b9\u7a0b\u7684\u529f\u80fd\u3002<span style=\"color: #0000ff;\">The sympy library in python is a symbolic operation library with powerful functions. Here we test its function of finding differential equations.<\/span><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u8bd5\u8bd5\u7528sumpy\u6c42\u89e3\u5355\u81ea\u7531\u5ea6\u7c98\u6ede\u963b\u5c3c\u4f53\u7cfb\u81ea\u7531\u632f\u52a8\u7684\u8fd0\u52a8\u65b9\u7a0b\u3002<span style=\"color: #0000ff;\">We can try to use sumpy to solve the equation of motion of the free vibration of a single degree of freedom viscous damped system.<\/span><\/p>\n<p>\u5355\u81ea\u7531\u5ea6\u7c98\u6ede\u963b\u5c3c\u4f53\u7cfb\u7684\u81ea\u7531\u632f\u52a8\u7684\u8fd0\u52a8\u65b9\u7a0b\u53ef\u4ee5\u8868\u793a\u4e3a\u4ee5\u4e0b\u7684\u504f\u5fae\u5206\u65b9\u7a0b\u3002<span style=\"color: #0000ff;\">The equation of motion of the free vibration of a single degree of freedom viscous damping system can be expressed as the following partial differential equation.<\/span><\/p>\n<p><strong>\\[\\ddot u{\\rm{ + 2}}\\zeta {w_n}\\dot u{\\rm{ + }}{w_n}^2u = 0\\]<\/strong><\/p>\n<p>\u5f0f\u4e2d\uff1a\\(u\\)\u662f\u4f4d\u79fb\uff0c\\(\\zeta \\)\u662f\u963b\u5c3c\u6bd4\uff0c\\({w_n}\\)\u662f\u4f53\u7cfb\u7684\u81ea\u632f\u9891\u7387\u3002<\/p>\n<p>\u4ee5\u4e0b\u662fpython\u4ee3\u7801<\/p>\n<pre>from sympy import*\r\ny = symbols('y', cls=Function)\r\nt = symbols('t')\r\n\u03b6 = symbols('\u03b6')\r\nw = symbols('w')\r\neq = Eq(y(t).diff(t, t)+2*\u03b6*w*y(t).diff(t)+w*w*y(t), 0)\r\nprint(dsolve(eq, y(t)) )<\/pre>\n<p>\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n<p><code>Eq(y(t), C1*exp(t*w*(-\u03b6 - sqrt(\u03b6**2 - 1))) + C2*exp(t*w*(-\u03b6 + sqrt(\u03b6**2 - 1))))<\/code><\/p>\n<p>\u5199\u6210\u516c\u5f0f\u7684\u5f62\u5f0f\u5373\u4e3a\uff1a<\/p>\n<p>\\[u(t) = {C_1}{e^{{w_n}t( &#8211; \\zeta &#8211; \\sqrt {{\\zeta ^2} &#8211; 1} )}} + {C_2}{e^{{w_n}t( &#8211; \\zeta + \\sqrt {{\\zeta ^2} &#8211; 1} )}}\\]\n<p>\u8be5\u516c\u5f0f\u53ef\u8fdb\u4e00\u6b65\u5199\u6210\u4ee5\u4e0b\u5f62\u5f0f\uff0c<\/p>\n<p>\\[u(t) = {e^{ &#8211; \\zeta {w_n}t}}\\left[ {{C_1}{e^{ &#8211; {w_n}t\\sqrt {{\\zeta ^2} &#8211; 1} }} + {C_2}{e^{{w_n}t\\sqrt {{\\zeta ^2} &#8211; 1} }}} \\right]\\]\n<p>\u7531\u4e0a\u53ef\u89c1\uff0c\u963b\u5c3c\u8870\u51cf\u9879\\({e^{ &#8211; \\zeta {w_n}t}}\\)\u5c31\u51fa\u73b0\u4e86\uff0c\u8fdb\u4e00\u6b65\u53ef\u6839\u636e\u963b\u5c3c\u6bd4\u03b6\u662f\u5927\u4e8e1\u6216\u8005\u5c0f\u4e8e1\u6216\u8005\u7b49\u4e8e1\uff0c\u5bf9\u4e0a\u8ff0\u516c\u5f0f\u8fdb\u884c\u6574\u7406\uff0c\u5373\u53ef\u5f97\u5230\u8fc7\u963b\u5c3c\u3001\u4e34\u754c\u963b\u5c3c\u53ca\u6b20\u963b\u5c3c\u4f53\u7cfb\u7684\u81ea\u7531\u632f\u52a8\u8fd0\u52a8\u65b9\u7a0b\u3002<\/p>\n<hr \/>\n<p style=\"text-align: center;\"><strong><div  class=\"thumbs-rating-container\" id=\"thumbs-rating-18305\" data-content-id=\"18305\"><button class=\"thumbs-rating-up thumbs-rating-voted\" onclick=\"thumbs_rating_vote(18305, 1);\">Vote Up +4<\/button> <button class=\"thumbs-rating-down\" onclick=\"thumbs_rating_vote(18305, 2);\">Vote Down -0<\/button><span class=\"thumbs-rating-already-voted\">You already voted!<\/span><\/div><\/strong><\/p>\n<ul style=\"list-style-type: square;\">\n<li><strong>\u76f8\u5173\u8bdd\u9898 (<span style=\"color: #000080;\"> Related Topics<\/span>)<\/strong><\/li>\n<\/ul>\n<p><strong><span style=\"color: #000000;\">[01].<\/span>\u00a0<a href=\"http:\/\/www.jdcui.com\/?p=6404\" target=\"_blank\" rel=\"noopener\">Python \u51fa\u73b0\u201dinvalid literal for int() with base 10: \\xef\\xbb\\xbf0\u2033 \u9519\u8bef<\/a><\/strong><\/p>\n<p><strong><span style=\"color: #000000;\">[02].<\/span>\u00a0<a href=\"http:\/\/www.jdcui.com\/?p=6408\" target=\"_blank\" rel=\"noopener\">[\u7f16\u7a0b\u7b14\u8bb0] Tuple in Python [Python\u4e2d\u7684\u5143\u7ec4]<\/a><\/strong><\/p>\n<p><strong><span style=\"color: #000000;\">[03].<\/span>\u00a0<a title=\"[Python][\u7f16\u7a0b][\u7b14\u8bb0] Python\u6d77\u9f9f\u7ed8\u56fe \u2014\u2014 \u591a\u8fb9\u5f62 Polygon\" href=\"http:\/\/www.jdcui.com\/?p=18283\" target=\"_blank\" rel=\"noopener\">[Python][\u7f16\u7a0b][\u7b14\u8bb0] Python\u6d77\u9f9f\u7ed8\u56fe \u2014\u2014 \u591a\u8fb9\u5f62 Polygon<\/a><\/strong><\/p>\n<p><strong><span style=\"color: #000000;\">[04].<\/span>\u00a0<a title=\"[Python][\u7f16\u7a0b][\u7b14\u8bb0] Python\u7b26\u53f7\u8ba1\u7b97\u2014\u2014\u6c42\u504f\u5fae\u5206\u65b9\u7a0b (Python symbolic computation \u2014 solving partial differential equations)\" href=\"http:\/\/www.jdcui.com\/?p=18305\" target=\"_blank\" rel=\"noopener\">[Python][\u7f16\u7a0b][\u7b14\u8bb0] Python\u7b26\u53f7\u8ba1\u7b97\u2014\u2014\u6c42\u504f\u5fae\u5206\u65b9\u7a0b (Python symbolic computation \u2014 solving partial differential equations)<\/a><\/strong><\/p>\n<ul style=\"list-style-type: square;\">\n<li style=\"text-align: left;\"><strong>\u5fae\u4fe1\u516c\u4f17\u53f7\u00a0(<span style=\"color: #000080;\">\u00a0Wechat\u00a0Subscription<\/span>)<\/strong><\/li>\n<\/ul>\n<p><a href=\"http:\/\/www.jdcui.com\/wp-content\/uploads\/2017\/01\/QRCODE.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3636\" src=\"http:\/\/www.jdcui.com\/wp-content\/uploads\/2017\/01\/QRCODE.jpg\" alt=\"WeChat_QRCode\" width=\"250\" height=\"255\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>\u6b22\u8fce\u5173\u6ce8\u00a0\u201c<span style=\"color: #ff00ff;\">\u7ed3\u6784\u4e4b\u65c5<\/span>\u201d\u00a0\u5fae\u4fe1\u516c\u4f17\u53f7<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9e\u5e72\u3001\u5b9e\u8df5\u3001\u79ef\u7d2f\u3001\u601d\u8003\u3001\u521b\u65b0\u3002 \u6700\u8fd1\u5fd9\uff0c\u653e\u677e\u65f6\u95f4\u5b66\u5b66python\u3002 python\u4e2d\u7684 sympy\u5e93\u662f\u4e00\u6b3e\u7b26\u53f7\u8fd0\u7b97\u5e93\uff0c\u529f\u80fd\u5f3a\u5927\u3002\u8fd9\u91cc\u6d4b\u8bd5\u5176\u6c42\u5fae\u5206\u65b9\u7a0b\u7684\u529f\u80fd\u3002The sympy library in python is a symbolic operation library with powerful functions. Here we test its function of finding differential equations. \u6211\u4eec\u53ef\u4ee5\u8bd5\u8bd5\u7528sumpy\u6c42\u89e3\u5355\u81ea\u7531\u5ea6\u7c98\u6ede\u963b\u5c3c\u4f53\u7cfb\u81ea\u7531\u632f\u52a8\u7684\u8fd0\u52a8\u65b9\u7a0b\u3002We can try to use &#8230;<\/p>\n","protected":false},"author":1,"featured_media":18327,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[382,21,1087,5],"tags":[3418,3417,3409,3410,3407,3406,3416,3412,427,3413,3408,3415,3414,3411],"class_list":["post-18305","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-","category-programming","category-structural-analysis-","category-structural-engineering","tag-critical-damping","tag-overdamping","tag-partial-differential-equations","tag-pde","tag-symbolic-mathematics","tag-sympy","tag-underdamping","tag-3412","tag-427","tag-3413","tag-3408","tag-3415","tag-3414","tag-3411"],"aioseo_notices":[],"views":2700,"_links":{"self":[{"href":"http:\/\/www.jdcui.com\/index.php?rest_route=\/wp\/v2\/posts\/18305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.jdcui.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jdcui.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jdcui.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jdcui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18305"}],"version-history":[{"count":0,"href":"http:\/\/www.jdcui.com\/index.php?rest_route=\/wp\/v2\/posts\/18305\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.jdcui.com\/index.php?rest_route=\/wp\/v2\/media\/18327"}],"wp:attachment":[{"href":"http:\/\/www.jdcui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jdcui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18305"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jdcui.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}