Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added ipynb for lectures
  • Loading branch information
rcc02007 committed Mar 9, 2017
1 parent e2b2c99 commit 0f702b6
Show file tree
Hide file tree
Showing 4 changed files with 1,283 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
@@ -1,6 +1,7 @@
# Computational Mechanics
## ME 3255 Spring 2017
### Github page: [https://github.uconn.edu/rcc02007/ME3255S2017.git]
### Public (ipynb rendering)[https://github.com/cooperrc/ME3255S2017]

### Course Description
This course introduces students to scientific programming utilizing Matlab/Octave.
Expand Down
366 changes: 366 additions & 0 deletions lecture_01/lecture_01.ipynb
@@ -0,0 +1,366 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Freefall Model\n",
"## Octave solution (will run same on Matlab)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%plot --format svg"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"set (0, \"defaultaxesfontname\", \"Helvetica\")\n",
"set (0, \"defaultaxesfontsize\", 18)\n",
"set (0, \"defaulttextfontname\", \"Helvetica\")\n",
"set (0, \"defaulttextfontsize\", 18) \n",
"set (0, \"defaultlinelinewidth\", 4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Define time from 0 to 12 seconds"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t =\n",
"\n",
" 0\n",
" 2\n",
" 4\n",
" 6\n",
" 8\n",
" 10\n",
" 12\n",
"\n"
]
}
],
"source": [
"t=[0,2,4,6,8,10,12]'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Define constants and analytical solution (meters-kilogram-sec)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"v_analytical =\n",
"\n",
" 0.00000\n",
" 18.61630\n",
" 32.45521\n",
" 40.64183\n",
" 44.84646\n",
" 46.84974\n",
" 47.77002\n",
"\n"
]
}
],
"source": [
"c=0.25; m=60; g=9.81; v_terminal=sqrt(m*g/c);\n",
"\n",
"v_analytical = v_terminal*tanh(g*t/v_terminal)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"v_numerical =\n",
"\n",
" 0.00000\n",
" 19.62000\n",
" 36.03213\n",
" 44.83284\n",
" 47.70298\n",
" 48.35986\n",
" 48.49089\n",
"\n"
]
}
],
"source": [
"v_numerical=zeros(length(t),1);\n",
"for i=1:length(t)-1\n",
" v_numerical(i+1)=v_numerical(i)+(g-c/m*v_numerical(i)^2)*2;\n",
"end\n",
"v_numerical"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Display time, velocity (analytical) and velocity (numerical)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"time (s)|vel analytical (m/s)|vel numerical (m/s)\n",
"-----------------------------------------------\n",
" 0.0 | 0.00 | 0.00\n",
" 2.0 | 18.62 | 19.62\n",
" 4.0 | 32.46 | 36.03\n",
" 6.0 | 40.64 | 44.83\n",
" 8.0 | 44.85 | 47.70\n",
" 10.0 | 46.85 | 48.36\n",
" 12.0 | 47.77 | 48.49\n"
]
}
],
"source": [
"fprintf('time (s)|vel analytical (m/s)|vel numerical (m/s)\\n')\n",
"fprintf('-----------------------------------------------')\n",
"M=[t,v_analytical,v_numerical];\n",
"fprintf('%7.1f | %18.2f | %15.2f\\n',M(:,1:3)');"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"420px\" viewBox=\"0 0 560 420\" width=\"560px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"\n",
"<title>Gnuplot</title>\n",
"<desc>Produced by GNUPLOT 5.0 patchlevel 3 </desc>\n",
"\n",
"<g id=\"gnuplot_canvas\">\n",
"\n",
"<rect fill=\"none\" height=\"420\" width=\"560\" x=\"0\" y=\"0\"/>\n",
"<defs>\n",
"\n",
"\t<circle id=\"gpDot\" r=\"0.5\" stroke-width=\"0.5\"/>\n",
"\t<path d=\"M-1,0 h2 M0,-1 v2\" id=\"gpPt0\" stroke=\"currentColor\" stroke-width=\"0.190\"/>\n",
"\t<path d=\"M-1,-1 L1,1 M1,-1 L-1,1\" id=\"gpPt1\" stroke=\"currentColor\" stroke-width=\"0.190\"/>\n",
"\t<path d=\"M-1,0 L1,0 M0,-1 L0,1 M-1,-1 L1,1 M-1,1 L1,-1\" id=\"gpPt2\" stroke=\"currentColor\" stroke-width=\"0.190\"/>\n",
"\t<rect height=\"2\" id=\"gpPt3\" stroke=\"currentColor\" stroke-width=\"0.190\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<rect fill=\"currentColor\" height=\"2\" id=\"gpPt4\" stroke=\"currentColor\" stroke-width=\"0.190\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<circle cx=\"0\" cy=\"0\" id=\"gpPt5\" r=\"1\" stroke=\"currentColor\" stroke-width=\"0.190\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt6\" stroke=\"none\" xlink:href=\"#gpPt5\"/>\n",
"\t<path d=\"M0,-1.33 L-1.33,0.67 L1.33,0.67 z\" id=\"gpPt7\" stroke=\"currentColor\" stroke-width=\"0.190\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt8\" stroke=\"none\" xlink:href=\"#gpPt7\"/>\n",
"\t<use id=\"gpPt9\" stroke=\"currentColor\" transform=\"rotate(180)\" xlink:href=\"#gpPt7\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt10\" stroke=\"none\" xlink:href=\"#gpPt9\"/>\n",
"\t<use id=\"gpPt11\" stroke=\"currentColor\" transform=\"rotate(45)\" xlink:href=\"#gpPt3\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt12\" stroke=\"none\" xlink:href=\"#gpPt11\"/>\n",
"\t<path d=\"M0,1.330 L1.265,0.411 L0.782,-1.067 L-0.782,-1.076 L-1.265,0.411 z\" id=\"gpPt13\" stroke=\"currentColor\" stroke-width=\"0.190\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt14\" stroke=\"none\" xlink:href=\"#gpPt13\"/>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"textbox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"white\" flood-opacity=\"1\" result=\"bgnd\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"bgnd\" operator=\"atop\"/>\n",
"\t</filter>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"greybox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"lightgrey\" flood-opacity=\"1\" result=\"grey\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"grey\" operator=\"atop\"/>\n",
"\t</filter>\n",
"</defs>\n",
"<g color=\"white\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"\t<g shape-rendering=\"crispEdges\" stroke=\"none\">\n",
"\t\t<polygon fill=\"rgb(255, 255, 255)\" points=\"43.6,378.0 530.7,378.0 530.7,19.6 43.6,19.6 \"/>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"rgb(255, 255, 255)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M43.6,378.0 L58.3,378.0 M530.8,378.0 L516.1,378.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"Helvetica\" font-size=\"18.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(33.9,384.7)\">\n",
"\t\t<text><tspan font-family=\"Helvetica\">0</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M43.6,306.3 L58.3,306.3 M530.8,306.3 L516.1,306.3 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"Helvetica\" font-size=\"18.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(33.9,313.0)\">\n",
"\t\t<text><tspan font-family=\"Helvetica\">10</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M43.6,234.6 L58.3,234.6 M530.8,234.6 L516.1,234.6 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"Helvetica\" font-size=\"18.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(33.9,241.3)\">\n",
"\t\t<text><tspan font-family=\"Helvetica\">20</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M43.6,162.9 L58.3,162.9 M530.8,162.9 L516.1,162.9 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"Helvetica\" font-size=\"18.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(33.9,169.6)\">\n",
"\t\t<text><tspan font-family=\"Helvetica\">30</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M43.6,91.2 L58.3,91.2 M530.8,91.2 L516.1,91.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"Helvetica\" font-size=\"18.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(33.9,97.9)\">\n",
"\t\t<text><tspan font-family=\"Helvetica\">40</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M43.6,19.5 L58.3,19.5 M530.8,19.5 L516.1,19.5 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"Helvetica\" font-size=\"18.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(33.9,26.2)\">\n",
"\t\t<text><tspan font-family=\"Helvetica\">50</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M43.6,378.0 L43.6,363.3 M43.6,19.5 L43.6,34.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"Helvetica\" font-size=\"18.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(43.6,405.7)\">\n",
"\t\t<text><tspan font-family=\"Helvetica\">0</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M124.8,378.0 L124.8,363.3 M124.8,19.5 L124.8,34.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"Helvetica\" font-size=\"18.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(124.8,405.7)\">\n",
"\t\t<text><tspan font-family=\"Helvetica\">2</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M206.0,378.0 L206.0,363.3 M206.0,19.5 L206.0,34.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"Helvetica\" font-size=\"18.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(206.0,405.7)\">\n",
"\t\t<text><tspan font-family=\"Helvetica\">4</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M287.2,378.0 L287.2,363.3 M287.2,19.5 L287.2,34.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"Helvetica\" font-size=\"18.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(287.2,405.7)\">\n",
"\t\t<text><tspan font-family=\"Helvetica\">6</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M368.4,378.0 L368.4,363.3 M368.4,19.5 L368.4,34.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"Helvetica\" font-size=\"18.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(368.4,405.7)\">\n",
"\t\t<text><tspan font-family=\"Helvetica\">8</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M449.6,378.0 L449.6,363.3 M449.6,19.5 L449.6,34.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"Helvetica\" font-size=\"18.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(449.6,405.7)\">\n",
"\t\t<text><tspan font-family=\"Helvetica\">10</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M530.8,378.0 L530.8,363.3 M530.8,19.5 L530.8,34.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"Helvetica\" font-size=\"18.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(530.8,405.7)\">\n",
"\t\t<text><tspan font-family=\"Helvetica\">12</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M43.6,19.5 L43.6,378.0 L530.8,378.0 L530.8,19.5 L43.6,19.5 Z \" stroke=\"black\"/></g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"\t<g id=\"gnuplot_plot_1a\"><title>gnuplot_plot_1a</title>\n",
"<g color=\"white\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"4.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"4.00\">\n",
"\t<path d=\"M43.6,378.0 L124.8,244.5 L206.0,145.3 L287.2,86.6 L368.4,56.5 L449.6,42.1 L530.8,35.5 \" stroke=\"rgb( 0, 0, 255)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_2a\"><title>gnuplot_plot_2a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"4.00\">\n",
"\t<path d=\"M43.6,378.0 L124.8,237.3 L206.0,119.6 L287.2,56.5 L368.4,36.0 L449.6,31.3 L530.8,30.3 \" stroke=\"rgb( 0, 128, 0)\"/>\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb( 0, 128, 0)\" transform=\"translate(43.6,378.0) scale(10.50)\" xlink:href=\"#gpPt5\"/></g>\n",
"\t<use color=\"rgb( 0, 128, 0)\" transform=\"translate(124.8,237.3) scale(10.50)\" xlink:href=\"#gpPt5\"/>\n",
"\t<use color=\"rgb( 0, 128, 0)\" transform=\"translate(206.0,119.6) scale(10.50)\" xlink:href=\"#gpPt5\"/>\n",
"\t<use color=\"rgb( 0, 128, 0)\" transform=\"translate(287.2,56.5) scale(10.50)\" xlink:href=\"#gpPt5\"/>\n",
"\t<use color=\"rgb( 0, 128, 0)\" transform=\"translate(368.4,36.0) scale(10.50)\" xlink:href=\"#gpPt5\"/>\n",
"\t<use color=\"rgb( 0, 128, 0)\" transform=\"translate(449.6,31.3) scale(10.50)\" xlink:href=\"#gpPt5\"/>\n",
"\t<use color=\"rgb( 0, 128, 0)\" transform=\"translate(530.8,30.3) scale(10.50)\" xlink:href=\"#gpPt5\"/>\n",
"</g>\n",
"\t</g>\n",
"<g color=\"white\" fill=\"none\" stroke=\"rgb( 0, 128, 0)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot(t,v_analytical,'-',t,v_numerical,'o-')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Octave",
"language": "octave",
"name": "octave"
},
"language_info": {
"file_extension": ".m",
"help_links": [
{
"text": "MetaKernel Magics",
"url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
}
],
"mimetype": "text/x-octave",
"name": "octave",
"version": "0.19.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 0f702b6

Please sign in to comment.