diff options
author | hardythe1 | 2015-04-07 15:58:05 +0530 |
---|---|---|
committer | hardythe1 | 2015-04-07 15:58:05 +0530 |
commit | 92cca121f959c6616e3da431c1e2d23c4fa5e886 (patch) | |
tree | 205e68d0ce598ac5caca7de839a2934d746cce86 /sample_notebooks/SauravSuman/Chapter_1.ipynb | |
parent | b14c13fcc6bb6d01c468805d612acb353ec168ac (diff) | |
download | Python-Textbook-Companions-92cca121f959c6616e3da431c1e2d23c4fa5e886.tar.gz Python-Textbook-Companions-92cca121f959c6616e3da431c1e2d23c4fa5e886.tar.bz2 Python-Textbook-Companions-92cca121f959c6616e3da431c1e2d23c4fa5e886.zip |
added books
Diffstat (limited to 'sample_notebooks/SauravSuman/Chapter_1.ipynb')
-rwxr-xr-x | sample_notebooks/SauravSuman/Chapter_1.ipynb | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/sample_notebooks/SauravSuman/Chapter_1.ipynb b/sample_notebooks/SauravSuman/Chapter_1.ipynb new file mode 100755 index 00000000..190fe03a --- /dev/null +++ b/sample_notebooks/SauravSuman/Chapter_1.ipynb @@ -0,0 +1,162 @@ +{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#Chapter 1: Preliminaries"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Example 1.1, Rounding off Numbers, Page no. 2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "81.9773 becomes 81.98\n",
+ "\n",
+ "\n",
+ "48.365 becomes 48.37\n",
+ "\n",
+ "\n",
+ "21.385 becomes 21.39\n",
+ "\n",
+ "\n",
+ "12.865 becomes 12.87\n",
+ "\n",
+ "\n",
+ "27.553 becomes 27.55\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "#variable declaration\n",
+ "a=[81.9773,48.365,21.385,12.865,27.553]\n",
+ "\n",
+ "#calculation and result\n",
+ "for i in xrange (0,5):\n",
+ " print '\\n%s becomes %.2f\\n' %(a[i],a[i])\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Example 1.2, Relative Maximum Error, Page no. 5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Maximum Error = 0.030\n",
+ "\n",
+ "Relative maximum error = 0.006\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ " \n",
+ "#variable declaration\n",
+ "h=0.001;\n",
+ "x=1;y=1;z=1;dx=0.001;dy=0.001;dz=0.001;\n",
+ "def f(x,y,z):\n",
+ " return (5*x*y**2)/z**3\n",
+ "\n",
+ "#calculation\n",
+ "du=abs(f(x+h,y,z)-f(x,y,z))*dx+abs(f(x,y+h,z)-f(x,y,z))*dy+abs(f(x,y,z+h)-f(x,y,z))*dz;\n",
+ "du=du/h;\n",
+ "Er=du/f(x,y,z)\n",
+ "\n",
+ "#result\n",
+ "print '\\nMaximum Error = %.3f\\n\\nRelative maximum error = %.3f' %(du,Er)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Example 1.3, Absolute Error, Page no. 6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Maximum Absolute Error of a+b+c+d = 600.050200\n",
+ "\n",
+ "\n",
+ "Maximum Absolute Error of c^3 = -172.000000\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=10;b=0.0356;c=15300;d=62000;\n",
+ "ea=0.05;eb=0.0002;ec=100;ed=500;\n",
+ "\n",
+ "#Calculation\n",
+ "e=ea+eb+ec+ed;\n",
+ "E=(c+2*ec)^3-(c+ec)^3\n",
+ "\n",
+ "#result\n",
+ "print '\\nMaximum Absolute Error of a+b+c+d = %f\\n' %e\n",
+ "print '\\nMaximum Absolute Error of c^3 = %f' %E\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
|