summaryrefslogtreecommitdiff
path: root/sample_notebooks/SauravSuman/Chapter_1.ipynb
blob: 190fe03afa30c9ed83fc20b1ab01b855cb01f1e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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
}