{"id":4458,"date":"2024-09-22T20:08:46","date_gmt":"2024-09-23T04:08:46","guid":{"rendered":"https:\/\/crm270s.abramjmeister.com\/?p=4458"},"modified":"2024-09-22T20:08:46","modified_gmt":"2024-09-23T04:08:46","slug":"trapezoid-animation-production","status":"publish","type":"post","link":"https:\/\/crm270s.mycpamytax.com\/?p=4458","title":{"rendered":"trapezoid ANIMATION production"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>import numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.animation import FuncAnimation, FFMpegWriter\n\n# Define the new function to integrate: x * log(x)\ndef func(x):\n    # Avoid log(0) by returning 0 when x is 0\n    return np.where(x == 0, 0, x * np.log(x))\n\n# Set up the figure and axis\nfig, ax = plt.subplots()\na, b = 0.01, 2  # Define the interval &#91;a, b] avoiding 0 to prevent log(0) issues\nx_vals = np.linspace(a, b, 1000)\nax.plot(x_vals, func(x_vals), 'r', label=r'$x \\log(x)$')\nax.set_ylim(-1, 2)\nax.set_xlim(a, b)\n\n# Title and labels\nax.set_title('Numerical Integration Process using Trapezoidal Rule for $x \\log(x)$')\nax.set_xlabel('x')\nax.set_ylabel('f(x)')\nax.legend()\n\n# Fill area under the curve (for animation purposes)\npatches = &#91;]  # To store the artists\n\n# Define the number of trapezoids to draw\nn_trapezoids = 50\nx_points = np.linspace(a, b, n_trapezoids + 1)\ny_points = func(x_points)\n\n# Function to update the animation at each step\ndef update(frame):\n    global patches\n    for patch in patches:\n        patch.remove()\n    patches = &#91;]\n    \n    # Plot the new trapezoid for the current frame\n    if frame > 0:\n        patch = ax.fill_between(&#91;x_points&#91;frame-1], x_points&#91;frame]], &#91;y_points&#91;frame-1], y_points&#91;frame]], \n                                color='lightblue', alpha=0.5)\n        patches.append(patch)  # Store the artist\n    \n    # Redraw the whole plot with current trapezoids filled\n    for i in range(1, frame):\n        patch = ax.fill_between(&#91;x_points&#91;i-1], x_points&#91;i]], &#91;y_points&#91;i-1], y_points&#91;i]], color='lightblue', alpha=0.5)\n        patches.append(patch)  # Store each trapezoid artist\n\n# Create the animation\nani = FuncAnimation(fig, update, frames=range(1, n_trapezoids+1), interval=200, repeat=False)\n\n# Save the animation as an MP4 file using FFmpeg\nmp4_writer = FFMpegWriter(fps=10, metadata=dict(artist='Me'), bitrate=1800)\nani.save(\"integration_animation_xlogx.mp4\", writer=mp4_writer)\n\n# Optionally, show the animation (if you still want to display it)\nplt.show()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[26],"tags":[],"class_list":["post-4458","post","type-post","status-publish","format-standard","hentry","category-codes"],"_links":{"self":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts\/4458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4458"}],"version-history":[{"count":0,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts\/4458\/revisions"}],"wp:attachment":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}