## Announcements

1. No more reading quizzes. I am tired of writing them and I don’t think they are doing too much in terms of helping. From now on, just read the book and we can all be happy.

2. I forgot to pass back the chapter 6 quiz today. I will give you extra time to submit a video reassessment for this standard.

## Energy and Launching stuff

Here is a comparison of launching rockets from a mountain vs. the equator.

http://www.wired.com/2011/07/space-shuttle-launch-equator-vs-mountains/

## Colliding Planets Problem

Here is the problem I suggested in class.

## GlowScript Tutorial 7: Useful Projectile Motion

Now you know enough stuff (from previous tutorials) to do something useful. Let’s start with a simple question: at what angle should you shoot a projectile to get the maximum range? If you just shout out “45 degrees” – you just memorized that. Let’s see if we can reproduce that with GlowScript.

Here is a starter program. http://www.glowscript.org/#/user/rhettallain/folder/phys221/program/GStutorial7changingprojectile

It looks like this:

This program first creates a function called “proj” (which is short for projectile motion). You give the function an initial velocity magnitude and angle and it models a thrown ball with that same starting velocity. The model shows the motion of the ball starting from y = 0 back to y = 0 (so on flat ground). The inside of the function looks just like your previous projectile motion program.

Notice that the function does not have a “return” statement. Instead, it just displays the motion of the ball. After the function, there are three instances that call the function. All start with the same initial speed but at different angles. When you run it, you get this:

Notice that I didn’t bother to draw the ground. Why would that matter? In fact, I don’t need to draw the ball at all. If I don’t make a sphere, GlowScript won’t create the 3d environment. Let me remove the sphere from the function and have it return the final x position. Here’s what the function now looks like.

This is essentially the same program. The big difference is the lack of objects (sphere) and the function returns the final x position and time. When you run it, you get this.

Each time the function is called, it prints out both the final x and the final time. I could just print the x position with this line.

Since the function produces two values, it gives them as a list. We can reference the first item in a list as proj(4,.2)[0] and the second item as proj(4,.2)[1] (remember that lists start with the index 0 not 1).

We are now ready to do some serious stuff. Here is the plan. Pick some starting launch velocity and some angle (a small angle). Run the projectile function and produce the final position of the projectile. Plot the starting angle and the final position. Repeat until you get to some very large angle. This should make a graph.

Here is a starter program with some blanks for you to fill in.

http://www.glowscript.org/#/user/rhettallain/folder/phys221/program/maxrangeexample

And this is the important part (the program won’t run until you fix it.

Clearly “stuff” shouldn’t be there. You will need to make some changes. Also notice that I used the variable v and theta1 instead of v0 and theta. Since these same variables are used inside the function, some would say it would be bad form to also use them outside the function.

When you fix it, you should get an output like this:

This shows a maximum range at around 45 degrees. Boom. Oh, why is the line squiggly? I will let you play with the code and see if you can figure that one out.

Next, something super useful. I mean, we already knew the answer for maximum range, right? What if I shoot the ball from a starting location that is 1 meter above the ground? At what angle will it go a maximum distance? Hint: you only need to change one thing in your program. Double hint: here is the output you should get.

**Homework**

There are many things left to explore. Here are some things you can try.

- What is the launch angle that gives the greatest time of flight?
- What if you add air resistance (see a previous tutorial)? What is the launch angle for a ping pong ball fired at a speed of 12 m/s?
- What if you start the ball on the ground a distance of 1 meter away from a vertical wall? What angle should you launch the ball (speed of 4 m/s) so that it hits the vertical wall at the highest point?
- If you shoot the ball starting 1 meter off the ground, does the angle for max range change with launch speed?
- What if you start from the ground and launch up to a table that is 1 meter off the ground? What is the angle for the maximum range? This is a little bit tougher since you will need to change the loop condition in your projectile function.

## GlowScript Tutorial 6: Functions

You want to do cool stuff with numerical calculations, right? Well, you can only go so far before you need to learn about functions.

Actually, functions aren’t anything new. You have already used functions like mag() and norm(). Let’s make our own function. Take a look at the following simple program.

When you run that, it should look like this:

This function is created in line 3 with “def”. Test is the name of the function and x and y are the two parameters that you pass to it. Anything indented after the def statement is part of the function. The “return” line tells the function what to give back when you call it.

Maybe that sounds confusing. Of course this “test” function is sort of silly. How about I make a function that recreates the magnitude of a vector. It would look like this.

Be aware that I have to use a unique name for this function. I couldn’t call it “mag” since that’s already used. Anything inside the function (like tempmag) only exists inside the function. I can give three different things to the function when I call it.

- A variable that is a vector (like A or B).
- A vector – like vec(-1,3,4)
- or a scalar (like 3).

Here is what happens when I run this program.

It appears that the first three times the function works correctly. When you give it a scalar, the function basically replies “dude. I don’t know what you are doing.” Your function uses the components of a vector. If you don’t give it a vector, it won’t work. The output says “NaN” which stands for “Not a Number”.

Ok, one more function. What if I want to sum the numbers up to a certain number. For instance, if I gave it 4, I would want it to calculate 1+2+3+4 = 10. Here is that function.

I guess I should have talked about loops first. Right? I feel dumb now although I technically DID talk about loops in previous tutorials when we used the “while” loop. Here is another kind of loop, he “for” loop. This “for” loop makes values of i for everything in n. Here is a super simple loop example.

Running gives this:

You can use any variable instead of “i” – but it will start from the value 0. That’s why my dumb counting function adds i+1 to the sum for each loop. Maybe it was a bad example of a function.

In the next tutorial we will do some physics using functions.

## GlowScript Tutorial 5: Air Resistance

Now you are probably ready to do something with GlowScript that you couldn’t do with paper and pencil. Let’s look at the motion of an object with a air resistance force. Usually, we pick objects that have a negligible air resistance force to make things simpler. The time for simple is past.

Ok, as an introduction to the air resistance force imagine that you are in a car with your hand out the window. You can easily feel the air pushing on your hand as the car moves. How hard does this air push? Here are some things you should be able to notice.

- The faster the car drives, the greater the air resistance force.
- If you make your hand into a fist, you decrease the cross sectional area and also decrease the force.
- The air resistance force pushes in the opposite direction as the motion of the car.

There are two other things about the air resistance force. First, it depends on the density of air. We typically use a value of about 1.2 kg/m^3 for the density of air (and it doesn’t change all that much). Second, the air resistance force depends not only on the size of the object, but the shape. If you put a cone on the front of a circle, it would have less air force than a flat circle.

With this in mind, we can write the following expression for the air resistance force.

Now, how do we add this force in GlowScript? Let’s start with the previous example on projectile motion. You need to add the following constants.

If you are looking at your projectile motion calculation, you might notice that I changed the mass of the ball from 100 grams to 10 grams. If you have a large mass, the air resistance force doesn’t change the velocity very much. Now you just need to add this force into your program. Here is what your old Fnet calculation should look like.

You just need to add the air resistance force into that equation. Here are some hints:

- Remember that mag() gives you the magnitude of a vector and norm() gives you a unit vector.
- You might want to write the velocity as ball.p/ball.m – if you write this as a velocity vector you will also need to calculate the velocity each time you go through the loop.
- The unit vector for momentum and velocity are in the same direction and have the same magnitude.

Add in the air resistance and see if you can get it to work. How will you know if it works? If you use a ball mass of 10 grams, a radius of 2 cm and an initial velocity of 4 m/s at a 60 degree angle, the final x-position should be 0.33 meters (remember the ball started at x = -1). If you put a statement after the loop, you can print the final position of the ball – like this:

Of course, that ball was not thrown very far. What if you increase the launch speed? But you still have a problem. How big of a difference does air resistance make? Here is one way to find out.

- Add a second ball (you can call it ball2).
- Give ball2 the same mass and initial momentum as the first ball. You can give it a different color.
- In your loop, calculate the force on ball2 as only the gravitational force. Update ball2’s momentum and position.

Now you have a reference ball without air resistance. You can test the limits of your ball with air resistance. Consider the following questions (and test them).

- What if you increase any of the following: density of air, drag coefficient, ball size? What should happen to the motion of the ball with air resistance? You can just print out the final position of the ball and compare it to the reference ball.
- What if you decrease the mass of the ball? What should happen?
- What if you put the density of air at 0? Would should you get?

## Video Reassessments

This is your final warning regarding videos that you send to me. Your reassessments must meet the following criteria:

- Include in your email: your name, the standard being reassessed, a description of the question being answered, and a link to the video.
- The video needs to be set to public or unlisted. I can not see private videos
- The video should be shorter than 5 min.
- I like videos that are horizontal and not vertical – but I will still watch vertical videos.
- If I have to turn my head to see the video (horizontal video that is uploaded vertical or the other way), I get cranky. Cranky Dr. Allain means lower scores.
- You should have two people watch the video before you send it to me – but I don’t actually check that.
- The video needs to be submitted within 2 weeks of taking the in class test.