Skip to content

Instantly share code, notes, and snippets.

@Keno
Created September 17, 2013 20:22
Show Gist options
  • Save Keno/6600039 to your computer and use it in GitHub Desktop.
Save Keno/6600039 to your computer and use it in GitHub Desktop.
SIUnits.jl Sample usage (Solving problem from Griffiths QM chapter 5)
{
"metadata": {
"language": "Julia",
"name": "SIUnits Demo"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": "using TexExtensions\nusing SIUnits",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Constants\n\u0127 = 1.05457 * 10.0^(-34) * (Joule*Second)\n# Electron mass\nm = 9.18938 * 10.0^(-31) * (KiloGram)\n# Avogadro's number\nN_a = 6.02214129 * 10.0^23 * Mole^(-1);",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 45
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "Griffiths 5.16"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Given Quantities\n # Mass-density\n \u03c1_copper = 9.86*(Gram/CentiMeter^3)\n # Atomic Weight \n M_copper = 63.5*(Gram/Mole);",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "a)"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Assumptions\nq = 1",
"language": "python",
"metadata": {},
"outputs": [
{
"latex": "\\[1\\]",
"metadata": {},
"output_type": "pyout",
"prompt_number": 13,
"text": "1"
}
],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Calculating the Fermi Energy of Copper\nN = N_a\nV = M_copper/\u03c1_copper\n# Equation 5.42\n\u03c1 = (N*q)/V\n# From Equation 5.43\nE_f = (\u0127^2/(2m)) * (3*\u03c1*\u03c0^2)^(2//3)\nas(E_f, ElectronVolt)",
"language": "python",
"metadata": {},
"outputs": [
{
"latex": "\\[7.446879565794478\\;\\text{eV}\\]",
"metadata": {},
"output_type": "pyout",
"prompt_number": 14,
"text": "7.446879565794478 eV"
}
],
"prompt_number": 14
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "b)"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Calculate the velocity\nv = sqrt(2*(E_f/m))",
"language": "python",
"metadata": {},
"outputs": [
{
"latex": "\\[1.6114403910119676\\times 10^{6}\\;\\frac{\\text{m} }{\\text{s} }\\]",
"metadata": {},
"output_type": "pyout",
"prompt_number": 25,
"text": "1.6114403910119676e6 m s\u207b\u00b9"
}
],
"prompt_number": 25
},
{
"cell_type": "code",
"collapsed": false,
"input": "# For comparison, the speed of light\nc = 299_792_458*Meter/Second\nv/c",
"language": "python",
"metadata": {},
"outputs": [
{
"latex": "\\[0.005375186559936633\\]",
"metadata": {},
"output_type": "pyout",
"prompt_number": 29,
"text": "0.005375186559936633"
}
],
"prompt_number": 29
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "c)"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Constants\nkB = 1.38065 * 10.0^(-23) * Joule/Kelvin;",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 33
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Calculate the Fermi Temperature\nT = E_f/kB",
"language": "python",
"metadata": {},
"outputs": [
{
"latex": "\\[86417.38257559626\\;\\text{K} \\]",
"metadata": {},
"output_type": "pyout",
"prompt_number": 34,
"text": "86417.38257559626 K "
}
],
"prompt_number": 34
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "d)"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Equation 5.46\nP=((3\u03c0^2)^(2/3)*\u0127^2)/(5m) * \u03c1^(5//3)",
"language": "python",
"metadata": {},
"outputs": [
{
"latex": "\\[4.462711654221244\\times 10^{10}\\;\\frac{\\text{kg} }{\\text{m} \\;\\text{s}^{2}}\\]",
"metadata": {},
"output_type": "pyout",
"prompt_number": 44,
"text": "4.462711654221244e10 kg m\u207b\u00b9s\u207b\u00b2"
}
],
"prompt_number": 44
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "Problem 5.17"
},
{
"cell_type": "code",
"collapsed": false,
"input": "B=(5//3)P",
"language": "python",
"metadata": {},
"outputs": [
{
"latex": "\\[7.437852757035406\\times 10^{10}\\;\\frac{\\text{kg} }{\\text{m} \\;\\text{s}^{2}}\\]",
"metadata": {},
"output_type": "pyout",
"prompt_number": 45,
"text": "7.437852757035406e10 kg m\u207b\u00b9s\u207b\u00b2"
}
],
"prompt_number": 45
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment