Day 6 - pre-class assignment

Goals for today's pre-class assignment

  • Use numpy and pyplot to create some plots!
  • Write a simple loop using numpy

Assignment instructions

No need to watch any videos for this one. Some useful resources are:

Recall that to make notebook cells that have Python code in them do something, hold down the 'shift' key and then press the 'enter' key (you'll have to do this to get the YouTube videos to run). To edit a cell (to add answers, for example) you double-click on the cell, add your text, and then enter it by holding down 'shift' and pressing 'enter'

This assignment is due by 11:59 p.m. the day before class, and should be uploaded into the "Pre-class assignments" dropbox folder for Day 6. Submission instructions can be found at the end of the notebook.

Question 1: In the cell below, use numpy's 'arange' method to create an array called 'x1' that goes from 0.0 to 20.0 with a stepsize of 4.0. (hint: remember that you can look up how 'arange' works using the help() command or a question mark after the method name!). After you do that, create an array called y1 that is equal to the sine of x1, using the numpy sine method (i.e., using np.sin() rather than the math module's sin() method). Plot x1 and y2 with a red solid line.


In [ ]:
# put your code here.

Does the plot above look like a sine function? Why or why not?

put your answer here!

Question 2: In the space below, use the same methods as before to make an array called x2 that goes from 0.0 to 20.0 with a stepsize of 1.0. Then, create an array called y2 that's equal to the sine of x2. Plot x1 vs. y1 and x2 vs. y2 on the same plot, using a red solid line for x1/y1 and a blue solid line for x2/y2.


In [ ]:
# put your code here.

Question 3: Finally do the same thing as above, but with a third array x3 that goes from 0.0 to 20.0 with a stepsize of 0.1, and an array y3 that is the sine of x3. Plot all three functions on the same plot, using the same colors as above for x1/y1 and x2/y2, but a black dashed line for x3/y3 (note: the symbol for black is 'k').


In [ ]:
# put your code here

How did your plot of sin(x) change appearance as you increased the resolution of your x-array from dx = 4 to dx = 0.1? What does this tell you?

Put your answer here!

Question 4: Finally, write a small program that loops over the array x2, and for each value of x in x2 prints out x2, sin(x2) + cos(x2), and $\sin^2(\mathrm{x2}) + \cos^2(\mathrm{x2})$.

(Hint: don't forget the numpy nditer() method and the The numpy video from last week!)


In [ ]:
# put your code here!

Give us your feedback on the class!

Feedback 1: How do you feel you’re doing in class?

put your feedback here!

Feedback 2: If you could change something about how your group works, what would it be?

put your feedback here!

Feedback 3: Do you have any other thoughts about how class is going so far, or how we could improve your learning environment?

put your feedback here!

Assignment wrapup

Question 5: What questions do you have, if any, about any of the topics discussed in this assignment after watching the videos, reading the link to the Python tutorial, and trying to write the programs?

Put your answer here!

Question 6: Do you have any further questions or comments about this material, or anything else that's going on in class?

Put your answer here!

Question 7: How long did this assignment take you to complete?

Put your answer here!

Congratulations, you're done!

Submit this assignment by uploading it to the course Desire2Learn web page. Go to the "Pre-class assignments" folder, find the dropbox link for Day 6, and upload it there.

See you in class!