saif Ali Karim
saif Ali Karim

Reputation: 1

Transformation with texts in equations

The objective is to transform step by step the completing square process with x^2 + 26x = 27. Have been facing errors like the list is out of range and there are overlapping of some characters as well after making some changes. Requesting to give me a script that achieves the objective with simple explanation. Thanks.

class CompletingTheSquare(Scene):
def construct(self):
First equation
equation = MathTex(
"x^2",  #0
"+",    #1
"26x",  #2
"=",    #3
"27"    #4
)
equation.to_edge(UP + LEFT)  # Move to the top-left edge
Display the equation
self.play(Write(equation))
self.wait(2)
2nd step
equation2 = MathTex(
"x^2",      #0
"+",        #1
"26x",      #2      
"+ 169",    #3
"=",        #4
"27",       #5
"+ 169"     #6
)
equation2.align_to(equation, LEFT)  # Move to the same position as equation
equation2.align_to(equation, UP)  # Move to the same position as equation
Group1 (x^2 + 26x) & (= 27)
same_terms1 = VGroup(equation[0], equation[1], equation[2])
same_terms2 = VGroup(equation[3], equation[4])
Group in new (x^2 + 26x) & (= 27)
same_terms3 = VGroup(equation2[0], equation2[1], equation2[2])
same_terms4 = VGroup(equation2[4], equation2[5])
Transform
self.play(
Transform(same_terms1, same_terms3),
Transform(same_terms2, same_terms4)
)
self.play(
Write(equation2[3]),
Write(equation2[6])
)
self.wait()
3 step
equation3 = MathTex(
"x^2",    #0
"+",      #1
"26x"     #2
"+ 169",  #3
"=",      #4
"196"     #5
)
equation3.align_to(equation2, LEFT)  # Move to the same position as the scaled equation
equation3.align_to(equation2, UP)  # Move to the same position as the scaled equation
Group in 2nd step (27 + 169)
same_terms5 = VGroup(equation2[0], equation2[1], equation2[2], equation2[3], equation2[4])
same_terms6 = VGroup(equation3[0], equation3[1], equation3[2], equation3[3], equation3[4])
same_terms7 = VGroup(equation2[5], equation2[6])
Display 169 + 27 becoming 196
self.play(Transform(same_terms5, same_terms6))
self.play(Transform(same_terms7, equation3[5]))
self.wait(1)
Last step
final_equation = MathTex(
"(x + 13)^2",  #0
"=",           #1
"196")         #2
final_equation.align_to(new_equation, LEFT)  
final_equation.align_to(new_equation, UP)  
Grouping x^2 + 26x + 169 = becomes (x+13)^2 =
same_terms8 = VGroup(equation3[0], equation3[1], equation3[2], equation3[3], equation3[4])
same_terms9 = VGroup(final_equation[0], final_equation[1])
Animate the transformation to the new equation and remove the old one
self.play(Transform(same_terms8, sameterms9))
self.play(Transform(equation3[5], final_equation[2]))
self.wait(2)

I'm just not understanding how manim sees the grouping instructions. I tried putting the elements from different equations in the groups, sometimes it did approximately what I wanted. Just want the equations to transformed one after the other correctly.

Upvotes: 0

Views: 28

Answers (0)

Related Questions