{"id":219,"date":"2021-04-12T16:36:21","date_gmt":"2021-04-12T16:36:21","guid":{"rendered":"https:\/\/www.msuperl.org\/wp\/icsam\/?page_id=219"},"modified":"2021-04-29T16:35:02","modified_gmt":"2021-04-29T16:35:02","slug":"phase-changes","status":"publish","type":"page","link":"https:\/\/www.msuperl.org\/wp\/icsam\/computational-activities\/phase-changes\/","title":{"rendered":"Phase Changes"},"content":{"rendered":"\n<p class=\"has-large-font-size\">Activity Information<\/p>\n\n\n\n<p class=\"has-medium-font-size\">Learning Goals<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Develop and use models to illustrate that energy at the macroscopic scale can be accounted for as a combination of energy associated with the motions of particles and energy associated with the relative position of particles (<a href=\"https:\/\/www.nextgenscience.org\/pe\/hs-ps3-2-energy\"> HS-PS3-2<\/a>)<\/li><li>Apply kinetic theory to state change and energy changes within matter<\/li><li>Explain and visualize how the physical properties of matter change (at atomic and macroscopic levels) to an energy input or temperature change<\/li><li>Plot and interpret the graph of temperature vs. time (heating curve) of a material<\/li><li>Use terms that describe what is happening on each part of the curve<ul><li>melting, condensing, boiling, etc.<\/li><\/ul><\/li><\/ul>\n\n\n\n<p class=\"has-medium-font-size\">Prior Knowledge Required<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Kinetic theory of motions <\/li><li>States of Matter <\/li><li>Heat and Enthalpy<\/li><\/ul>\n\n\n\n<p class=\"has-medium-font-size\">Code Manipulation<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Copying\/pasting code<\/li><li>Creating code from scratch<\/li><li>While loops and if statements<\/li><li>translating equations into code<\/li><\/ul>\n\n\n\n<p class=\"has-large-font-size\">Activity<\/p>\n\n\n\n<p class=\"has-medium-font-size\">Handout &#8211; Phase Changes<\/p>\n\n\n\n<p>A graph of the temperature of a material over time is called a heating curve. The heating curve shows the change of state of a material as more energy (higher temperature) is added to the material. The sloped regions of the graph show how energy is raising the temperature of that state until a plateau (the flat regions of the graph) is reached. This is known as *specific heat*. Specific heat capacity (shown as the variable \u201cC\u201d \u2014 not to be confused with Celsius of Calories) is the amount of heat required to change the temperature of a mass unit of a substance by one degree. For special conditions, Cv is used for isochoric (constant volume) environments or Cp for isobaric (constant pressure) environments. Q=mC\u0394T is the governing equation, where Q is the total energy in kilojoules, m is the mass of the substance in grams, and \u0394T is the difference between the final and initial temperatures of the substance in Kelvin.<\/p>\n\n\n\n<p>During the plateau, additional energy is needed to bring the entire mass of the matter to a point where it can move to the next state. This is known as the *latent heat* of the substance and is shown as the variable L. The total energy is given by the equation Q=mL.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"pre-coding_questions_part_1\">Pre-Coding Questions Part 1<\/h5>\n\n\n\n<p>Below is a graph showing the heating curve for water. Take a look and use the <a href=\"https:\/\/trinket.io\/glowscript\/d406d0473c?showInstructions=true\">code below<\/a> and then answer the following questions that investigate the relationships between kinetic energy level, temperature, particle movement, etc.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.msuperl.org\/wikis\/icsam\/lib\/exe\/fetch.php?w=600&amp;tok=a9c583&amp;media=repository:water_curve.png\" alt=\"\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\"><li>If the particle movement is low, the matter is in the _____ state.<\/li><li>The _____ state is reached as particles exhibit very high energy at a correspondingly _____ temperature.<\/li><li>When a gas loses so much energy it turns into a liquid, it undergoes _____.<\/li><li>Since particles in a solid are closely packed together, they can only move _____.<\/li><li>Particles exhibit _____ velocities in the highest energy state.<\/li><li>Solid particles that absorb so much energy they turn into a gas undergo _____.<\/li><li>At moderate levels of kinetic energy, the particles can move _____ and the matter exists as a _____.<\/li><li>Lower energy means _____ particle movement and _____ temperature.<\/li><li>Theoretically, no particle movement occurs at _____ \u00b0C (0 K).<\/li><li>Solids typically have _____ temperatures than gases.<\/li><li>If a gas is super heated to thousands of Kelvin, it ionizes and becomes _____.<\/li><li>Increases in _____ result in greater particle velocity and therefore greater kinetic energy.<\/li><li>The Kinetic Theory of Matter says that for hotter temperatures, the _____ of the particles move in matter.<\/li><\/ol>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"pre-coding_questions_part_2\">Pre-Coding Questions Part 2<\/h5>\n\n\n\n<p>Using the graph above, answer the following questions:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Partition this graph into three regions showing the 3 states of matter \u2014 label each region and shade it a different color.<\/li><li>Identify where the matter changes from one state to another.<\/li><li>Energy is increasing from left to right; label each part of the curve to describe what the matter is doing as energy increases (above the curve) and when energy is decreasing (below the curve). For example, as energy is added, what word describes how the solid changes?<\/li><li>Based on the graph, at what temperature (K) does the matter freeze?<\/li><li>At what temperature does the matter vaporize?<\/li><li>If water ionizes (and turns into plasma) at 12000 K, is this graph an accurate model of how water changes state?<\/li><li>Looking at the heating curve program, What do you notice about the first and second plateaus? what does this say about the heat capacity of water in the liquid vs. the steam state? Which state is more efficient\/better for carrying heat?<\/li><\/ol>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"post-coding_questions\">Post-Coding Questions<\/h5>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.msuperl.org\/wikis\/icsam\/lib\/exe\/fetch.php?w=600&amp;tok=bfa945&amp;media=repository:boiling.png\" alt=\"\" \/><\/figure>\n\n\n\n<p>Now that you understand how the program works to show the relationship between kinetic energy, particle movement, and temperature, it is time to apply your knowledge to improving and extending the power of the program. Develop answers to the following questions by modifying and improving the <a href=\"https:\/\/trinket.io\/glowscript\/d406d0473c?showInstructions=true\">existing code<\/a>.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Do you think the movement of all particles is the same for all substances given the same energy? For example, should a particle of hydrogen (mass = 1.01 amu) move at the same velocity as a particle of nitrogen (mass = 14.01 amu) for a given temperature?<\/li><li>What are some of the key equations you would need to model the movement of the particles?<\/li><li>Which variables are constants and which can change?<\/li><li>How could we show different movement for different types of substances?<\/li><li>How would the heating curve graph look if we used another substance?<\/li><li>So far, all these calculations have been isobaric (same pressure) and isochoric (same volume). What would happen to your answers if the pressure was doubles to 2 atmospheres? How would you model that? Would that affect your entire heating curve or just a portion? What equations relate pressure, temperature, and volume?<\/li><\/ol>\n\n\n\n<p class=\"has-medium-font-size\">Code<\/p>\n\n\n\n<p><a href=\"https:\/\/trinket.io\/glowscript\/d406d0473c?showInstructions=true\">Link<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>GlowScript 2.7 VPython\n#COLLAPSE LINES 3, 8, 11, AND 16! These are special bundles of code, called subroutines, which help simplify the coding later in the program.\ndef ShrinkSolidGrowLiquid():#This subroutine changes the sizes of the solid and liquid phases during melting\n    solid.pos=solid.pos+vec(0,-(L_box\/(2*ceil(m*Hfus\/dE))),0) #SizeIncrement1=L_box\/(2*ceil(m*Hfus\/dE))\n    solid.radius=solid.radius-(L_box\/(2*ceil(m*Hfus\/dE)))\n    liquid.pos=liquid.pos+vec(0,0.5*(L_box\/(2*ceil(m*Hfus\/dE))),0)\n    liquid.size=liquid.size+vec(0,(L_box\/(2*ceil(m*Hfus\/dE))),0)\ndef ShrinkLiquid():#This subroutine changes the size of the liquid phase during vaporization\n    liquid.pos=liquid.pos+vec(0,-0.5*L_box\/(2*ceil(m*Hvap\/dE)),0) #SizeIncrement2=L_box\/(2*ceil(m*Hvap\/dE))\n    liquid.size=liquid.size+vec(0,-L_box\/(2*ceil(m*Hvap\/dE)),0)\ndef MakeNewParticle():#This subroutine creates a new gas particle and adds it to a list of particles\n    newparticle = sphere(pos=vector(L_box*(random()-0.5),(L_box-liquid.size.y)*(random()-0.5)+liquid.size.y\/2,L_box*(random()-0.5)),radius=0.05, color=color.cyan)\n    newparticle.mass = 1\n    newparticle.velocity = vector(random()-0.5,random()-0.5,random()-0.5)*2 #the coefficient of 2 is a scaling factor for visual effect\n    listOfParticles.append(newparticle)\ndef ParticleMovementAndCollisions(): #This subroutine moves gas particles and handles particle-wall and particle-particle collisions\n    for particle in listOfParticles:\n        if Etotal &gt; Eboil: #If all the liquid has evaporated, start increasing the velocity of the gas particles\n            particle.velocity=particle.velocity+sqrt(2*dE\/particle.mass)*(particle.velocity\/mag(particle.velocity))*2E-4 #Increase velocity with increasing energy. The coefficient of 2E-4 is a scaling factor for visual effect\n        particle.pos = particle.pos + particle.velocity*0.1 #Update particle position, assume dt=0.1\n        if abs(particle.pos.x) &gt;= container.length\/2:#Particle-wall collision in x\n            particle.velocity.x = - particle.velocity.x\n        if abs(particle.pos.y) &gt;= container.height\/2 or particle.pos.y &lt;= (liquid.size.y-L_box\/2):#Particle-wall collision in y\n            particle.velocity.y = - particle.velocity.y\n        if abs(particle.pos.z) &gt;= container.width\/2:#Particle-wall collision in z\n            particle.velocity.z = - particle.velocity.z\n    for i in range(0,len(listOfParticles)):#Particle-particle collisions, loop through every particle\n        for j in range(i+1,len(listOfParticles)):#loop through every OTHER particle\n            diff = listOfParticles&#091;j].pos - listOfParticles&#091;i].pos #displacement vector between two particles\n            distance = mag(diff) #magnitude of displacement is distance\n            if distance &lt;= listOfParticles&#091;i].radius + listOfParticles&#091;j].radius: #if particles will collide, check their next positions\n                nextpos1 = listOfParticles&#091;i].pos + listOfParticles&#091;i].velocity*0.1 #assume dt=0.1\n                nextpos2 = listOfParticles&#091;j].pos + listOfParticles&#091;j].velocity*0.1 #assume dt=0.1\n                if mag(nextpos2 - nextpos1) &lt; distance: #if they collide with each other, transfer momentum\n                    rhat = norm(diff) #unit vector of displacement\n                    mv1 = listOfParticles&#091;i].mass*listOfParticles&#091;i].velocity #momentum of first particle\n                    mv2 = listOfParticles&#091;j].mass*listOfParticles&#091;j].velocity #momentum of second particle\n                    transfer = 2.*dot(listOfParticles&#091;i].mass*mv2-listOfParticles&#091;j].mass*mv1,rhat)\/(listOfParticles&#091;i].mass+listOfParticles&#091;j].mass)*rhat #momentum transferred\n                    listOfParticles&#091;i].velocity = (mv1 + transfer)\/listOfParticles&#091;i].mass\n                    listOfParticles&#091;j].velocity = (mv2 - transfer)\/listOfParticles&#091;j].mass\n \n#Define initial parameters: mass of system, inital temperature of system, initial energy of system, and length of container\nm = 100 #mass (g)\nT = 0 #Initial Temp (K)\nEtotal = 0 #Inital total energy input\ndE = 1000 #incremental energy change (J), how much energy is added to our system for each step of the program. You are advised NOT to change dE.\nL_box = 6 # Define the length of our container\n \n#Create our objects: container, sphere for solid phase, blue box for liquid phase, and empty list for gas particles\ncontainer = box(pos=vec(0,0,0), size=vec(L_box,L_box,L_box), color=color.white, opacity=0.1) # Creates a box of length L_box\nsolid = sphere(pos=vec(0,0,0), radius=L_box\/2, color=color.white) #Creates a sphere for the solid phase\nliquid = box(pos=vector(0,-L_box\/2,0), size=vector(L_box,0,L_box), color=color.blue, opacity=0.75, visible=False) #Creates a box for the liquid phase\nlistOfParticles = &#091;] #Creates an empty list of gas particles for the gas phase\n \n#Define properties of our material: heat capacities, latent heats, and transition temperatures\nc_s=2.108 #solid heat capacity (J\/gK)\nHfus=335.5 #Latent heat of fusion (J\/g)\nc_l=4.186 #liquid heat capacity (J\/gK)\nHvap=2260 #Latent heat of vaporization (J\/g)\nc_g=1.996 #gas heat capacity (J\/gK)\nTm=273 #Melting point (K)\nTb=373 #Boiling point (K)\n \n#Calculate total energy values at different points (J)\nEsol=5e4 #Energy to raise temp to melting point, i.e. max energy a solid can have\nEmelt=1e5 #Energy to raise temp AND melt all of the solid\nEliq=2e5 #Energy to raise temp, AND melt, AND reach boiling point, i.e. max energy a liquid can have\nEboil=4e5 #Energy melt AND reach boiling point AND boil all the liquid\n \n#Initialize Graph\nGrph1 = graph(title='Temperature vs Energy', xtitle='Energy Input to System (J)', ytitle='Temperature (K)', fast=False, ymin=0, ymax=1000) #initialize our graph axes, titles, and boundaries\nHeatingCurve = gcurve(color=color.red, label='Heating Curve') #Prepare a data series to be plotted\n \nEfinal = 1.25*Eboil #Set the final energy to stop the program at\nwhile Etotal &lt; Efinal: #Run loop until Energy is larger than Efinal\n    rate(25) #Change this to make your program run faster or slower. 10-100 is recommended.\n \n    if Etotal &lt; Esol: #If statement for changing temp within solid phase\n \n        HeatingCurve.plot(Etotal, T) #Plot T(K) vs E in J\n \n    elif Etotal &lt; Emelt: #If statement for changing from solid to liquid\n        liquid.visible=True #make sure the liquid phase is visible\n        ShrinkSolidGrowLiquid() #Change sizes of solid and liquid phases\n        HeatingCurve.plot(Etotal, T) #Plot T(K) vs E in J\n \n    elif Etotal &lt; Eliq: #If statement for changing temp within liquid phase\n        solid.visible=False #make sure the solid phase is invisible\n \n        HeatingCurve.plot(Etotal, T) #Plot T(K) vs E in J\n \n    elif Etotal &lt; Eboil: #If statement for changing from liquid to gas\n        ShrinkLiquid() #Change size of liquid phase\n        MakeNewParticle() #Add a gas atom to the container\n        ParticleMovementAndCollisions() #Make the gas particles move and collide\n        HeatingCurve.plot(Etotal, T) #Plot T(K) vs E in J\n \n    else: #Changing temperature within gas phase\n        liquid.visible=False #make sure the liquid phase is invisible\n \n        ParticleMovementAndCollisions() #Make the gas particles move and collide\n        HeatingCurve.plot(Etotal, T) #Plot T(K) vs E in J\n \n    Etotal = Etotal + dE # Increase the total energy by dE<\/code><\/pre>\n\n\n\n<p class=\"has-large-font-size\">Answer Key<\/p>\n\n\n\n<p class=\"has-medium-font-size\">Handout<\/p>\n\n\n\n<p>If the particle movement is low, the matter is in the <em><strong>solid<\/strong><\/em> state.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>The <em><strong>gas<\/strong><\/em> state is reached as particles exhibit very high energy at a correspondingly <em><strong>high<\/strong><\/em> temperature.<\/li><li>When a gas loses so much energy it turns into a liquid, it undergoes <em><strong>condensation<\/strong><\/em>.<\/li><li>Since particles in a solid are closely packed together, they can only move <em><strong>vibrationally<\/strong><\/em> .<\/li><li>Particles exhibit <em><strong>high<\/strong><\/em> velocities in the highest energy state.<\/li><li>Solid particles that absorb so much energy they turn into a gas undergo <em><strong>sublimation<\/strong><\/em>.<\/li><li>At moderate levels of kinetic energy, the particles can move <em><strong>freely<\/strong><\/em> and the matter exists as a <em><strong>liquid<\/strong><\/em>.<\/li><li>Lower energy means <em><strong>slower<\/strong><\/em> particle movement and <em><strong>lower<\/strong><\/em> temperature.<\/li><li>Theoretically, no particle movement occurs at <em><strong>-273.15<\/strong><\/em> \u00b0C (0 K).<\/li><li>Solids typically have <em><strong>lower<\/strong><\/em> temperatures than gases.<\/li><li>If a gas is super heated to thousands of Kelvin, it ionizes and becomes <em><strong>plasma<\/strong><\/em>.<\/li><li>Increases in <em><strong>temperature<\/strong><\/em> result in greater particle velocity and therefore greater kinetic energy.<\/li><li>The Kinetic Theory of Matter says that for hotter temperatures, the <em><strong>more<\/strong><\/em> of the particles move in matter.<\/li><\/ol>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"pre-coding_questions_part_21\">Pre-Coding Questions Part 2<\/h5>\n\n\n\n<ol class=\"wp-block-list\"><li><img decoding=\"async\" src=\"https:\/\/www.msuperl.org\/wikis\/icsam\/lib\/exe\/fetch.php?w=600&amp;tok=d3129b&amp;media=repository:heating_curve.jpg\" alt=\"\" width=\"600\"><\/li><li>The first plateau is where the matter melts (goes from solid to liquid) or freezes (goes from liquid to solid). Likewise, the second plateau is where the matter boils\/vaporizes (goes from liquid to gas) or condenses (goes from gas to liquid)<\/li><li>See graph and previous answer<\/li><li>273.1 K (0 \u00b0C)<\/li><li>373.1 K (100 \u00b0C)<\/li><li>The graph accurately models the changes between the solid, liquid, and gas phases of water, but does not include the process of ionization<\/li><li>The first plateau is longer than the second. This indicates that the heat capacity of liquid water is higher than the heat capacity of steam. This means that water is more efficient and carrying heat; it requires more energy to change its temperature in the liquid phase versus the gaseous phase<\/li><\/ol>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"post-coding_questions1\">Post-Coding Questions<\/h5>\n\n\n\n<ol class=\"wp-block-list\"><li>No. We know kinetic energy is equal to 12mv2. Rearranging for velocity, we find v=\u221a2KEm. Therefore, for the same energy level, more mass results in less velocity.<\/li><li>Q=mc\u0394T and Q=mL <\/li><li>The mass, specific heat capacities, latent heat of fusion, latent heat of vaporization will not change. Energy input is an independent variable and temperature of the substance is a dependent variable. <\/li><li>We can show different heating curves for different substances by changing the parameters defined in lines 56-62 (specific heat capacities, latent heat of fusion, melting point, etc.) <\/li><li>Here are some examples:<img decoding=\"async\" src=\"https:\/\/www.msuperl.org\/wikis\/icsam\/lib\/exe\/fetch.php?w=600&amp;tok=24a63c&amp;media=repository:heating_curves.jpg\" alt=\"\" width=\"600\"> <\/li><li>If the model occurred at 2 atmospheres of pressure, the melting\/freezing point would lower and the boiling\/condensing point would increase. We can look at a <a href=\"https:\/\/chem.libretexts.org\/Bookshelves\/Physical_and_Theoretical_Chemistry_Textbook_Maps\/Supplemental_Modules_(Physical_and_Theoretical_Chemistry)\/Physical_Properties_of_Matter\/States_of_Matter\/Phase_Transitions\/Phase_Diagrams#:~:text=Phase%20diagram%20is%20a%20graphical,diagram%2C%20a%20phase%20change%20occurs.\">phase diagram<\/a> to see how pressure affects change of state for different substances. One equation that relates pressure, temperature, and volume is the ideal gas law: PV=nRT (note that this only applies to gases)<\/li><\/ol>\n\n\n\n<p class=\"has-medium-font-size\">Code<\/p>\n\n\n\n<p><a href=\"https:\/\/trinket.io\/glowscript\/2f3f50f661?showInstructions=true\">Link<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>GlowScript 2.7 VPython\n#COLLAPSE LINES 3, 8, 11, AND 16! These are special bundles of code, called subroutines, which help simplify the coding later in the program.\ndef ShrinkSolidGrowLiquid():#This subroutine changes the sizes of the solid and liquid phases during melting\n    solid.pos=solid.pos+vec(0,-(L_box\/(2*ceil(m*Hfus\/dE))),0) #SizeIncrement1=L_box\/(2*ceil(m*Hfus\/dE))\n    solid.radius=solid.radius-(L_box\/(2*ceil(m*Hfus\/dE)))\n    liquid.pos=liquid.pos+vec(0,0.5*(L_box\/(2*ceil(m*Hfus\/dE))),0)\n    liquid.size=liquid.size+vec(0,(L_box\/(2*ceil(m*Hfus\/dE))),0)\ndef ShrinkLiquid():#This subroutine changes the size of the liquid phase during vaporization\n    liquid.pos=liquid.pos+vec(0,-0.5*L_box\/(2*ceil(m*Hvap\/dE)),0) #SizeIncrement2=L_box\/(2*ceil(m*Hvap\/dE))\n    liquid.size=liquid.size+vec(0,-L_box\/(2*ceil(m*Hvap\/dE)),0)\ndef MakeNewParticle():#This subroutine creates a new gas particle and adds it to a list of particles\n    newparticle = sphere(pos=vector(L_box*(random()-0.5),(L_box-liquid.size.y)*(random()-0.5)+liquid.size.y\/2,L_box*(random()-0.5)),radius=0.05, color=color.cyan)\n    newparticle.mass = 1\n    newparticle.velocity = vector(random()-0.5,random()-0.5,random()-0.5)*2 #the coefficient of 2 is a scaling factor for visual effect\n    listOfParticles.append(newparticle)\ndef ParticleMovementAndCollisions(): #This subroutine moves gas particles and handles particle-wall and particle-particle collisions\n    for particle in listOfParticles:\n        if Etotal &gt; Eboil: #If all the liquid has evaporated, start increasing the velocity of the gas particles\n            particle.velocity=particle.velocity+sqrt(2*dE\/particle.mass)*(particle.velocity\/mag(particle.velocity))*2E-4 #Increase velocity with increasing energy. The coefficient of 2E-4 is a scaling factor for visual effect\n        particle.pos = particle.pos + particle.velocity*0.1 #Update particle position, assume dt=0.1\n        if abs(particle.pos.x) &gt;= container.length\/2:#Particle-wall collision in x\n            particle.velocity.x = - particle.velocity.x\n        if abs(particle.pos.y) &gt;= container.height\/2 or particle.pos.y &lt;= (liquid.size.y-L_box\/2):#Particle-wall collision in y\n            particle.velocity.y = - particle.velocity.y\n        if abs(particle.pos.z) &gt;= container.width\/2:#Particle-wall collision in z\n            particle.velocity.z = - particle.velocity.z\n    for i in range(0,len(listOfParticles)):#Particle-particle collisions, loop through every particle\n        for j in range(i+1,len(listOfParticles)):#loop through every OTHER particle\n            diff = listOfParticles&#091;j].pos - listOfParticles&#091;i].pos #displacement vector between two particles\n            distance = mag(diff) #magnitude of displacement is distance\n            if distance &lt;= listOfParticles&#091;i].radius + listOfParticles&#091;j].radius: #if particles will collide, check their next positions\n                nextpos1 = listOfParticles&#091;i].pos + listOfParticles&#091;i].velocity*0.1 #assume dt=0.1\n                nextpos2 = listOfParticles&#091;j].pos + listOfParticles&#091;j].velocity*0.1 #assume dt=0.1\n                if mag(nextpos2 - nextpos1) &lt; distance: #if they collide with each other, transfer momentum\n                    rhat = norm(diff) #unit vector of displacement\n                    mv1 = listOfParticles&#091;i].mass*listOfParticles&#091;i].velocity #momentum of first particle\n                    mv2 = listOfParticles&#091;j].mass*listOfParticles&#091;j].velocity #momentum of second particle\n                    transfer = 2.*dot(listOfParticles&#091;i].mass*mv2-listOfParticles&#091;j].mass*mv1,rhat)\/(listOfParticles&#091;i].mass+listOfParticles&#091;j].mass)*rhat #momentum transferred\n                    listOfParticles&#091;i].velocity = (mv1 + transfer)\/listOfParticles&#091;i].mass\n                    listOfParticles&#091;j].velocity = (mv2 - transfer)\/listOfParticles&#091;j].mass\n \n#Define initial parameters: mass of system, inital temperature of system, initial energy of system, and length of container\nm = 100 #mass (g)\nT = 0 #Initial Temp (K)\nEtotal = 0 #Inital total energy input\ndE = 1000 #incremental energy change (J), how much energy is added to our system for each step of the program. You are advised NOT to change dE.\nL_box = 6 # Define the length of our container\n \n#Create our objects: container, sphere for solid phase, blue box for liquid phase, and empty list for gas particles\ncontainer = box(pos=vec(0,0,0), size=vec(L_box,L_box,L_box), color=color.white, opacity=0.1) # Creates a box of length L_box\nsolid = sphere(pos=vec(0,0,0), radius=L_box\/2, color=color.white) #Creates a sphere for the solid phase\nliquid = box(pos=vector(0,-L_box\/2,0), size=vector(L_box,0,L_box), color=color.blue, opacity=0.75, visible=False) #Creates a box for the liquid phase\nlistOfParticles = &#091;] #Creates an empty list of gas particles for the gas phase\n \n#Define properties of our material: heat capacities, latent heats, and transition temperatures\nc_s=2.108 #solid heat capacity (J\/gK)\nHfus=335.5 #Latent heat of fusion (J\/g)\nc_l=4.186 #liquid heat capacity (J\/gK)\nHvap=2260 #Latent heat of vaporization (J\/g)\nc_g=1.996 #gas heat capacity (J\/gK)\nTm=273 #Melting point (K)\nTb=373 #Boiling point (K)\n \n#Calculate total energy values at different points (J)\n<strong>Esol=m*c_s*(Tm-T) #Energy to raise temp to melting point, i.e. max energy a solid can have\nEmelt=Esol+m*Hfus #Energy to raise temp AND melt all of the solid\nEliq=Emelt+m*c_l*(Tb-Tm) #Energy to raise temp, AND melt, AND reach boiling point, i.e. max energy a liquid can have\nEboil=Eliq+m*Hvap #Energy to reach melting point, melt, reach boiling point, and boil all the liquid<\/strong>\n \n#Initialize Graph\nGrph1 = graph(title='Temperature vs Energy', xtitle='Energy Input to System (J)', ytitle='Temperature (K)', fast=False, ymin=0, ymax=1000) #initialize our graph axes, titles, and boundaries\nHeatingCurve = gcurve(color=color.red, label='Heating Curve') #Prepare a data series to be plotted\n \nEfinal = 1.25*Eboil #Set the final energy to stop the program at\nwhile Etotal &lt; Efinal: #Run loop until Energy is larger than Efinal\n    rate(25) #Change this to make your program run faster or slower. 10-100 is recommended.\n \n    if Etotal &lt; Esol: #If statement for changing temp within solid phase\n<strong>        T=T+dE\/(m*c_s) #Calculate temperature (K) from q=mc(Delta_T) equation<\/strong>\n        HeatingCurve.plot(Etotal, T) #Plot T(K) vs E in J\n \n    elif Etotal &lt; Emelt: #If statement for changing from solid to liquid\n        liquid.visible=True #make sure the liquid phase is visible\n        ShrinkSolidGrowLiquid() #Change sizes of solid and liquid phases\n        HeatingCurve.plot(Etotal, T) #Plot T(K) vs E in J\n \n    elif Etotal &lt; Eliq: #If statement for changing temp within liquid phase\n        solid.visible=False #make sure the solid phase is invisible\n<strong>        T=T+dE\/(m*c_l) #Calculate temperature (K) from q=mc(Delta_T) equation<\/strong>\n        HeatingCurve.plot(Etotal, T) #Plot T(K) vs E in J\n \n    elif Etotal &lt; Eboil: #If statement for changing from liquid to gas\n        ShrinkLiquid() #Change size of liquid phase\n        MakeNewParticle() #Add a gas atom to the container\n        ParticleMovementAndCollisions() #Make the gas particles move and collide\n        HeatingCurve.plot(Etotal, T) #Plot T(K) vs E in J\n \n    else: #Changing temperature within gas phase\n        liquid.visible=False #make sure the liquid phase is invisible\n<strong>        T=T+dE\/(m*c_g) #Calculate temperature (K) from q=mc(Delta_T) equation<\/strong>\n        ParticleMovementAndCollisions() #Make the gas particles move and collide\n        HeatingCurve.plot(Etotal, T) #Plot T(K) vs E in J\n \n    Etotal = Etotal + dE # Increase the total energy by dE<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Activity Information Learning Goals Develop and use models to illustrate that energy at the macroscopic scale can be accounted for as a combination of energy associated with the motions of particles and energy associated with the relative position of particles ( HS-PS3-2) Apply kinetic theory to state change and energy changes within matter Explain and &hellip; <a href=\"https:\/\/www.msuperl.org\/wp\/icsam\/computational-activities\/phase-changes\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Phase Changes&#8221;<\/span><\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"parent":29,"menu_order":22,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-219","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.msuperl.org\/wp\/icsam\/wp-json\/wp\/v2\/pages\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.msuperl.org\/wp\/icsam\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.msuperl.org\/wp\/icsam\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.msuperl.org\/wp\/icsam\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.msuperl.org\/wp\/icsam\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":3,"href":"https:\/\/www.msuperl.org\/wp\/icsam\/wp-json\/wp\/v2\/pages\/219\/revisions"}],"predecessor-version":[{"id":373,"href":"https:\/\/www.msuperl.org\/wp\/icsam\/wp-json\/wp\/v2\/pages\/219\/revisions\/373"}],"up":[{"embeddable":true,"href":"https:\/\/www.msuperl.org\/wp\/icsam\/wp-json\/wp\/v2\/pages\/29"}],"wp:attachment":[{"href":"https:\/\/www.msuperl.org\/wp\/icsam\/wp-json\/wp\/v2\/media?parent=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}