 I'm going to show you, this is Khan Academy's new, quite awesome, computer science module, and I'm going to show you how I use it to make a program to do numerical modeling in physics. Okay, so why this particular platform? The cool things about this, I've already written a program here and I'm going to explain to you how it works, but one of the cool things, let me just show you, is that I can go over here and change these, I can click on a variable right there and this window comes up and I can actually just drag it and it changes dynamically the position of the object right away, so let me put this back to 400. You can do that too for colors, if I click this background color up here, this little thing pops up and you can choose whatever color you want. If you have an error in your code, let me delete this thing, it gives you a little error message and show me where the problem is and it says I think you're missing something. This is something that's always bothered me about computer programs, is that if you know there should be a semicolon there, maybe you could just put it, but I got it. I got it, okay, because you know, then it wouldn't be me. And so you can share it, you can save it. Their tutorials are very nice, they have a little play button down here and you can pause it and interact with the code at any time. So it gives you this real output window and the code is fairly nice. It's not Python, but you know. So let me show you how this simple program works and I'm going to run it right now. Instead, let me show you some important things about this and I'll explain everything in here. Okay, so first I drew a picture, here's a picture I drew. So this is the, one of the things, here's the window with a whole bunch of too much code on there, but. So the first thing is that the origin in this display is up here in the corner in the upper left hand corner. So that's positive X and that's positive Y. That's not perfect, but we can deal with it. So what we're going to use here is, I want to model the motion of a ball going up in the air, using basic physics. So the first idea that I want to use is this right here. This definition of velocity is the change in position over change in time. So what I can do with that is say delta Y is Y2 minus Y1, here's Y2, here's Y1. And I can get this equation right here. Pretty straightforward. Y2 equals the position where it was, plus, and here I put V1 because I'm being tricky, times the change in time. So if I have a time step on my computer, some small time step, and I know the velocity, and I know where it was, I can find out the new position. So I can say, here's where the ball was, and now here's where the ball is going to be, and I can tell the computer to draw it there. Now if this is projectile motion, then the velocity is not going to be constant. If it were, then I just have some value right there. Okay, so let's look at this side over here. How do I find the new velocity? If the ball is going up, and I know the acceleration, acceleration is defined as the change in velocity over time. And I'm not using vectors in this case, just to make it, I want to make it as simple as possible. Oh, before I forget, this is 200 pixels this way and 400 down. So it's 200 by 400. But then I can use the same idea right here to solve for the final velocity. So v2, the velocity at this position, is going to be whatever it was before, v1, plus acceleration times the change in time, whatever that change in time is. And now here's the big trick in numerical modeling. If delta t is really small, a small time step, then I can use the velocity, I really want this is really the average velocity, which would be the average of these two numbers. But if I haven't calculated that velocity yet, then I can't do that. But if the time step is small, then v1 is going to be very similar to v2. And so it doesn't really matter which one I use. And this is what we're going to do in the program is to take these small time steps, calculate a position, the new position after a small time, and the new velocity after a small time. And then start over and do it again, and do it again, and again, and again. And that's where the computer comes in. So here's the program. Let me explain the different parts of it. This just, I don't think I actually need this first line right here, but it's there. So this first variable, one of the things when you play with this and say, what does this variable do? Well, click on it and change it and you can see. That's one of the nice things you can do. In this case, changing the other variables won't do too much. I can change it later. So that's where it starts, 400 down here at the bottom. This is my time delta t, I'm calling it dt. And then here's my initial velocity, which is up, right? I put negative 50, that's this way. And then I have here the starting time and the acceleration, which I just called dt. I probably should call it a, but whatever. Sorry. Okay. That's just so we can, the t is needed just so I can keep track of time. This is something that I'm pretty sure I calculated correct, but I might not have, but you can't control that I know of so far, it could be wrong, how fast it does each loop. So I've calculated that it's one second in here is 0.035 seconds in real life. So one second in real life is 28.6 at the Khan Academy seconds. So here's the main part of the program. When you put this draw equals function and anything in here, it just keeps on repeating and doing. Okay. So this is what I have in each, let's just go through each line. This first part right here, background, sets the color. If you don't have that in here and you should try moving it out, then it won't redraw the background and so you'll keep on getting a ball each, it won't delete the old balls. Okay. Ellipse, this draws the circle right here. So this is the x position, the y position, you see I used the variable y from up here. So whatever y is, it puts right down there. And this is the x and the y width. You can see you can change this, let me change the y one. So it makes it skinny or whatever. The color of the ball, if that's important to you, is from the fill. Okay. You click this and see I have it as red. But you can change that if you want. Let's make it blue. Boom. Blue ball. Okay. I like red. Why do I change it? Okay. That's kind of pinky. See what happens when you change? Never change. Now it's still pink. Oh, I know. I can just change this to zero. It was 25500. There. Okay. So this part right here, all this stuff, this just writes this text in here. Okay. So this t equals puts that t equals and then I have the actual t, the variable t, it prints out the time. This is the x and y coordinate of where I want those locations to be. So I had to, you just have to play around with these a little bit, but you can see here if I click this, I can move t back and forth and you can play with it and get it the way you like it. For here for the y, I want this to be positive y. So make this 400 and this zero. So I just put 400 minus y. I don't know. I just like that. Okay. So here's the physics part. So here I put an if loop. You don't have to have this. You can put this without that and it would just keep running forever. But I want this, I want to shoot the ball up, have it go up and come back down and stop when it gets to here. So I said as long as the y variable is less than or equal to 401, remember 401 is right below this little window here, then do the following. First thing I do is this is just like y equals y plus v delta t. That's just like going back over here, this. Now there is one small difference. Where was I? Okay. This is not an equal sign. That's an assign sign. That says make y equal to whatever value it was before plus v delta t. Okay. So it's not an equal sign. And then this, it's just like the v2 equals v1 plus a delta t, okay. And then I'm also doing the same thing for time. So I'm changing time. Actually, if you took this out, the program would still run. That time just wouldn't change. Okay. So let's go ahead and run the program. And then so it keeps on doing whatever is in this thing until y gets less than 401. The restart, and it's not real fast because I had to go 50 meters per second up. And you can see that it's pretty high. And so this is the con time, not real time. Yeah. But that would be the time it would take a ball to go that high and come back down. So now it's coming back down. And what did I say I was going to change? Okay. There are all sorts of things you could change here, but I want to show you something. Okay. So it's done running. I'm going to go down here and press return. Now I'm going to say, what if I want to know the final velocity? Let's just put text v and then let's put 0, 0, put it up in the corner. Oh, you can't read it. Okay. Let's move this to 100, 100. Oops. I guess it didn't. Why didn't it print it there? Let's see if I put it in here. There. Okay. So I can find the velocity. You see the velocity when it ends is about the same as what it started except this is negative, right? Because remember everything's backwards. So you can write down things that you want and find things. You can actually use this to do useful stuff. And this is a very simple case, but you can use it. Okay. So I'll link to this and you can play with it. And make sure you say, okay, what happens if I change the time interval? So go over here and let's make this, ooh, not that, let's make it 1 and let's make it 0.1. You have to put 0.1 or it gets angry. And then restart. See, cool, huh? I'm pretty excited. Okay.