{"id":2588,"date":"2024-03-19T09:46:37","date_gmt":"2024-03-19T09:46:37","guid":{"rendered":"https:\/\/favtutor.com\/articles\/?p=2588"},"modified":"2024-03-19T16:37:29","modified_gmt":"2024-03-19T16:37:29","slug":"math-animations-claude-3-manim-tutorial","status":"publish","type":"post","link":"https:\/\/favtutor.com\/articles\/math-animations-claude-3-manim-tutorial\/","title":{"rendered":"Create Math Animations with Claude 3 and Manim [Tutorial]"},"content":{"rendered":"\n<p>Claude 3&#8217;s latest feature lets users create animations thus allowing them to explore and understand complicated mathematics topics using visuals. Here&#8217;s a guide to creating Maths animations like Sphere Theorem, Distance Formula, and Riemann Sum using Claude 3 and Manim!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Claude 3&#8217;s Math Animations Feature<\/strong><\/h2>\n\n\n\n<p><strong>Claude 3 has introduced support for Manim Animation Engine, designed specifically for mathematical animations.<\/strong><\/p>\n\n\n\n<p>Manim is an open-source, community-maintained Python library that is used for creating explanatory math videos using animations and writing just a few lines of code. With this integration, users can understand various complex problems in mathematics using simple but stunning visuals.<\/p>\n\n\n\n<p>A video showing the animation of the Pythagoras theorem generated by Claude is causing waves all over the internet. You can take a look at how Claude functions with Manim in the video below:<\/p>\n\n\n\n<div align=\"center\"><blockquote class=\"twitter-tweet\" data-media-max-width=\"560\"><p lang=\"en\" dir=\"ltr\">Ok, this is amazing.<br><br>I asked Claude 3 to generate an animation of the Pythagorean Theorem and this is what it created: <a href=\"https:\/\/t.co\/bM4oDbyEbv\" target=\"_blank\">pic.twitter.com\/bM4oDbyEbv<\/a><\/p>&mdash; Alvaro Cintas (@dr_cintas) <a href=\"https:\/\/twitter.com\/dr_cintas\/status\/1767569938217087199?ref_src=twsrc%5Etfw\" target=\"_blank\" rel=\"noopener\">March 12, 2024<\/a><\/blockquote> <script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/div>\n\n\n\n<p>The user asked Claude to explain the Pythagoras theorem with the help of visuals. Claude then uses the manim library and provides the user with a simple explanation of the theorem in a short video.<\/p>\n\n\n\n<p>It excels at designing animations for any mathematical concept, although its accuracy may not be flawless. The possible use cases will be to create educational videos, presentations, visualization of algorithms, and simulations. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Generate Animations with Claude 3?<\/strong><\/h2>\n\n\n\n<p>Claude AI is slowly sending out its new Manim update to all users. For those who have access to Manim in Claude, this is how they can use it:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to <a href=\"https:\/\/claude.ai\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">claude.ai<\/a>. <\/li>\n\n\n\n<li>Enter the prompt in the following template pattern:\n<ul class=\"wp-block-list\">\n<li><strong>Mathematical Expression\/Concept:<\/strong> Animate the process of finding the derivative of the function f(x) = x^3 + 2x^2 &#8211; 3x using the power rule.<\/li>\n\n\n\n<li><strong>Additional Context:<\/strong> Show the step-by-step process of applying the power rule to each term of the function and Highlight the original function and the resulting derivative function.<\/li>\n\n\n\n<li><strong>Specific Requests:<\/strong> Use a clean and minimalist style with a white background and Color-code the different terms and coefficients for clarity.<\/li>\n\n\n\n<li><strong>Desired Output:<\/strong> Please provide the complete Python script using <code>manim<\/code> to create the animation.<\/li>\n\n\n\n<li><strong>Additional Requirements:<\/strong> Include instructions on how to run the animation locally or on platforms like Google Colab.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Claude provides the Python code for the required concept.<\/li>\n<\/ol>\n\n\n\n<p>As of now, Claude doesn\u2019t have support to render animations just yet, there are two ways to visualize the animation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Run the Code Locally<\/strong><\/h3>\n\n\n\n<p>First, Install the Manim library by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install manimlib<\/code><\/pre>\n\n\n\n<p>Create the Python script \u2018script.py\u2019 and import the necessary classes from the manim lib. For example:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from manim import *\n\nclass EquationAnimation(Scene):\n    def construct(self):\n        equation = MathTex(r&quot;x^2 + y^2 = z^2&quot;)\n        self.play(Write(equation))\n        self.wait()<\/pre><\/div>\n\n\n\n<p>To render the animation and generate the video, run the following command in the command prompt or terminal on your local machine<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python -m manim path\/to\/your\/script.py EquationAnimation -pl<\/code><\/pre>\n\n\n\n<p>To run this animation, you can find the video in your current working directory in the <em>media\/videos\/ <\/em>directory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>On a platform like Google Colaboratory<\/strong><\/h3>\n\n\n\n<p>Upload the Python script to Google Colab or create a new notebook.<\/p>\n\n\n\n<p>Install the following dependencies for running the manim animation.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>!apt-get install -qq sox libcairo2 libpango1.0-dev ffmpeg &gt; \/dev\/null\n!pip install -qq manim<\/code><\/pre>\n\n\n\n<p>Import the necessary classes from Manim.<\/p>\n\n\n\n<p>To render the animation, run the following code in a code cell. The render() method runs the animation and saves the video on Google Colab.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from manim import *\n\n# Define your Scene class\nclass EquationAnimation(Scene):\n    def construct(self):\n        equation = MathTex(r&quot;x^2 + y^2 = z^2&quot;)\n        self.play(Write(equation))\n        self.wait()\n\n# Render the animation\nscene = EquationAnimation()\nscene.render()<\/pre><\/div>\n\n\n\n<p>To display the rendered video, you can use the IPython.display module in Colab or download the video from the media\/videos\/ directory in the folder structure.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from IPython.display import Video\n\nVideo(\"EquationAnimation.mp4\")<\/code><\/pre>\n\n\n\n<p>Let\u2019s take a look at a few examples!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example 1: Sphere Theorem<\/strong><\/h2>\n\n\n\n<p>In this example, we will try to animate the popular Sphere Theorem. The Sphere Theorem states that The surface area of a sphere is equal to the area of its circumscribing cylinder&#8217;s curved surface. <\/p>\n\n\n\n<p><strong>Prompt:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nAnimate the process of the Sphere theorem in mathematics\nShow the step by step process of the theorem\nUse a clean and minimalist style with a white background\nColor-code the variables appropriately\nPlease Provide the complete Python Script using 'manim' to create the animation\nInclude appropriate code so that I can run it in Google Colab<\/code><\/pre>\n\n\n\n<p><strong>Response:<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"837\" height=\"119\" src=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output.png\" alt=\"Sphere Theorem Claude 3 Output\" class=\"wp-image-2593\" srcset=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output.png 837w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-300x43.png 300w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-768x109.png 768w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-750x107.png 750w\" sizes=\"(max-width: 837px) 100vw, 837px\" \/><\/figure>\n<\/div>\n\n\n<p><strong>Python code:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from manim import *\n\nclass Disc(VGroup):\n    def __init__(self, radius, **kwargs):\n        super().__init__(**kwargs)\n        self.radius = radius\n        circle = Circle(radius=radius, **kwargs)\n        self.add(circle)\n\nclass SphereTheorem(Scene):\n    def construct(self):\n        # Create a sphere\n        sphere = Sphere(radius=2, resolution=(24, 48), fill_opacity=0.5, fill_color=BLUE_E, stroke_width=4, stroke_color=WHITE)\n        self.play(DrawBorderThenFill(sphere))\n        self.wait()\n\n        # Label the radius\n        r = MathTex(&quot;r&quot;, color=GREEN_B).next_to(sphere, LEFT)\n        self.play(Write(r))\n        self.wait()\n\n        # Show the equation\n        equation = MathTex(r&quot;V = \\frac{4}{3}\\pi r^3&quot;, color=WHITE).to_edge(UP)\n        self.play(Write(equation))\n        self.wait()\n\n        # Create a cylinder with the same radius and height\n        cylinder = Cylinder(height=4, radius=2, resolution=(24, 48), fill_opacity=0.5, fill_color=YELLOW_D, stroke_width=4, stroke_color=WHITE)\n        self.play(DrawBorderThenFill(cylinder))\n        self.wait()\n\n        # Label the height\n        h = MathTex(&quot;h&quot;, color=RED_B).next_to(cylinder, RIGHT)\n        self.play(Write(h))\n        self.wait()\n\n        # Show the equation for the cylinder's volume\n        cylinder_equation = MathTex(r&quot;V = \\pi r^2 h&quot;, color=WHITE).next_to(equation, DOWN)\n        self.play(Write(cylinder_equation))\n        self.wait()\n\n        # Slice the sphere into horizontal discs\n        discs = VGroup(*[\n            Disc(radius=2 * np.cos(theta), fill_opacity=0.5, fill_color=PURPLE_A, stroke_width=2, stroke_color=WHITE)\n            for theta in np.linspace(0, PI \/ 2, 12)\n        ])\n        self.play(DrawBorderThenFill(discs))\n        self.wait()\n\n        # Rearrange the discs to form a cylinder\n        discs.arrange(DOWN, buff=0)\n        self.play(Transform(discs, cylinder))\n        self.wait()\n\n        # Show the relationship between the sphere's volume and the cylinder's volume\n        relationship = MathTex(r&quot;\\frac{V_{\\text{sphere}}}{V_{\\text{cylinder}}} = \\frac{4}{3}&quot;, color=WHITE).next_to(cylinder_equation, DOWN)\n        self.play(Write(relationship))\n        self.wait()\n\n# To run the animation locally\n# with tempconfig({&quot;quality&quot;: &quot;low_quality&quot;}):\n#     scene = SphereTheorem()\n#     scene.render()\n\n# To run the animation on Google Colab\nscene = SphereTheorem()\nscene.render()<\/pre><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"837\" height=\"495\" src=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-2.png\" alt=\"Sphere Theorem Claude 3 Output 2\" class=\"wp-image-2594\" srcset=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-2.png 837w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-2-300x177.png 300w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-2-768x454.png 768w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-2-750x444.png 750w\" sizes=\"(max-width: 837px) 100vw, 837px\" \/><\/figure>\n<\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"885\" height=\"672\" src=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-3.png\" alt=\"Sphere Theorem Claude 3 Output 3\" class=\"wp-image-2595\" srcset=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-3.png 885w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-3-300x228.png 300w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-3-768x583.png 768w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-3-750x569.png 750w\" sizes=\"(max-width: 885px) 100vw, 885px\" \/><\/figure>\n<\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"883\" height=\"355\" src=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-4.png\" alt=\"Sphere Theorem Claude 3 Output 4\" class=\"wp-image-2596\" srcset=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-4.png 883w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-4-300x121.png 300w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-4-768x309.png 768w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Sphere-Theorem-Claude-3-Output-4-750x302.png 750w\" sizes=\"(max-width: 883px) 100vw, 883px\" \/><\/figure>\n<\/div>\n\n\n<p>To access the video, look into Colab\u2019s folder structure:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"370\" height=\"453\" src=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Claude-3-Folder.png\" alt=\"Claude 3 Folder\" class=\"wp-image-2597\" srcset=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Claude-3-Folder.png 370w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Claude-3-Folder-245x300.png 245w\" sizes=\"(max-width: 370px) 100vw, 370px\" \/><\/figure>\n<\/div>\n\n\n<p>Here is the video:<\/p>\n\n\n\n<div align=\"center\"><blockquote class=\"twitter-tweet\" data-media-max-width=\"560\"><p lang=\"en\" dir=\"ltr\">Here is an animation of the Sphere Theorem: <a href=\"https:\/\/t.co\/6BfRVIdeOh\" target=\"_blank\">pic.twitter.com\/6BfRVIdeOh<\/a><\/p>&mdash; dhruv (@_dhruvvvvv_) <a href=\"https:\/\/twitter.com\/_dhruvvvvv_\/status\/1770020014600695986?ref_src=twsrc%5Etfw\" target=\"_blank\" rel=\"noopener\">March 19, 2024<\/a><\/blockquote> <script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/div>\n\n\n\n<p>We observe that although it provides a partial description of the theorem, it fails to deliver a comprehensive explanation as requested by the user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example 2: Distance Formula<\/strong><\/h2>\n\n\n\n<p>Another way to understand a math problem is by providing Claude with the problem&#8217;s image and the prompt. Claude analyses the image and tries to give the best possible animation for it.<\/p>\n\n\n\n<p>Let\u2019s take an example of the distance formula. The distance formula is used to find the distance between any two points. <\/p>\n\n\n\n<p><strong>Prompt:<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"825\" height=\"513\" src=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula.png\" alt=\"Distance Formula\" class=\"wp-image-2598\" srcset=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula.png 825w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-300x187.png 300w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-768x478.png 768w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-750x466.png 750w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/figure>\n<\/div>\n\n\n<p>Response:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from manim import *\n\nclass DistanceFormula(Scene):\n   def construct(self):\n       # Set up the scene\n       self.camera.background_color = BLACK\n       axes = Axes(\n           x_range=[-4, 4, 1],\n           y_range=[-3, 3, 1],\n           x_length=6,\n           y_length=5,\n           tips=False,\n       )\n       axes_labels = axes.get_axis_labels()\n       self.play(Create(axes), Write(axes_labels))\n\n       # Create points (x1, y1) and (x2, y2)\n       point1 = Dot([-2, 1, 0], radius=0.08, color=RED)\n       point2 = Dot([1, -1, 0], radius=0.08, color=GREEN)\n       point1_label = MathTex(&quot;(x_1, y_1)&quot;, color=RED).next_to(point1, LEFT)\n       point2_label = MathTex(&quot;(x_2, y_2)&quot;, color=GREEN).next_to(point2, RIGHT)\n\n       # Draw the distance line between the points\n       distance_line = Line(point1.get_center(), point2.get_center(), color=YELLOW)\n\n       # Show the distance formula\n       formula = MathTex(\n           r&quot;d = \\sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}&quot;,\n           color=BLUE\n       ).to_edge(UP)\n\n       # Substitute the point coordinates into the formula\n       substituted_formula = MathTex(\n           r&quot;d = \\sqrt{(1 - (-2))^2 + (-1 - 1)^2}&quot;,\n           color=PURPLE\n       ).next_to(formula, DOWN)\n\n       # Evaluate the formula\n       result = MathTex(r&quot;d = \\sqrt{9 + 4} = \\sqrt{13}&quot;, color=GREEN).next_to(substituted_formula, DOWN)\n\n       # Animate objects\n       self.play(\n           DrawBorderThenFill(point1),\n           DrawBorderThenFill(point2),\n           Write(point1_label),\n           Write(point2_label),\n           DrawBorderThenFill(distance_line),\n           Write(formula),\n           Write(substituted_formula),\n           Write(result)\n       )\n       self.wait()\n\n# Run the scene\nscene = DistanceFormula()\nscene.render()<\/pre><\/div>\n\n\n\n<p><strong>Video:<\/strong><\/p>\n\n\n\n<div align=\"center\"><blockquote class=\"twitter-tweet\" data-media-max-width=\"560\"><p lang=\"en\" dir=\"ltr\">I also provided it with the Distance Formula\u2019s image and got this animation for it: <a href=\"https:\/\/t.co\/p8CaV1zmXb\" target=\"_blank\">pic.twitter.com\/p8CaV1zmXb<\/a><\/p>&mdash; dhruv (@_dhruvvvvv_) <a href=\"https:\/\/twitter.com\/_dhruvvvvv_\/status\/1770020691179634794?ref_src=twsrc%5Etfw\" target=\"_blank\" rel=\"noopener\">March 19, 2024<\/a><\/blockquote> <script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/div>\n\n\n\n<p>The output we got from Claude 3 is:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"746\" height=\"693\" src=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-Claude-3-Output.png\" alt=\"Distance Formula Claude 3 Output\" class=\"wp-image-2599\" srcset=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-Claude-3-Output.png 746w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-Claude-3-Output-300x279.png 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/figure>\n<\/div>\n\n\n<p>However, all the animations still aren\u2019t entirely perfect. Some animations are not very descriptive and don\u2019t convey a lot of meaning to the user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example 3: Riemann Sum Theorem<\/strong><\/h2>\n\n\n\n<p>Let us consider the Riemann Sum theorem. This theorem provides a method for approximating the area under a curve by dividing the interval into smaller subintervals and summing the areas of corresponding rectangles. Claude was prompted with the sample image and told to explain the theorem.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"836\" height=\"559\" src=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-Issues.png\" alt=\"Distance Formula Issues\" class=\"wp-image-2600\" srcset=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-Issues.png 836w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-Issues-300x201.png 300w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-Issues-768x514.png 768w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-Issues-750x501.png 750w\" sizes=\"(max-width: 836px) 100vw, 836px\" \/><\/figure>\n<\/div>\n\n\n<p><strong>Python code:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from manim import *\n\nclass RiemannSum(Scene):\n    def construct(self):\n        # Create the axes\n        axes = Axes(\n            x_range=[0, 4, 1],\n            y_range=[0, 5, 1],\n            x_length=6,\n            y_length=6,\n            axis_config={&quot;include_tip&quot;: False},\n            tips=False,\n        )\n        self.play(Create(axes))\n        self.wait()\n\n        # Define the function\n        func = lambda x: 4 * (1 - x \/ 4) ** 2\n        curve = axes.plot(func, color=BLUE)\n        self.play(Create(curve))\n        self.wait()\n\n        # Show the Riemann Sum equation\n        riemann_sum_equation = MathTex(r&quot;\\sum_{i=1}^{n} f(x_i^*) \\Delta x&quot;, color=WHITE).to_edge(UP)\n        self.play(Write(riemann_sum_equation))\n        self.wait()\n\n        # Create the rectangles\n        rectangles = VGroup()\n        n = 4  # Number of rectangles\n        dx = 4 \/ n  # Width of each rectangle\n        for i in range(n):\n            x = i * dx\n            y = func(x)\n            rect = Rectangle(\n                width=dx,\n                height=y,\n                stroke_color=WHITE,\n                fill_color=YELLOW,\n                fill_opacity=0.5,\n            )\n            rect.move_to(axes.c2p(x + dx \/ 2, y \/ 2))\n            rectangles.add(rect)\n\n        self.play(DrawBorderThenFill(rectangles))\n        self.wait()\n\n        # Animate the rectangles\n        for rect in rectangles:\n            self.play(rect.animate.stretch_to_fit_height(axes.p2c(rect.get_center())[1]), run_time=0.5)\n            self.wait(0.5)\n\n        self.wait(2)\n\n# To run the animation locally\n# with tempconfig({&quot;quality&quot;: &quot;low_quality&quot;}):\n#     scene = RiemannSum()\n#     scene.render()\n\n# To run the animation on Google Colab\nscene = RiemannSum()\nscene.render()\n<\/pre><\/div>\n\n\n\n<p>Here&#8217;s the response we got:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"828\" height=\"442\" src=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-Claude-3-Output-2.png\" alt=\"Distance Formula Claude 3 Output 2\" class=\"wp-image-2602\" srcset=\"https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-Claude-3-Output-2.png 828w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-Claude-3-Output-2-300x160.png 300w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-Claude-3-Output-2-768x410.png 768w, https:\/\/favtutor.com\/articles\/wp-content\/uploads\/2024\/03\/Distance-Formula-Claude-3-Output-2-750x400.png 750w\" sizes=\"(max-width: 828px) 100vw, 828px\" \/><\/figure>\n<\/div>\n\n\n<p>Claude\u2019s explained the theorem and gave the correct formula but the animation couldn\u2019t provide any clarity. This is not useful for the user who wants a clear explanation of the theorem.<\/p>\n\n\n\n<div align=\"center\"><blockquote class=\"twitter-tweet\" data-media-max-width=\"560\"><p lang=\"en\" dir=\"ltr\">I then provided it with a sample image and asked to explain the theorem (Riemann Sum): <a href=\"https:\/\/t.co\/ViKcY8Y7Mn\" target=\"_blank\">pic.twitter.com\/ViKcY8Y7Mn<\/a><\/p>&mdash; dhruv (@_dhruvvvvv_) <a href=\"https:\/\/twitter.com\/_dhruvvvvv_\/status\/1770021078087389628?ref_src=twsrc%5Etfw\" target=\"_blank\" rel=\"noopener\">March 19, 2024<\/a><\/blockquote> <script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/div>\n\n\n\n<p>While not always accurate, these animations are still useful in explaining concepts to users. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>AI&#8217;s mastery of math algorithms, pattern recognition, data understanding, and precision in generating animations is a process that will still require time. Nevertheless, this addition to Claude will revolutionize automation within the mathematics industry by enabling the creation of diverse tutorials with minimal input<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a tutorial to create math animations with Claude 3. We tried to animate the Sphere Theorem, Distance Formula, and Riemann Sum.<\/p>\n","protected":false},"author":18,"featured_media":2617,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jnews-multi-image_gallery":[],"jnews_single_post":null,"jnews_primary_category":{"id":"","hide":""},"footnotes":""},"categories":[57],"tags":[56,90,59,116],"class_list":["post-2588","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","tag-ai","tag-claude","tag-generative-ai","tag-manim"],"_links":{"self":[{"href":"https:\/\/favtutor.com\/articles\/wp-json\/wp\/v2\/posts\/2588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/favtutor.com\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/favtutor.com\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/favtutor.com\/articles\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/favtutor.com\/articles\/wp-json\/wp\/v2\/comments?post=2588"}],"version-history":[{"count":8,"href":"https:\/\/favtutor.com\/articles\/wp-json\/wp\/v2\/posts\/2588\/revisions"}],"predecessor-version":[{"id":2659,"href":"https:\/\/favtutor.com\/articles\/wp-json\/wp\/v2\/posts\/2588\/revisions\/2659"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/favtutor.com\/articles\/wp-json\/wp\/v2\/media\/2617"}],"wp:attachment":[{"href":"https:\/\/favtutor.com\/articles\/wp-json\/wp\/v2\/media?parent=2588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/favtutor.com\/articles\/wp-json\/wp\/v2\/categories?post=2588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/favtutor.com\/articles\/wp-json\/wp\/v2\/tags?post=2588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}