Introduction to Netlogo: A Newton s Law of Gravity Simulation Purpose Netlogo is an agent-based programming language that provides an all-inclusive platform for writing code, having graphics, and leaving out any additional compilers before the user can see how the program is working. It is designed with the intent of being convenient for the user, and also providing a way to write and run simulations on many different STEM topics, including physics and inverse-square law problems. This lesson is an introductory lesson for students to learn some of the basic commands and syntax for Netlogo, while getting students to try to modify an existing program for Newton s law of universal gravitation. The code has two masses attract each other from initial positions. The modifications students will try to make will attempt to find the proper initial positions and speeds such that one of the masses moves and goes into an orbit around the second, stationary mass. Netlogo will allow for the graphics as well as real-time graphs of several physical quantities so students will have quantitative information about the event. Overview Students will use computers that have Netlogo pre-loaded, and will be provided a Netlogo file that will open up an initial, stripped down program for Newton s law of gravity. The lesson first attempts to have students just look at the code as written, run it, and decide what certain commands mean. The lesson then attempts to get students to modify the code so the moving mass in the simulation goes into orbit around the stationary mass. This allows students to not only see Newton s law in action, but also gets them to begin doing simple programming, even if they have no prior experience with any programming language. Newton s law of gravity allows one to find the electric force between any two masses. It is written as F = Gm 1m 2/r 2, where the m s are symbols for mass in kilograms, r is the distance between the two masses, and G is a constant, 6.67 x 10-11 Nm 2 /kg 2. Note that the program is in arbitrary units where G = 1. It is used to observe the general behavior of this law, and does not provide exact units. Student Outcomes
This lesson will allow students to learn about computer simulations. This includes what they do, how they work, and what computer code looks like in a Netlogo program. Students will gain a better understanding of Newton s law of gravity since they will see the consequences of it in real time when massive particles actually produce gravitational forces on each other. This cannot be done with pencil and paper since the force is constantly changing when the particles move. This is the power of a simulation. Students will explore the nature of the inverse square law. They can change the power of r in Newton s law of gravity to see why orbits occur for a power of 2, and not other values of 1 or 3, where orbits cannot be formed. This has consequences for the understanding of planetary orbits or manmade satellites around the earth (in a classical sense). A similar electrostatics lesson can be done to show why we have stable orbits of charges, when the electric force behaves as an inverse square law. This lesson addresses the following Illinois State Science goals: - 11.A.5a 11.A.5e: Know and apply concepts, principles, and processes of science inquiry - 12.C.5b: Know and apply concepts describing matter and energy properties of materials - 12.D.5a, 12.D.5b: Know and apply concepts describing forces (EM) and motion (electrons) This activity addresses the following skills from the Computational Thinking (CT) STEM Taxonomy chart: - 1e Analyzing Data: See Appendix C - 1f Visualizing Data: See Appendix D - 3a Using Computational Models to Understand a Concept: See Appendix E - 3c Assessing Computational Models: See Appendix F This activity addresses the following Next Generation Science Standards (NGSS): MS.PS-FM Forces and Motion b. Communicate observations and information graphically and mathematically to represent how an object s relative position, velocity, and direction of motion are affected by forces acting on the object. c. Collect data to generate evidence supporting Newton s Third Law, which states that when two objects interact they exert equal and opposite forces on each other.
d. Use mathematical concepts and observations to describe the proportional relationship between the acceleration of an object and the force applied upon the object, and the inversely proportional relationship of acceleration to its mass MS.PS-IF Interactions of Forces a. Plan and carry out investigations to illustrate the factors that affect the strength of electric and magnetic forces. b. Use a model or various representations to describe the relationship among gravitational force, the mass of the interacting objects, and the distance between them. c. Plan and carry out investigations to demonstrate that some forces act at a distance through fields. d. Develop a simple model using given data that represents the relationship of gravitational interactions and the motion of objects in space HS.PS-IF Interactions of Forces a. Use mathematical expressions to determine the relationship between the variables in Newton s Law of Gravitation and Coulomb s Law, and use these to predict the electrostatic and gravitational forces between objects. b. Use models to demonstrate that electric forces at the atomic scale affect and determine the structure, properties (including contact forces), and transformations of matter HS.ESS-SS Space Systems e. Use mathematical representations of the positions of objects in the Solar System to predict their motions and gravitational effects on each other. f. Analyze evidence to show how changes in Earth s orbital parameters affect the intensity and distribution of sunlight on Earth s surface, causing cyclical climate changes that include past Ice Ages MP.2: Reason abstractly and quantitatively. MP.4 Model with Mathematics. MP.5 Use appropriate tools strategically. S.ID Summarize, represent, and interpret data on a single count or measurement variable. F.BF Build a function that models a relationship between two quantities.
Time Students will need 2-3 class periods to complete this activity. Level This activity can be done by any high school physics class. Materials and Tools Students will need Netlogo installed on the computers they will be using in order to run the simulation and have access to Netlogo code. Teachers may want to also have the electronic copy of the Netlogo User Guide available to students, so they may access it when they have questions or need to find definitions and examples of Netlogo commands. This is found at http://ccl.northwestern.edu/netlogo/docs/. An example of a student lab sheet is shown at the end of this lesson plan. Preparation Most importantly, teachers want to have Netlogo downloaded on computers prior to student use. They should also have the means for students to access the code for this lesson. The files are in the Netlogo folder at http://sp.eths.k12.il.us/vondracekm/shared %20Documents/Forms/AllItems.aspx. Students should start off with the Stripped Down file in order to have the opportunity to add and modify the code in the lesson. The Full file is the answer key, where the code will allow the masses to form an orbit. To run either program, students only need to copy the file to their computer desktop and double-click the file, and Netlogo will open the programs. Students should also have studied Newton s law of gravity and basic motion prior to doing this lesson. Prerequisites If students have any prior programming experience with any programming language, they will likely be able to do this activity faster and with slightly better understanding than those students with no prior programming experience whatsoever. But knowing any programming is not a prerequisite. Students should have exposure to Newton s law of gravity prior to this activity, so that they are not trying to learn two major ideas at the same time, those being gravitational interactions as well as programming.
It is recommended that if you do this with a class where most students do not know what a program is in general, or what computer simulations are all about, that they do some preliminary activities where they learn the gist of a computer programming. It is suggested that they do the Thinking Like a Computer lesson on the GK12 wiki. This will allow the students to have a better grasp of why programs are written the way they are and how they work. A second option is for students to do the Do a Simulation By Hand activity on the GK12 wiki, so that they have an idea of what a time step is and how it works in Netlogo. Background Students do not need to know how to program in order to use and benefit from Netlogo. This lesson has a focus on Newton s law of gravity, but students can access dozens of other simulations in other concepts and disciplines to better learn Netlogo and discover its versatility. Computer simulations allow the user to do computer experiments. Variables within the mathematical model can be changed at will, and the effect of that change can be observed immediately. This includes changing the very essence of the model in the case of Newton s law of gravity, the exponent of r can be changed. This is equivalent to creating an entirely new nature of Nature. This would not be possible to do in physical experiments, and allows us to explore hypothetical situations. This is also why it is essential in modern science to understand at least the basic concept behind mathematical models and simulating those models with computers. It is now a fundamental piece of science research and exploration. Newton s law of gravity allows one to find the gravity force between any two masses. It is written as F = Gm 1m 2/r 2, where the m s are symbols for mass, r is the distance between the two masses, and G is a constant, 6.67 x 10-11 Nm 2 /kg 2. Note that the program is in arbitrary units where G = 1. It is used to observe the general behavior of this law, and does not provide exact units. Teaching Notes Computer modeling of mathematical models is considered to be a third leg of science research, along with experimentation and theory. In this lesson students are introduced to computer simulations in the context of Netlogo. They will be able to begin learning a language, modify and create their own programs, and see the power of computer simulations in science. It is recommended that students are given an introduction to Netlogo, using a simple program that demonstrates the basic commands and features of the Netlogo platform. Students should be shown how any change to the code can immediately be seen in the Interface tab, which shows the world of the program. Students should also recognize before
starting on their own that the agents are referred to as Breeds in Netlogo. Students can also be shown how slider bar and Teachers have the option of using the Stripped programs, which has the basic shell of a program set up. Students will need to follow the lesson below to try to add or edit commands, and then immediately see what the changes do to the program in the Interface tab of Netlogo. This will require time for students to make mistakes and use trial and error to figure out what to add. If students need more guidance, or if time is tight, the Full version of the activity can be opened. This is considered the answer key to this lesson, and has code that will address all parts of the lesson. Students can compare what is in the Full version to what they were trying to see what was missing. They can also learn more about the meaning of different commands and syntax of Netlogo. It is recommended for teachers to review the Full version prior to the lesson, especially if Netlogo is new to the teacher. Once the simulation is running, students can run computer experiments. They can change Newton s law of gravity and see what differs when the power of r is varied. They can see that long-term stable orbits only form at r = 2, and not when r =1 or r =3. This discovery can be extended to Coulomb s law, and the fact that intermolecular forces would be very different electric forces did not follow an inverse-square law. There is also a Coulomb s law version of this lesson if the teacher prefers to use it. This program allows for additional investigations, especially if teachers want students to use the full version. Teachers can emphasize initial conditions, and students can vary both the initial position and initial speed of the particle. The center mass is fixed in place. A connection can be made to Kepler s first law of planetary motion, which states planets move in elliptical orbits. This simulation allows students to immediately see that an elliptical orbit indeed forms. Because there is only one orbital speed for one specific radius for circular orbits, the chance of circular orbits forming naturally are near zero. Teachers can challenge students to find the right set of initial conditions to form a circular orbit; students will discover it is difficult to do this, and see as a consequence either elliptical orbits or orbits that decay and are unstable over time. With the graphs that show real-time force and potential energy plots, the periodicity of orbits is visualized. All of these features should begin to provide a stronger conceptual understanding of how orbits form and their behaviors under numerous different sets of conditions. Teachers can have students make these changes and run computer experiments either by using the slider bars or going to the code and changing the values of parameters.
Assessment This is a lab activity, and teachers can have the students write it up as they normally do and grade it as a class lab report. An example of the student lab sheet is shown below in this lesson plan. Additional Information In Netlogo, there is an option under Files called Models Library. This has dozens of other existing programs and simulations, each of which one can access the code and modify it as they wish. Any of these can be used by students in order to better learn Netlogo s commands and structure to do more and different simulations. The Netlogo files for this lesson can be found at: http://sp.eths.k12.il.us/vondracekm/shared%20documents/forms/allitems.aspx. Students should start off with the Stripped Down file in order to have the opportunity to add and modify the code in the lesson. The Full file is the answer key, where the code will allow the masses to form an orbit. To run either program, students only need to copy the file to their computer desktop and double-click the file, and Netlogo will open the programs. On the next page is an example of the student lab sheet.
Intro to Netlogo and a Gravity Force Simulation Part 1: Understanding the Code How many types of agents are there? Agent types are listed first in the code. What are they? Including GO and Setup how many procedures are there? Note that Setup and Go are the two buttons you need to click on to run the program. In what procedure does the force between the two masses get calculated? What approximation is made when moving the particles? In the procedure update-force explain what the command face one-of centers does. The variable r is defined as a global variable, what procedures is it used in and how is it calculated? Part 2: Editing the code Position of moving particle Instead of the test (movable) mass being generated at a random location in the world, we now want to be able to specify where it starts. To start this we must first delete the command that creates the particle at a random location find the line with the following code and delete it: fd random-float (max-pxcor - 6) Since netlogo is primarily a visual modeling language, the x y locations of agents is already a well defined variable built into the language. We can edit the pre existing variables by using the command: setxy x y. This command sets the location of the agent, an example of this is we wanted to set the particle to the position of (-15, 12) we would use setxy -15 12 We cannot simply use this piece of code where ever we want. Since we are setting the position of the movable mass (or what this simulation calls a particle, not a center), we need to make sure we are setting its position and nothing else. Luckily, since this is an agent based language this is rather easy. We could simply just ask the particle to move to our desired location: ask particles [ setxy -15 12 ]
With this in mind we need to be conscientious of where in the program we are asking the particle to set its location and where this would be best served. If placed correctly in the code asking the particle to set its location will do the job, but I think an easier and cleaner way to write this into the code is to set the particle s location in the command when the particle is created. See if you can make this work! Now that we know how to change the location of the particle by editing the code, we want to be able to do this without having to recode our simulator every time. This means that we want to create a user defined variable in the simulator. On the Interface tab we can left click in any of the empty white space to bring a list of user input options. I would recommend using either a slider or an input option. A slider defines a variable that is set by the value the slider is slide to. To use a slider you must define a variable, a maximum value, a minimum value, and an increment. An input is simply a box where you again define a variable and it will be set to anything typed into the input box. Note that there is a distinct advantage to slider when considering how the code runs and the possible entries a user would be able to put into an input box. Can you think of what this is? Now that we can have the user define the value of a variable using either a slider or an input box we can use the variable to set the x and y position of the particle. This can be done as the arguments of the setxy command do not need to be numbers but can also be variables. For example if we had a user define two variables favoritenumber and age we could set the particle s location to: setxy favoritenumber age So in my case this would set the particles position to (24,26). But someone else will have a different favorite number and age setting their particle to a different location without having to adjust the code. Position of stationary particle So hopefully by now we have all the pieces in place to set some user defined variables to set the location of the moving mass. Can you do this with the stationary mass as well? Masses Thus far we have changed the location of the particles. In the original simulator we have a slider to determine the values of both masses simultaneously. The next improvement to the simulator should be allowing the two masses to be set independently of each other. No special commands should be necessary, However, one must set another new user defined variable and look at the code carefully to make the necessary adjustments. Initial Velocities Now that we can control the positions and masses of each of the agents we want to make things more interesting than having the two masses fly away or towards each other. To do this we will need to give the movable mass some initial velocity. Note there are already variables that exist for the x and y velocity of the particle, we just need to figure out how to set their initial values.
Exponential Law s Last but not least, to get to some really interesting physics, we want to be able to change the type of force experienced by the two masses. It is well known that the Gravitational Force is a 1/r^2 force, but what if it was not? What if it was 1/r or 1/r^3? Usually these are very complicated problems requiring differential equations to solve, however instead of solving the problem let s model it! Part 3: Using the Simulator Find 2 configurations that make the moving mass orbit the stationary mass. List all used parameters and describe the shape of the orbit and if the orbit is stable (the orbit stays in the same place) or unstable (the orbit itself precesses around the stationary mass). Find 2 configurations that give you a nearly perfect circular orbit. Again list all used parameters. Can you get a circular orbit in both stable and unstable configurations? Repeat the previous 4 configurations now using a 1/r law instead of a 1/r^2 law. Describe how each of these differed from the original. Can we make any generalizations about the relative strengths between a 1/r versus 1/r^2 law? Repeat the previous 4 configurations now using a 1/r^3 law instead of a 1/r^2 law. Describe how each of these differed from the original. Can we make any generalizations about the relative strengths between a 1/r^3 versus 1/r^2 law? Conclusions: Summarize what you found with different power laws, and how they relate to the stability or instability of orbits. Challenge: Do a more systematic study of power laws, and see if it is possible to get any stable orbits using small ranges of values near 2 for your exponent (e.g. 2.1, 1.9, etc). Any luck getting orbits of any kind? Describe your findings.