Replies: 1 comment
-
Use the #https://github.com/ManimCommunity/manim/discussions/4139#discussion-7877358
from manim import *
pixel_width = 450
pixel_height = 800
config.frame_width=20
config.frame_height=15
class TemperatureDistribution(Scene):
def construct(self):
# initialize the parameter value trackers
T_l = ValueTracker(300) # Left temperature (in Kelvin)
T_r = ValueTracker(400) # Right temperature (in Kelvin)
q = ValueTracker(100) # Heat generation rate (W/m^3)
k = ValueTracker(50) # Thermal conductivity (W/m·K)
L = ValueTracker(10) # Length of the rod (meters)
# Define the temperature function T(x)
def T(x,T_l,T_r,q,k,L):
return T_l+(0.5*(L**2)*(q/k)+T_r-T_l)*(x/L)-(0.5*L**2)*(q/k)*(x/L)**2
axes = Axes(
x_range=[0, 10, 1],
y_range=[0, 700 ,50],
axis_config={"include_numbers": True},
)
x_label = axes.get_x_axis_label("distance, x [m]") # Label for the x-axis
y_label = axes.get_y_axis_label("Temperature, T(x) [K]") # Label for the y-axis
# Create the graph of the temperature distribution function T(x)
graph = axes.plot(lambda x: T(x,T_l.get_value(),T_r.get_value(),q.get_value(),k.get_value(),L.get_value()))
graph.add_updater(
lambda m : m.become(
axes.plot(lambda x: T(x,T_l.get_value(),T_r.get_value(),q.get_value(),k.get_value(),L.get_value()))
)
)
# Label the axes
# Add the axes and the graph to the scene
self.play(Create(axes))
self.play(Create(graph))
self.play(Write(x_label), Write(y_label))
# Animate the graph by changing the value of L (length of the rod)
T_l_label = DecimalNumber(T_l.get_value(), num_decimal_places=3)
T_r_label = DecimalNumber(T_r.get_value(), num_decimal_places=3)
q_label = DecimalNumber(q.get_value(), num_decimal_places=3)
k_label = DecimalNumber(k.get_value(), num_decimal_places=3)
L_label = DecimalNumber(L.get_value(), num_decimal_places=3)
T_l_label.add_updater(lambda m: m.set_value(T_l.get_value()))
T_r_label.add_updater(lambda m: m.set_value(T_r.get_value()))
q_label.add_updater(lambda m: m.set_value(q.get_value()))
k_label.add_updater(lambda m: m.set_value(k.get_value()))
L_label.add_updater(lambda m: m.set_value(L.get_value()))
parameters = VGroup(
VGroup(MathTex("T_l = "), T_l_label).arrange(RIGHT),
VGroup(MathTex("T_r = "), T_r_label).arrange(RIGHT),
VGroup(MathTex("q = "), q_label).arrange(RIGHT),
VGroup(MathTex("k = "), k_label).arrange(RIGHT),
VGroup(MathTex("L = "), L_label).arrange(RIGHT)
).arrange(DOWN, aligned_edge=LEFT).to_corner(UR, buff=2)
self.play(
Create(parameters)
)
# Animate the parameters
self.play(
T_l.animate.set_value(500)
)
self.play(
T_l.animate.set_value(100)
)
self.play(
T_l.animate.set_value(300)
) And here is the result TemperatureDistribution.mp4 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is a beginner question, but I'm struggling with this.
I have an equation that represents the temperature distribution along one dimension:
I would like to plot the temperature as a function of the distance x. I want to display all the other parameters on the screen (T_l, T_r, q, K, L) and sweep through the parameters (one at a time) to show what the curve does when these parameters change. I want to display the parameter value on the screen and constantly have this update.
Can someone walk me through the easiest way to do this?
Here is what I have so far:
Beta Was this translation helpful? Give feedback.
All reactions