Simple Harmonic Motion: What Your Sensors Measure (and What the Models Show)
Vernier · Uploaded · 57:16 · Watch on YouTube
Physicist Rhett Allain, with Vernier's Fran Poodry, walks students through collecting spring-cart oscillation data with a Go Direct cart and measuring spring constant. He then shows how to export that position data into a Python model to compare with real measurements.
Transcript
Captions as a .vtt fileEmbed with the transcript
- 0:00Hello, everybody. Thank you so much for joining us. We are so excited to dive into simple harmonic
- 0:10motion. Let me go ahead and pull up the slideshow so you guys know where you are.
- 0:21While I'm getting this set up, go ahead and pop in the chat and let us know where you're
- 0:28joining us from. I am here. Sorry, I've got all my windows open. I am here in Oregon where the
- 0:41Vernier headquarters is. Oh, we've got someone from Argentina. That's cool. Awesome. Good to see you.
- 0:53Syracuse, New York, California, Texas. Oh, Roger from Boulder, Colorado. I went to CSU in Fort
- 1:00Collins. Sorry, Roger. But my twin brother went to Boulder, so I'm an ally.
- 1:08Kaysville, Utah, Pennsylvania, Selma, Syracuse. Oh, Marianne from Swarthmore. Hi.
- 1:14Nice. Hayward, California. Awesome. Well, thank you all so much for joining us today. I want to get to
- 1:22the meat and potatoes of today's presentation. Oh, hi, Tony. Perfect. Sorry. Oh, no, you're good.
- 1:32I wanted to hop into some housekeeping items. So, as you can see, we are in on 24, which means that
- 1:39you are going to get a follow-up to this webinar very quickly. I think it sends a follow-up within
- 1:44the day. We will have it, you know, on our website and on YouTube within three to five business days.
- 1:49We still just have to edit it if it's going on YouTube. But you will get that and a certificate
- 1:55of attendance. I'm also going to tell you where to find that right now. So, looking at the top of
- 2:02your screen, a quick walkthrough of what you're seeing. So, if you look at the speakers tab,
- 2:07you'll see some info about today's presenters as well as how to contact them. I know you all already
- 2:13located the attendee chat. That's where you'll be active today. So, that's where you can ask your
- 2:19questions, give us your comments. I'm going to keep an eye on the chat. I know that Fran is also
- 2:24keeping an eye on the chat. Under additional resources, you'll find a link to the certificate
- 2:29of attendance and anything else we drop to you. You shouldn't need to, you know, follow an experiment
- 2:35or something. Rhett will walk you through the whole thing. And there's also reaction buttons. We want to
- 2:41know what you think about this whole shebang. So, please use those reaction buttons. Let us know how
- 2:46the presentation is going. And besides that, if we happen to miss a question that you drop in a Q&A
- 2:54or if it comes to you later, please reach out to us. You can reach us at physicsatvernier.com and
- 3:01you'll have that email address again later if you need to contact us. So, really quickly today,
- 3:08we are just going to go through some introductions. Rhett has an amazing presentation. We'll cover any
- 3:14questions at the end that you might want to wait for a further conversation, anything like that. But
- 3:19please feel free to be dropping that in as we're going through the presentation. And then we are doing
- 3:24a prize drawing. We're doing a $100 gift certificate to Vernier that is only open to folks who
- 3:30are still live on the meeting at the end. So, stay with us. And then a quick meet the presenters.
- 3:39So, I'll let you two introduce yourselves, but I have some fun facts up here.
- 3:45Rhett, will you go first?
- 3:47My fun fact?
- 3:49Go ahead.
- 3:50So, my fun fact that we came up with was I remember meeting Fran, I think it was at the Chicago AAPT
- 3:57meeting, and it was a long time ago. Because she was, and I knew her because she was a blogger.
- 4:02Isn't that correct?
- 4:04That's correct. Yep.
- 4:06That's my fun fact.
- 4:07Pretty cool.
- 4:08And my fun fact is that I'm learning Korean, so I can turn off the subtitles on the K-dramas
- 4:14that I watch. And the Korean there just says that I like K-dramas.
- 4:19All right. And with that, I will stop sharing my side and kick it over to you, Rhett. Thank you so
- 4:29much.
- 4:31Okay. So, what I'm going to do, the goal here is to collect data on simple harmonic motion
- 4:40and then to model simple harmonic motion numerically. And I'm going to do this in a format that I would
- 4:47do to my, for my students. So, I mean, I'm going to, I'm going to tell you things that you probably
- 4:51already know, but I'm presenting it in a way that you could do it also for your students. And this
- 4:56would work for pretty much any level. I think from, you know, high school, even algebra-based
- 5:02physics. I would even do this in calculus-based physics because it's that awesome. So, what we're
- 5:07going to do is use the GoDirect cart to collect data, and then we use Python to model it. So, I want
- 5:13to talk first about springs, mass on a spring. So, let's look at a mass on a spring. If we
- 5:22have a mass or any spring in general, and I stretch it some distance, S, then it will
- 5:33exert a force backwards. And the magnitude of that force is K times S. So, the strength of
- 5:39the force on the spring is proportional to the stretch. And this proportionality constant
- 5:43is the spring constant. Constant. Now, the first thing that we want to do in order to
- 5:53model simple harmonic motion is to determine the value of our spring constant. So, I have
- 5:57a spring. So, let me show you my spring. And you can do this with any spring, but here's
- 6:04my spring right here. I think for this particular experiment, the lower spring constant springs
- 6:11work better. But again, anything can make, you can make any of them work. So, what I want
- 6:15to do is to measure the spring constant for this. The traditional way is you would hang
- 6:19it right here. You'd place masses on there. It would stretch down. You measured the stretch.
- 6:24You can determine the force based on the gravitational force pulling it down from the mass. But we're
- 6:29going to use the cart instead because I love this method, and it's really great for other
- 6:33kinds of springs too. So, what I want to do is I have my cart already connected to LoggerPro.
- 6:38I'm going to show you, not LoggerPro, graphical analysis. I'm going to show you what it looks
- 6:44like first, and then I'll come back and I'll collect the data live. So, I'm going to move
- 6:49my camera over here just for a second. I don't have the best set up, but I think I can get
- 6:53this to work. So, here we go. There's my track. And I have my cart. It's already connected
- 7:02to the computer. I want to mount my spring somehow. Well, you can be mounted in any creative
- 7:08way, and then I want to connect it to the cart. And the track should be level.
- 7:15Now, what I can do is just pull the cart back. Since the cart measures position with the roller
- 7:22wheel and force with the front hook, I can get position and force data for both there and back
- 7:28all right at one time. Okay. So, that's what I'm going to do. So, I'm going to put it back over here,
- 7:34and then we're going to switch, and we're going to collect data for that. Okay. Let's see.
- 7:46So, this is, I have graphical analysis loaded. I've already connected my cart to the program,
- 7:56and I have all this stuff because I turned on both position and force, and I don't want all
- 8:01these graphs. So, let's just switch this to one graph, number of graphs, one. Another thing I want
- 8:07to do, and it's not super important, but the cart has the positive x direction in the direction of
- 8:14the spring. I actually want to measure positive x the other way. It doesn't matter. Okay. You still
- 8:19get the same thing. So, down here, I'm going to change my, click the position. I'm going to reverse
- 8:25the direction. I'm also going to zero it out, even though that, again, also doesn't matter. For the
- 8:30force, I'm going to zero that too. Now, I want to, I have force versus time. I'm going to change this
- 8:36to force versus position. One final thing. I'm going to switch this to collect data for 10 seconds,
- 8:44just so I have enough time. So, now I have force versus position. I'm going to collect data. I'm
- 8:51going to pull the cart back, and then I'm going to let the cart go back to its unstretched position,
- 8:56and then we'll analyze it from there. So, I'm clicking collect, and it did really slow,
- 9:07and then I'll let's zoom in so you can see what that looks like. I mean, that's actually a pretty
- 9:11awesome graph. You can see that you do have a slight different set of data for when you're
- 9:16pulling it and when you're coming back, but it's so close together that it works fine, and the slope
- 9:22of this line is the spring constant. So, that's it. Now, down here, I maybe don't want that data,
- 9:28so I'm just going to highlight that part over here, and then I'm going to go to apply curve fit,
- 9:35linear, apply, and then there's my spring constant right there. So, I have a spring constant of 7.612
- 9:42newtons per meter. Let me write that on the board before I forget. K, 7.62. What was it? 612?
- 9:55612. Of course. Yep. Okay. That's K. Now, we're going to also collect data on the oscillation of the
- 10:08cart. Now, before we do that, we're going to need the mass of the cart. You can take your cart and put
- 10:15it on a scale, but why would you do that when I can just measure the mass of the cart directly?
- 10:22So, over here, let me switch over the view options. I'm going to turn on the meters, and we can see the
- 10:29force that the cart is being pulled on, and I'm going to take the cart, and you can hold it with
- 10:35the, you can hold the cart. I'll show you a picture of this in just a second, but I'm going to, I'm
- 10:42holding it up with rubber band so that it doesn't, it's vertical, and I get 2.7. Let's go with 2.7
- 10:49newtons. So, here's what that looks like. I'll show you that. 2.7 is a, so I'm just holding up the
- 10:56cart like that, and I'm using its own force sensor to determine the weight, and then we can use that
- 10:59to determine the mass. So, I'm going to write over here, mg, 2.7 newtons. Okay. Now, I'm going to take
- 11:11my rubber band and put it back. It, for future use, if you use this method to determine the spring
- 11:17constant with the rubber band, you see that it's not a spring, and it's pretty awesome. So, the
- 11:21stretching and the unstretching are different spring constants effectively, and it depends on how fast
- 11:26you do it. Great experiment to do with the rubber band with that one, but we're going to look at
- 11:30simple harmonic motion. So, in simple harmonic motion, we have a cart, and the cart, the spring
- 11:37pulls it one way, but as it moves, the spring force changes. So, that makes it a very complicated
- 11:43situation since we have a non-constant force. The force changes the velocity, the velocity changes
- 11:49the position, the position changes the force, and so forth. It is a solvable problem, but we want to
- 11:54numerically model it. The best thing about science is building a model that agrees with real data,
- 12:04and so that's the stuff that we want here. We want to use the cart to get the real data,
- 12:08and then we can do the magic of making a model that agrees with the data. That's the real win
- 12:14right there. Okay, so I'm going to show you how I put the cart on the track, and then we're going to
- 12:19come back to graphical analysis and collect data, and then we have to do some tricks in order to get
- 12:24this in Python, and then the fun cert stuff in Python. So, what I'm going to do, let me put this on
- 12:31the track, and I'll move the camera again. Okay, let's move the camera. So, here's my track. Now,
- 12:43it doesn't want to oscillate back and forth because we have a spring that only gets pulled,
- 12:49and it doesn't compress, so you can't make it oscillate back and forth like this. However,
- 12:54you can use a trick. You can incline your track, and here I'm just going to use a textbook
- 13:01that I have. I'm going to put it under here like that. Now, there is a component of force
- 13:10in the direction down the track, and so the equilibrium position of the cart has the spring
- 13:15already stretched. Now, when I displace it a little bit like that, it will oscillate up back and forth,
- 13:21and that's what I want. Now, the steeper your track, the greater the amplitude of oscillation. If I
- 13:27pull this back too much, you can see I get slack in my spring, and I don't want that.
- 13:31There. Okay. So, I'm going to do just a really tiny oscillation. So, what I want to do is collect
- 13:38data for the position as the function of time right here, and then we're going to use that in
- 13:43our model. Okay, so let's go back to, I'm going to show you how to set this up in graphical analysis
- 13:49because there is a trick that we need. We want that position time data, and we want to export it.
- 13:55Okay. So, if I just look at the data right now, let's switch to graphical analysis. We already have
- 14:07position time data there. Okay. We use it to plot this force. If I go over here to show the data
- 14:12table, I don't want the meters. I want the data table. There is an issue that I have these time
- 14:18values right here, and the data rate for the position sensor is different than the data rate
- 14:23for the force sensor. And so, I don't want to have these spaces in between my position datas.
- 14:32So, I'm going to start over, and I'm going to not use the force sensor, and maybe there's a better
- 14:36way to do that, but it's okay to not do things the best way. We can just do it the way we want.
- 14:41So, I don't really care about saving that. And now, I'm going to do sensor collection again.
- 14:49But this time, actually, I'm going to go over here, and I'm going to turn off the force sensor.
- 14:56So, I have the sensors. I'm going to turn that off. Okay. And then, I want one graph,
- 15:02and I do want position versus time. Okay. But now, when I collect data, it won't have skipped
- 15:08all my times. It won't have time position, time position like that. And I can use it in a better
- 15:15way. Okay. So, we're ready to collect data. What I'm going to do is, let's see, this is,
- 15:21let's do eight seconds. I don't need too much time. And I'm going to leave it like that. I'm going to,
- 15:28oh, I don't, I can reset the position to zero. I can reverse the direction. It doesn't really matter
- 15:34like I had before. Now, what I'm going to do is displace a little bit and collect data. And then,
- 15:40we can move this to Python, where we can do our work. Okay. So, I'm going to click,
- 15:45I'm going to pull it down a tiny little bit, collect, collect, let go. And then, that's good
- 15:55enough. Stop. And then, let me zoom in so you can see that. So, there's two really important things
- 16:00here. One, this is simple harmonic motion, and that's pretty awesome. Number two, we don't have a
- 16:06constant amplitude, because it's not a perfect system. We can take care of that later, and that's
- 16:10part of the magic of the whole thing. So, but what we want to do here is to get this data into
- 16:17Python. And I'm going to be using web v Python. Okay. So, how do we do that? I'm going to go back over
- 16:24here. I'm going to click data table. And now, you see, I have a data table that has time and position,
- 16:29and that's exactly what I want. It starts at 0.2. That's fine. Okay. So, I don't, I know that I
- 16:39have a time interval of 0.04 seconds. So, I don't really need to copy the time data. You can if you
- 16:45want to, but I'm just going to copy the position data. So, if I click on the top up here, it will
- 16:50highlight the whole thing, and I'm just going to copy it. Now, it's a list of numbers, but in Python,
- 16:56I need it as a comma separated list, so I can, I can use it. So, how do we do that? So, I'm going
- 17:05to, this is my trick. I'm going to go to use Google Spreadsheets. So, let me switch my window over
- 17:12here. Window, is this it? I think this is it. Yeah. Okay. So, I'm in Google Spreadsheets,
- 17:29and I'm going to paste my data right here. And I already put it in the formula because I would
- 17:35forget it. But there's a formula in Spreadsheets right up here. It says equals text join, and I want
- 17:42to join all the text right here with a comma space in between them. And then, I don't know what the
- 17:48true means, but then A, A means just use the whole comma of A. So, in this one cell, I have all of my
- 17:54data as a comma separated list. So, if I click this and copy it, I have all my data. Okay. Let's
- 18:01go over to Python, and let's plot this thing and see what happens. Okay. Now, if you haven't done
- 18:08anything in Python before, it's not scary. Okay. There's some stuff to do, but it's not that bad.
- 18:16The worst part is going to be plotting this data. But I think you could do it. So, this is, there's
- 18:23several versions of Web v Python that you can use. There's GlowScript.org. There's Trinket.gopickup.org.
- 18:32This is Web v Python sponsored by GoPickup. I mean, Pickup. They're a physics integrating
- 18:40computation and physics group. This one's the one I like to use. There's also one, there's a
- 18:46Mandarin interaction server that has it too, but this is the one I always go to. GlowScript works
- 18:51just fine too. You can also run it locally, but then you have to install stuff, and I don't want
- 18:55to install stuff. So, this is, I'm logged in as Trinket, and the first thing I'm going to do is click
- 19:00right here, and then go to my name, and then click new Trinket. So, they're called Trinkets, and in
- 19:06fact, we have two kinds of Trinkets. You can just do plain Python, but we want to do Web v Python. It has
- 19:11all the stuff that we want in there. And you can see right now that we have a website with code in it.
- 19:18We can run it. We can edit it, and that's great. The other nice thing about Trinkets is that if you
- 19:23write code and you share it with your students, they can edit it, and it won't change your code, and it
- 19:28works really well that way. Okay. So, let's just add our data in here. We're going to call this X,
- 19:35and I'm going to call it XV since it's from for near, and it's going to be a list of numbers. So,
- 19:43we define lists in Python with these square brackets, and I'm just going to paste my numbers
- 19:47in there. It's a huge thing, right? And that's fine. Okay. So, now, how do I plot this, though?
- 19:55That's the question. How do I plot this? Let's go ahead and make a graph. So, in Web v Python,
- 20:03there's an object called a graph, and it makes the axes for your graph, and it doesn't make the
- 20:09function a plot. So, it's a built-in object. So, let's give it a name. You don't have to give it a
- 20:14name. I'm going to call it G1. It's an object of type graph. Now, there's a lot of properties to the
- 20:20object, the graph object. I'm going to give it, I'm going to define some of the properties.
- 20:26There's X title, which tells you your X axis. There's Y title, your Y axis, and then there's
- 20:32the size. So, I'm going to say, I want to plot position versus time. X title equals T. You can
- 20:38type whatever you want in the quotes. You could call it Bob or whatever. Y title is X. I'm giving
- 20:45it units. I put my units in square brackets. Now, because I'm zoomed in a lot on my browser,
- 20:52I'm going to change the size of my graph so that it looks better. So, I'm going to give
- 20:57it a width that's a built-in property of 500. So, that's 500 pixels wide, and then give it
- 21:03a height of 250. You don't have to do that. It'll do the default size, which is too big
- 21:08for me. Now, if I run this, nothing happens because it's just the axis. I need a function
- 21:12to plot. So, let's call this function that we plot in the graph. It's a type called G
- 21:18curve. I'm going to give it the name FV for the Vernier function, and it's a G curve. And
- 21:25again, this has properties to it. This will connect, I mean, plot the points that you want
- 21:32and connect them by a line. It won't show the points, though. I always like to give it
- 21:37a color because color is fun. So, I'm going to say color is color dot blue. There's, you
- 21:43know, blue, red, green, purple, magenta, cyan, yellow, yellow, yellow. You can think of different
- 21:50colors that you want. If you go to the help site, it tells you all the different built-in
- 21:54colors. Okay. Now, so, I have my X values. I don't have my time values. So, I'm going to
- 22:01need to plot time, too. So, in fact, I think I am going to just copy the time. I changed
- 22:08my mind. So, let's switch back over here. I'm going to go to, you can't see this. I'm
- 22:13just going to highlight my time. And now, okay, now I'm back over here. I'm just going
- 22:18to paste in my time values right there and then copy them. So, then I don't have to rebuild
- 22:23my time. You could do it either way. So, I'm going to call this TV is equal to all that
- 22:28stuff. Okay. So, now I have all my time values, I have all my position values. I can go through
- 22:34and plot them. So, let me show you how this works. I'm going to use a for loop. So, I'm
- 22:40going to say for I, and now let me type it out and then tell you what it means. In range
- 22:45length of XV. And I'm going to just to show you how it works. I'm going to print I. So,
- 22:52this goes through the list XV and calls each element the number that it is. So,
- 23:01it'll go from the first one to be zero, then one, then two, and three. So, this will go
- 23:05through the whole list and call each one I. So, you see, I have 151 elements in my
- 23:11list, which I don't really care about. But I do want to reference each element in my
- 23:16list. So, if I wanted to print out the first one, it would be XV zero. So, I can
- 23:21print XV zero. So, you square brackets and now print the first one. I can print the
- 23:28second one print as XV one and so forth. So, if I want to do that, I can and it'll
- 23:35print out that numbers. I don't want to print them. I want to plot them. So, to plot in
- 23:41Web v Python, we're just going to use our function name here, FV dot plot, and I need
- 23:47to give it my X value coordinate and my Y value coordinate. So, in this case, my X value
- 23:52is TV and my Y value is XV. And then that's going to plot it. Now, I don't need to do
- 23:59anything else because I'm already going through all these I values. This should plot what we
- 24:03have. And there you go. So, that's the data from graphical analysis. That's the
- 24:11real data that we collected. And we want to use that to make a model and compare with
- 24:16it. Now, we're going to need initial conditions. But let's just go through how we model, how
- 24:26we make a numerical model for a mouse on a spring without friction. So, it won't match
- 24:31perfectly, but we can fix that later. Okay. So, I'm going to the board and we're going to
- 24:35talk about numerical models. I should save that code if I didn't because I like to live
- 24:40dangerously. So, stop sharing. There we go. Okay. Now, we're on the board. So, I have over
- 24:45here the two things I want to save. I want to save the mass and spring constant because
- 24:53we're going to need that. Over here, let's just draw a little picture of what's going
- 24:57on. I saved that because I thought I'd forget it. So, imagine that I have my spring and this
- 25:06is x equals zero. And I pull it over here. So, now there's a force. And I'm going to use
- 25:11one-dimensional notation because we don't need two-dimensional stuff here. So, this will
- 25:16just make it a little bit easier. So, that's my spring force. And I'm assuming that it is
- 25:21horizontal. We can show later that it doesn't matter that it's vertical or horizontal. It's
- 25:26going to work out the same way, which is easy to do in Python, not easy to do in real life.
- 25:32I know the value of this force. I'm going to write it here. F net is going to be equal
- 25:39to Fs. And that's negative Kx. So, if my x is positive, the force is in the negative
- 25:47x direction. Once I get over here and I have negative x, my force is in the positive direction.
- 25:52And that's what makes it all straight back and forth. And we can set, since that's the
- 25:56only force acting on it in the system, I can set that equal to mass times acceleration.
- 26:00But, as we said before, the acceleration depends on x, and the x depends on the
- 26:06velocity, which changes with acceleration. So, that's why it's a hard problem.
- 26:11The first thing I want to do is to just solve for the value of acceleration.
- 26:14So, the acceleration is going to be negative K over M times x. And I'm going to put a box
- 26:21around that. So, the trick to numerical calculations is that if I break my motion into short time
- 26:32intervals, so let's say delta T is 0.01 seconds, then during that time interval, I can assume
- 26:43that this acceleration is constant. It's not, but it's kind of. So, I can assume that it is.
- 26:49And if I do that, then I can use the following definition for acceleration.
- 26:54I can say the acceleration is a change in velocity with respect to time. Now, imagine that I have a
- 27:04velocity right here, V1, and a little bit later, I have a velocity right here, V2. I can write this
- 27:10as V2 minus V1 over delta T. And that's true if the acceleration is constant, and it's kind of true
- 27:21if my time interval is small. But I can use this. I can multiply both sides by delta T.
- 27:26I get V2 minus V1 is A delta T. I can add V1 to both sides, and I get V2 is V1 plus A delta T.
- 27:38I'm going to put a green box around this one because I bought this colored chalk, so I've got to use it.
- 27:45This is a really important equation, too, right? Here, I can calculate the acceleration for that short
- 27:50time interval. Here, if I know the velocity at the beginning of the time interval, I can find it at
- 27:56the end of the time interval. So, this tells me something I do need to know the very, very first
- 28:01velocity. But now, let's go one step further. The definition of velocity, let's assume the velocity
- 28:08is constant, which is crazy because we just said we change it. But crazy is only a little crazy with
- 28:14little time steps. So, here I can say V is the change in X over the change in time, and that's going to be
- 28:21X2 minus X1 over delta T. And I'm going to solve this for X2, and I get X2 is X1 plus V delta T.
- 28:33What color? How about yellow? Box that one. So, here's what we're going to do. We're going to,
- 28:42one, calculate the acceleration. Two, use that acceleration to update the velocity. And then,
- 28:49oh, yellow. Three, use that velocity to update the position. Now, if I have a time interval of 0.01
- 28:58seconds, I just found out where the mass is and how fast it's going after 0.01 seconds. But we have data
- 29:04for five seconds. So, that means I need to go back up here and do it again. Now, after I move my
- 29:10position, I'm going to have a new acceleration. So, I'm going to recalculate that. And then, I have a
- 29:14new acceleration. I'm going to re-update my new velocity, update my new position, do it again and
- 29:20again and again. And this is the idea of a numerical calculation. Yes, there are much more complicated
- 29:27recipes. But this one is the easiest for students to understand. And it's very straightforward. And
- 29:35it works. Okay. So, we don't need to worry about, you know, higher order calculations here. So, this
- 29:41works really well. Spoiler alert, the order does matter. Okay. You always want to calculate the
- 29:47highest derivative things first. Acceleration, then velocity, and then position. And then, just do it
- 29:53again and again. But, like I said, in order to update the velocity to the, after that first time
- 29:58interval, I need to find the first velocity. In order to update the position, I need the first
- 30:02position. So, we need to find those first values. And the easiest thing to do is to start when the
- 30:09velocity is equal to 0. But our data doesn't have velocity is equal to 0. So, we need to, we need to
- 30:14cheat. But we're going to, this is what we're going to do in Python. We know the spring constant.
- 30:18I can calculate the mass so that I can calculate the acceleration, update velocity, update position.
- 30:24And we're going to go for it. Okay. So, let's go, let's go for it. Right here. Okay. Here's where we
- 30:34were. Now, let's run this because I want to show you something, a little trick that we're going to do.
- 30:43This is our real data. Notice up here, the way I collected data, it was already moving. It's not,
- 30:50it's not at, it's close, but it's not released from rest. That's fine. I want to use data where
- 30:56it's released from rest. So, I could use either one of these, these down here, but let's just go
- 31:00down here to this one. So, right down here at this position, at the bottom point, the slope of the line
- 31:07is zero. So, it's released from rest. So, I know the velocity of that point is zero. And now what I
- 31:12want to do is just look at the time, 0.533, and the position, negative 0.0.
- 31:20Point, is that 0.019? Yes. So, almost, almost two. Hey, Rhett. Yeah. So, we had a question.
- 31:31Could you do this using energy instead of kinematics? Yes. You can do it with energy, but the problem is
- 31:38that the energy, since energy is a scalar, it doesn't really give you the oscillation in the same way.
- 31:45One of the things that's really useful later that you can do for homework, and I'll talk
- 31:50about this at the end, is calculating the loss, the energy loss due to friction. And that will tell
- 31:56you why this thing decays like that. But if you want to do a numerical calculation and you start
- 32:01from energy, you're not going to, it's not going to work. Also, energy is a change in, deals with change
- 32:08in position instead of change in time. Is that good? He says thanks. Okay, great. Thanks for the
- 32:19question. So, right down here, I want to look at these points on my graph. It doesn't have to be
- 32:24perfect, but I do want to write them down. I'm going to write them down on the board. So, I have x1
- 32:29is negative 1.98 times 10 to negative 2. And t1 is 0.533. So, those are the values I want to start
- 32:48with when I start my numerical calculation. And again, because I know the velocity there,
- 32:54because I need to know both the velocity and the position. You could take anywhere. If I pick this
- 32:58point right here, then, oh, I say the position is 0. Maybe I'm very close to 0. But now I have
- 33:03to calculate the velocity. And I don't have that from this data. You could get it, but it's just
- 33:07easier to do it this way. Okay. So, back over here, all this did was plot our real data. What we're
- 33:13going to do now is make our numerical model. So, the first thing that I want to do is to make a graph
- 33:19to plot the numerical model. So, up here, I'm going to add a second curve. I'm going to call this
- 33:25fr for real. And I'm going to make it red. If you want, you can give it labels and stuff too,
- 33:32but I'm not going to do that. Now, down here, I need to start off with my initial conditions. So,
- 33:37I'm going to say t is 0.533. That's what I got from my data. That's the time I want to start it at.
- 33:44Okay. And then, I need to give it my initial x position, which I just said was, what did I say?
- 33:49Negative. I wrote on the board. That's why I write on the board. Negative 1.98 times 10 to negative 2.
- 33:54And I need my initial velocity. Notice that I didn't give indices here. It's just x.
- 34:01Because we're going to change the value of these variables. We're not going to keep up with all the
- 34:05different variables. Same thing. So, we need to change velocity, k, and t. Now, I do need a couple
- 34:12other things. I need my spring constant, which I said from before, 7.612. And I need my mass,
- 34:19which is going to be equal to 2.7 divided by 9.8. Now, if you're familiar with Python,
- 34:28you know this. But if you're not, we need to deal with numbers, right? So, we don't have units up here.
- 34:36Units are the job of the human. Numbers are the job of the computer. If you want to put your units
- 34:41here because it makes you uncomfortable to not have it, you can put it in as a comment like that.
- 34:47Anything after the number sign is ignored by Python. And you can put them all down here.
- 34:52But I don't normally do that. It does make the code look a little bit more cluttered.
- 34:56And for students, you know, it's more difficult to understand. If you just measured the mass of the
- 35:01cart, you could type it here. But we had 2.7 newtons divided by 9.8 newtons per kilogram.
- 35:07Finally, we need one more thing. And that's our time step. So, we have the time step from our data.
- 35:13But we don't have to have the same time step. We can use a different time step. So, I'm going to
- 35:17use, like I said, time step of 0.01 seconds. Now, what we want to do is to create a loop. We want
- 35:26to loop through the time. So, I'm going to say while t is less than 5. So, this will do in Python.
- 35:35We make a loop. It starts with a colon. And then everything that's tab indented underneath that
- 35:43is part of the loop. Once you de-dent, it's no longer in the loop. That's what we did up here.
- 35:49So, in this for loop, I have the colon. Everything that's tab indented below that's part of the loop.
- 35:55And then this is not part of the loop because it's de-dented. So, I want to do this while the value
- 36:02of t is less than 5. And so, I'm going to do this weird. What I'm going to do is just print t just so
- 36:09you can see how it works. Let's do it until it's 1. And the most important thing for a loop like this
- 36:15is that I have to update the value of time. If you do not update time, you will be stuck in an infinite
- 36:22loop, which seems fun, but it's in fact not fun. Okay. So, here's how you update time.
- 36:29There's more than one way to do it. This way, I always do it. So, this is not – I always point
- 36:34out to students that this is not an algebraic equation. This does not say t equals t plus dt
- 36:41because the t's would cancel. This says make the value of t this – what it was before – plus this dt.
- 36:49So, this changes the value of our time, our t variable. And so, now we don't have to keep track of all
- 36:56the different variables. We just change it. So, I'm going to run this. We're going to print out tons
- 36:59of numbers. I'm going to show you that it does indeed work. Let's do this. Print. Finished. Just so you can
- 37:06see that we did finish the loop. So, you see it went through all those time values. It printed them out.
- 37:14And then, when I de-dented, it said finished. Okay. So, that's how we're going to go through
- 37:19our list of calculations. I always like to put that t equals t plus dt in there right away
- 37:26because if you're typing stuff and you forget to put it – infinite loop. Awkward. Really awkward
- 37:32when you're teaching a class. Fortunately, they did add – at least in this version of Trinket – the
- 37:39play button to run it turns into a stop button. So, you actually can stop it. That's actually new and
- 37:44I like it a lot. Okay. So, what we want to do, just like we said on the board, is to first calculate
- 37:50the acceleration. So, I'm going to say –
- 37:52Pause.
- 37:53Pause. Yep. I got another question. I'm ready. In line 16, did we just tell Python to use
- 38:00interpolated values instead of the real data? Aren't we using one model to generate another?
- 38:05Right. So, this is – well, this dt is our numerical time step and it doesn't have to be the same as
- 38:13our real data. We're still going to plot them together and the data from Vernier sensor cart
- 38:21has a lower rate and we actually want to increase the rate. We can change that later and you can see
- 38:26what happens and we will do that. But these are two different – one's not a calculation. One's just
- 38:31data. And the other one is our calculation time step. So, they don't have to be the same.
- 38:38Thanks.
- 38:39Yep. Thank you. So, here's our acceleration. Actually, I should write it like this. Negative k
- 38:45times x over m. So, notice that we start off with the value of x up here. So, we start off with an
- 38:52acceleration in the positive direction because that's a negative number. That's the way we picked
- 38:57it. Now, I'm going to update the velocity. The velocity starts at zero and then I'm going to do
- 39:04this. So, just like the time down here when we're updating the value of time, this is again not an
- 39:12algebraic equal sign. It's a make equal to sign. Make equal to sign. It says take the value of the
- 39:18acceleration times dt, add that to v, and make that your velocity. Okay. And then finally, we need
- 39:23to update the position just like we did it before. And I'm using dt instead of delta v because I don't
- 39:30want to type delta. So, we're done except for the plotting. So, now I'm just going to – I'm going to
- 39:39plot this. One of the – you know, you can argue about whether you should plot before or after you
- 39:44update the time. It should probably be before. But the beauty of Python is with small time steps,
- 39:52it's not really wrong where you put this. And that's good. So, I'm going to call – I said this
- 39:56graph was called fr. And now here, I'm going to plot t on the horizontal axis and x because I'm
- 40:03generating those values. I'm not getting them from a list. I'm generating them each time. So, let's run
- 40:08this and hopefully we don't make a disaster of the whole thing and see what happens. That's
- 40:14actually pretty good. Okay. It's not exactly the same. It's not. But it's still – you get that
- 40:21cosine function or sine function depending where you put your origin, which is awesome because it's
- 40:28not in the code anywhere. And it's not perfectly the same because of this friction that we have over
- 40:35here. But it turns out that you can actually add the frictional force and make it much more the same.
- 40:43So, let's go to the board for a second and show how to do that. So, here's my net force I just have
- 40:53as a spring force. But what if I say the net force is the spring force plus some frictional force?
- 41:00So, I'm going to delete that. So, the net force is the spring force plus friction. And that's equal to
- 41:15mass times acceleration. Now, we do have a problem with the friction force because as the cart's moving
- 41:23this way, friction's that way. And the cart's moving this way, friction's that way. So, we need to
- 41:28determine the value, the direction of the frictional force based on the direction of the cart. But we
- 41:35can do that. Okay. And I'm just going to – you can measure the coefficient of kinetic friction for
- 41:41the cart, but we're just going to guess. Okay. We're just going to guess at a value and see if we can
- 41:44get it to work. So, let's switch back to the Python and my code right here. So, what I want to do
- 41:56is let's just say that if V is greater than zero, okay, if the value of V is greater than zero,
- 42:06then it's positive, then my acceleration is going to be this. And I want the friction force to be in
- 42:13the negative X direction. So, I'm going to say negative, let's say 0.001 times M times G. So,
- 42:20that'd be a coefficient of friction of 0.001. I'm just guessing here. We're going to change it.
- 42:25Okay. And if it's not greater than zero, I'm going to say else A equals negative K times X over M
- 42:33plus 0.001 times M times G. Okay. So, now I have a friction that changes direction. Let's just run
- 42:41it and see what kind of damage we did. Oh, I have an error. Good. G is not defined. I can fix that.
- 42:49G equals 9.8. Okay. So, it looks like it didn't have enough friction maybe. That's fine. Let's change
- 43:05this to five. Let's see what happens there. Okay. Now, it's starting to look better. You can see that
- 43:17the amplitude is decreasing. This red curve is my calculation. Notice that the amplitude is larger,
- 43:24so I need a little bit more friction. So, more friction. I'm just going to, I'm just manually
- 43:29changing this. I'm just guessing numbers. You could call it a variable if you want. We're getting
- 43:36really close. Okay. I think my period of oscillation is a little off. I think that's the best I can do.
- 43:44Maybe my spring constant is off a little bit or my mass is off a little bit. Let's just mainly adjust
- 43:50that spring constant. I'll make it a little bit. Which way do I want to go? Got another question?
- 43:57I'm ready. Is there a reason to use if then rather than sine of v or something similar?
- 44:06I mean, if else? You could say, yeah, you could say if v is greater than zero, do this. And you could
- 44:14say if v is less than zero, do this. But in this case, we're going to do one or the other. We're going
- 44:19to either make it a positive x component friction or negative x component friction. So, in that case,
- 44:25an if else works a little bit better. It's less cumbersome. You could just say if it's greater than
- 44:31zero, do this. If it's less than zero, do that. And that would work the same. Thanks. Okay. I'm not
- 44:39going to try to make this match perfectly. I'm happy enough with it where it is, especially doing it
- 44:45live. So, I think maybe we could stop there and if you have any questions. But I do want to point out
- 44:54one important thing. We did what we wanted, right? We have real data and we can show, even if you play
- 45:01with a little bit more, that you can make that data fit a numerical model. And then that's the win
- 45:06right there. That's the scientific process. Getting data, building a model, ensuring that
- 45:11they agree. Even if there's some messing around with it, we can make it look a little bit better.
- 45:17So, do we have any other questions? Or I think that'd probably be the best place to stop for the
- 45:23code. I'll put it back on the code. And I'll give you a link to the code, too, if you want to.
- 45:28Yeah. So, the previous question was a mistype. There's a reason to use if then rather than if
- 45:39else, or if else rather than if then.
- 45:43If then.
- 45:45Oops. No, I'm doing it wrong. Robert, could you please retype the question then?
- 45:49If we could just use one statement with
- 46:09the sine of V. So, positive or negative V instead of the if else.
- 46:15Yeah. What you could do is you could put, if you put this right here, let's just copy that
- 46:22temporarily. I just didn't think of it this way. Here, I go through and I set the acceleration.
- 46:27And then I could down here say, well, if the velocity is the other way, change it to this.
- 46:32And that would work. So, it automatically put the acceleration with a positive frictional
- 46:37force. And then it would change it to negative only if the velocity is positive. That would do
- 46:42the same thing. You know, either way is fine. I'm not a Python programmer. I just use Python
- 46:49to do physics. So, everyone does things differently. And that's fine. If you have students that come
- 46:53in that are programming, they're like, oh, I don't like this. This V equals V plus. They like
- 46:59to use equals plus sign. And that's fine if you want to do it that way. I like this way just because
- 47:04it matches what we do on the board the best. So, again, all those little things like that.
- 47:08There's a lot of different ways to get this to work. And I try to do the simplest way that makes
- 47:15the most sense to students. And really, the test is, does it match what actually happens, right?
- 47:23Like, if it's matching the actual data or not. So, another question was, does Python give better
- 47:28results than Desmos, which is more intuitive for my high school students? Well, not mine.
- 47:33I don't use, I mean, if you do, if you could do the same thing in the spreadsheet. And I remember
- 47:38a long time ago, I used to use a spreadsheet to do this exact same thing. You could do it on paper,
- 47:44right? It does, what gives the best results is your time step. And so, if you change your time step,
- 47:48let's just change the time step to 0.1. And I'm going to run this and you can see what happens.
- 47:54So, now you can see a lot blockier code, right? And the calculation isn't nearly as good.
- 48:00The smaller the time step, the better. And so, it's not Desmos versus a spreadsheet versus
- 48:07Python versus Java. It's the recipe. It's the numerical recipe that tells you whether it's good
- 48:12or not. And as long, as well as the time step, I'm going to make it even smaller. And there you
- 48:18get even better values. I don't know what Desmos does. I've just never really played with that too
- 48:25much. But if you use the same recipe, you'd get the same data. Great.
- 48:35So, then we got another question. I think we are
- 48:44not trying to discuss this model, but could you try with a drag force for friction?
- 48:50So, like a velocity-dependent force. I think you don't need that,
- 48:56based on my small amplitude. But yeah, you can put any forces that you want in here. And that's
- 49:00another thing that you can try, right? I have it at an angle. You can add a gravitational force in
- 49:05here and see what happens. And if you have a constant force added to this, it doesn't change
- 49:11the period of oscillation, which is really good. But if you want to have like, let's say, C equals
- 49:170.001. There's my drag coefficient. All I need to do is add it in my acceleration down here. Oh,
- 49:24you know what I did wrong? I didn't divide this by the mass. That was my problem. See,
- 49:29because I have the acceleration. I put it in the force. Let's see if that makes a big difference.
- 49:33Well, anyway, I'm going to add in... Again, it depends on the velocity. Actually,
- 49:38this one doesn't depend on the velocity, because if the velocity is positive, then the drag force
- 49:42would be negative. So, negative C times V over M. I'll put it down here. Negative C times V over M.
- 49:50So, that's a linear drag force, not a quadratic drag force. But you can add anything in there
- 49:55that you want. So, that one died down really quickly and just stopped. Okay? Too much drag.
- 50:01That's in oil. But you can change this drag coefficient to something small and run it.
- 50:09It's still too small. I don't know what I did wrong there. Oh, did I... Okay, I'm just going to delete
- 50:15that stuff. You could do it. How about that? The answer is you could do it. Another question is,
- 50:21would you ever have your students calculate the normal force and attempt to determine the friction
- 50:25from that? Oh, I did mess something up. Would the... So, what I would do is to measure the angle of the
- 50:40incline. You do a normal free body diagram and calculate the normal force, calculate the frictional
- 50:46force, measure the frictional coefficient experimentally, which you could do by just
- 50:50pushing the card on the track and measuring the acceleration as it rolls down the track,
- 50:54and then use that value. That would work just fine.
- 51:01And then, do students ask why you use the spring force without gravity? What happened to the gravitational
- 51:06force? Yeah. So, you can add that in there, and it works just fine. And I typically do. I don't
- 51:14normally... Normally, what I would do is have them just oscillate the spring up and down because it's way
- 51:20easier to do. But you don't get position versus time data like you do with the cart. So, you just get
- 51:26period data. And then, when I have them model it horizontally, they don't even see the spring
- 51:31or gravity, and it makes a little bit easier. But you can add that in. It works just fine if you add
- 51:35in the gravitational force. Does anyone else have any questions they want to type into the chat?
- 52:04I'm not seeing any other questions, Rhett. Okay. Well, that's fine. I mean, ask questions,
- 52:09not ask questions. It's all good with me. I have a fun time doing Python, so that's all that matters.
- 52:15Yeah. So, a question. I've used the position sensors to find force and position data on a spring.
- 52:22Could we use this with that data? So, force and position data, and then model it in Python.
- 52:31So, I mean, that's... You could plot the force as a function of position in Python for sure,
- 52:37but you don't really gain anything more than the data straight from
- 52:42graphical analysis, because you'd just be taking that data and plotting it in Python.
- 52:49We essentially did model the force of the function of distance by assuming the acceleration right here
- 52:57is negative K times X divided by the mass. So, that is this... That's using that model. That's
- 53:02choosing Hooke's Law and assuming that's the model for our spring force.
- 53:05All right. There is a question about an easy or automated way to export a CSV from the Vernier
- 53:17software. And so, I was answering that in the chat. But basically, if you show the data table
- 53:22in graphical analysis, it has to be showing. Then go up to the top left and there's that little icon
- 53:29with the dog-eared page. You'll find export there. And then from... If you click on export,
- 53:37you'll have the opportunity to export a CSV. It's pretty easy. You can also do what Rhett did
- 53:44and click at the top... Top left. Oh, yeah. Right there. Yeah. Yeah. So, you can see one of those
- 53:53choices is the CSV. But you can also just double click at the top of the column and that should
- 53:59select the entire column. And then you can use your keyboard commands to do copy and paste or your
- 54:04mouse left click or whatever. Right click, rather. The one thing that I like to do with
- 54:10the way I did it is because I want... If you have the CSV data file, it's got both of them in there.
- 54:17So, it's a little bit more work to separate them in Python in terms of time and position,
- 54:22whereas the way I did it, it already gives... We just have position. We just did position. And we just
- 54:27did time. So, it's a little bit easier to put it into Python. You can do it this way, too. There's a little
- 54:32bit more stuff that you would need to do to get that to work, though. All right. We got it. Thanks for
- 54:44that. I think Dylan has something to say. Yes. Yeah. Well, first, thank you so much, Rhett
- 54:52and Fran. What an amazing presentation. Really good conversations. So, as we were going through the
- 55:02presentation, I actually entered everyone's names into a random name generator. This is not influenced by
- 55:07the very kind compliment that was just dropped in the chat. The winner of $100 gift card to Vernier is
- 55:15Stuart F. So, congratulations, Stuart. That is what the internet decided today. I have your information
- 55:24from when you registered for the webinar. So, I'm going to email you. If you don't see an email from
- 55:29someone with an at Vernier domain, it might be in your spam. But, otherwise, congratulations.
- 55:35Congratulations, Stuart. Yes.
- 55:39All right, my friends. Any last-minute questions that anyone has for you? Let's see.
- 55:52I hope you're reading the chat, Rhett, because you're getting some compliments.
- 55:55Oh, let's see. I'm only on that. See, I need to do all chat. I don't know how to do all
- 56:00how to get that. Live view. So, it should be on the right-hand side. It might be under more.
- 56:09And it says attendee chat.
- 56:15More. There's more. Attendees.
- 56:17No, that's not the chat. And then under attendees, it should say attendee chat.
- 56:24There it is. Got it. Awesome. Thank you.
- 56:29Thank you very much. See, where am I typed in there? I think my things are big enough.
- 56:38There we go. All right. Well, I see no further questions. So,
- 56:47oh, great. Rhett popped a link to the code in there. So, you should be able to grab that.
- 56:52And then we are good. Thank you all so much for attending. And I hope you have a great rest of
- 56:59your Thursday. And wherever you are, stay warm or cool. Whatever weather would be optimal for you.
- 57:07And dry if it's wet where you are. Yes.
Discussão
Um e-mail quando alguém comentar. Sem precisar de conta.
A newsletter
Receba nossa newsletter gratuita, com novos instrumentos, preços e notícias de biotecnologia.