Skip to content

Instantly share code, notes, and snippets.

@Tsangares
Last active February 5, 2019 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tsangares/b427680adb92544ae47e47d83ac3c471 to your computer and use it in GitHub Desktop.
Save Tsangares/b427680adb92544ae47e47d83ac3c471 to your computer and use it in GitHub Desktop.
Programming Assignent For Phys 9A

Hi all,

The first thing I would like to do is use the library matplotlib to plot the normal distrubution with μ = 0 and σ = 1.

To import matplotlib you use the statement:

import matplotlib.pyplot as plt

Now you can plot make plots using plt.plot() like plt.plot([0,1,2,3],[0,1,2,3]), and to show them use plt.show() (it might be different on juipiter).

To make this plot, I would like you to use numpy.linspace; to import: from numpy import linspace You can use linspace like so:

linspace(0,1,11)
#OUTPUTS: array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ])

An incredibly useful skill with programming is being able to formulate your questions and querying them on Google, or DuckDuckGo to find your answer. I would like you to do that to learn about linspace and matplotlib.pyplot; also, feel free to ask me questions on discord.

The task is follows:

  • Plot a normal distribution with μ = 0 and σ = 1
  • Find the maximum y-value of this plot. The constant in front of the exponential component of the equation can be 1 or 1/sqrt(2*pi*sigma^2) or you can find the max y-value for both.

Some of you have already done this so here is another plot I would like to see:

  • Plot the random distribution using from random import random; random() will output a real number between 0-1. Generate an array of 10,000 random numbers, and plot them using the matplot lib histogram. If my array of random numbers was [.4,.2,.053], I would plot them like plt.hist([.4,.2,.053]).
  • Find the standard devation and average of the random distribution. If you are using python3 you can import the statistics library using import statistics, then to find the standard devation and mean is simply: statistics.stdev([.4,.2,.053]) and statistics.mean([.4,.2,.053]). Again, I am assuming my list of random numbers is [.4,.2,.053].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment