summaryrefslogtreecommitdiff
path: root/sample_notebooks
diff options
context:
space:
mode:
Diffstat (limited to 'sample_notebooks')
-rwxr-xr-xsample_notebooks/AJEET KUMARSINGH/Chapter_11_Inheritance.ipynb2636
-rwxr-xr-xsample_notebooks/AJEET KUMARSINGH/Chapter_11_Inheritance_(1).ipynb2636
-rwxr-xr-xsample_notebooks/AbhishekGupta/Chapter02.ipynb328
-rwxr-xr-xsample_notebooks/AjayTheetla/Chapter_1.ipynb208
-rwxr-xr-xsample_notebooks/AjayTheetla/Chapter_1_1.ipynb208
-rwxr-xr-xsample_notebooks/AkshayPatil/chapter1.ipynb190
-rwxr-xr-xsample_notebooks/AkshayPatil/chapter1_1.ipynb190
-rwxr-xr-xsample_notebooks/Aman KumarJain/Chapter_6_Objects_and_Classes.ipynb934
-rwxr-xr-xsample_notebooks/ApurvaBhushan/Chapter_3.ipynb195
-rwxr-xr-xsample_notebooks/ArchanaDharmasagar Kalidas/chapter3.ipynb560
-rwxr-xr-xsample_notebooks/AvinashReddy/Chapter6.ipynb424
-rwxr-xr-xsample_notebooks/AvinashReddy/Chapter6_1.ipynb424
-rwxr-xr-xsample_notebooks/Ershad AhamedChemmalasseri/chapter1.ipynb556
-rwxr-xr-xsample_notebooks/Ershad AhamedChemmalasseri/chapter1_1.ipynb556
-rwxr-xr-xsample_notebooks/ManikandanD/Chapter1.ipynb248
-rwxr-xr-xsample_notebooks/ManikandanD/chapter_1_.ipynb256
-rwxr-xr-xsample_notebooks/MayankSahu/Chapter1_.ipynb1
-rwxr-xr-xsample_notebooks/MayankSahu/Chapter5_.ipynb1
-rwxr-xr-xsample_notebooks/MayankSahu/Chapter5__1.ipynb1
-rwxr-xr-xsample_notebooks/MohdAsif/Chapter2,_Measurement_Errors.ipynb257
-rwxr-xr-xsample_notebooks/MohdAsif/Chapter4.ipynb216
-rwxr-xr-xsample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI.ipynb462
-rwxr-xr-xsample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_1.ipynb462
-rwxr-xr-xsample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_2.ipynb462
-rwxr-xr-xsample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_3.ipynb462
-rwxr-xr-xsample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_4.ipynb462
-rwxr-xr-xsample_notebooks/NirenNegandhi/ch2.ipynb507
-rwxr-xr-xsample_notebooks/NitamoniDas/chapter_8_Data_Abstraction_through_Classes_and_User-Defined_Data_Types.ipynb809
-rwxr-xr-xsample_notebooks/NitamoniDas/chapter_8_Data_Abstraction_through_Classes_and_User-Defined_Data_Types_1.ipynb809
-rwxr-xr-xsample_notebooks/SINDHUARROJU/Chapter1.ipynb463
-rwxr-xr-xsample_notebooks/SantoshPawar/Chapter9.ipynb569
-rwxr-xr-xsample_notebooks/Sashankkonete/Chapter1.ipynb458
-rwxr-xr-xsample_notebooks/SauravSuman/Chapter_1.ipynb162
-rwxr-xr-xsample_notebooks/ShriniwasSabban/Chapter2.ipynb233
-rwxr-xr-xsample_notebooks/ShriniwasSabban/Chapter2_1.ipynb233
-rwxr-xr-xsample_notebooks/ShubhamRungta/Chapter2.ipynb228
-rwxr-xr-xsample_notebooks/SrutiGoyal/Chapter_11-_Object_Initialization_and_Clean-Up.ipynb1779
-rwxr-xr-xsample_notebooks/SrutiGoyal/Chapter_11-_Object_Initialization_and_Clean-Up_1.ipynb1779
-rwxr-xr-xsample_notebooks/Tarun KumarDas/Chapter9.ipynb227
-rwxr-xr-xsample_notebooks/VikasPrasad/chapter1.ipynb166
-rwxr-xr-xsample_notebooks/VikasPrasad/chapter1_1.ipynb166
-rwxr-xr-xsample_notebooks/YogeshPatil/Chapter_11.ipynb494
-rwxr-xr-xsample_notebooks/YogeshPatil/Chapter_2.ipynb229
-rwxr-xr-xsample_notebooks/YogeshPatil/Chapter_2_1.ipynb229
-rwxr-xr-xsample_notebooks/YogeshPatil/Chapter_2_2.ipynb229
-rwxr-xr-xsample_notebooks/YogeshPatil/Chapter_2_3.ipynb229
-rwxr-xr-xsample_notebooks/ajinkyakhair/Untitled3.ipynb105
-rwxr-xr-xsample_notebooks/ajinkyakhair/Untitled3_1.ipynb105
-rwxr-xr-xsample_notebooks/harishsahu/Chapter1.ipynb134
-rwxr-xr-xsample_notebooks/harishsahu/Chapter1_1.ipynb134
-rwxr-xr-xsample_notebooks/harishsahu/Chapter1_2.ipynb134
51 files changed, 23945 insertions, 0 deletions
diff --git a/sample_notebooks/AJEET KUMARSINGH/Chapter_11_Inheritance.ipynb b/sample_notebooks/AJEET KUMARSINGH/Chapter_11_Inheritance.ipynb
new file mode 100755
index 00000000..4f69b243
--- /dev/null
+++ b/sample_notebooks/AJEET KUMARSINGH/Chapter_11_Inheritance.ipynb
@@ -0,0 +1,2636 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e85379c4218575d4b069259557cffbbc2d0259e3ba5d0e030c11dd77aae5e38d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.1, Page Number:444"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#A simple classA having a public data member x\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.x=None\n",
+ "\n",
+ "#A simple classA having a public data member y \n",
+ "class B(A): #derived class\n",
+ " def __init__(self):\n",
+ " self.y=None\n",
+ " \n",
+ "b=B() #create a instance b of Derived class B\n",
+ "b.x=20\n",
+ "b.y=30\n",
+ "\n",
+ "print 'member of A:',b.x\n",
+ "print 'Member of B:',b.y"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "member of A: 20\n",
+ "Member of B: 30\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.2, Page Number:445"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A:\n",
+ " def __init__(self): #class A having x as a private data member\n",
+ " self.__x=20\n",
+ " \n",
+ " def showx(self):\n",
+ " print \"x=\",self.__x\n",
+ " \n",
+ " \n",
+ "class B(A): #Derived class\n",
+ " def __init__(self):\n",
+ " self.y=30 #class B having y as a public data member\n",
+ " \n",
+ " def show(self):\n",
+ " a=A()\n",
+ " a.showx()\n",
+ " print \"y=\",self.y\n",
+ " \n",
+ " \n",
+ "b=B() #declaration of object\n",
+ " #class the method of derived class object by a derived class instance\n",
+ "b.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 20\n",
+ "y= 30\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.3, Page Number:447"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#base class\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.x=None #x is a public member\n",
+ " \n",
+ " \n",
+ "#derived class\n",
+ "class B(A):\n",
+ " def __init__(self):\n",
+ " self.y=40 \n",
+ " A.__x=20 #since it is privately inherites base class ,x become private member of it\n",
+ " \n",
+ " def show(self):\n",
+ " print \"x=\",A.__x\n",
+ " print \"y=\",self.y\n",
+ " \n",
+ "b=B()\n",
+ "b.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 20\n",
+ "y= 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.4, Page Number:448"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.__x=20 #x is a privet member of it\n",
+ " \n",
+ " def showx(self): \n",
+ " print \"x=\",self.__x\n",
+ " \n",
+ " \n",
+ "class B(A):\n",
+ " def __init__(self):\n",
+ " self.y=40 #y is a public member of it\n",
+ " \n",
+ " def show(self):\n",
+ " a=A()\n",
+ " a.showx() #call the base class method\n",
+ " print \"y=\",self.y\n",
+ " \n",
+ " \n",
+ "b=B()\n",
+ "b.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 20\n",
+ "y= 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.5, Page Number:449"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A:\n",
+ " def __init__(self):\n",
+ " self._x=None #x is a protected member of the base class\n",
+ " \n",
+ " \n",
+ "class B(A): #private inheritance,x become a private member of the derived class\n",
+ " def __init__(self):\n",
+ " self.y=40\n",
+ " self.__x=30\n",
+ " \n",
+ " \n",
+ " def show(self):\n",
+ " print \"x=\",self.__x\n",
+ " print \"y=\",self.y\n",
+ " \n",
+ " \n",
+ "b=B()\n",
+ "b.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 30\n",
+ "y= 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.6, Page Number:456"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class ABC: #Base class\n",
+ " def __init__(self):\n",
+ " self._name=None #these 2 are protected data member\n",
+ " self._age=None\n",
+ " \n",
+ "class abc(ABC): #Derived class ,Public derivation\n",
+ " def __init__(self):\n",
+ " self.height=None\n",
+ " self.weight=None\n",
+ " \n",
+ " def getdata(self):\n",
+ " \n",
+ " self.name=raw_input(\"Enter a name: \") #take inputes to all the data members \n",
+ " self.age=raw_input(\"Enter a age: \") \n",
+ " self._height=raw_input(\"Enter a Height: \") \n",
+ " self._weight=raw_input(\"Enter a Weight: \") \n",
+ " \n",
+ " def show(self): #display the value of data members\n",
+ " print 'Name:',self.name \n",
+ " print 'Age:',self.age,\"years\"\n",
+ " print 'Height:',self._height,\"Feets\"\n",
+ " print 'Weight:',self._weight,\"kg.\"\n",
+ " \n",
+ " \n",
+ "x=abc()\n",
+ "x.getdata()\n",
+ "x.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a name: Santosh\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a age: 24\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a Height: 4.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a Weight: 50\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Santosh\n",
+ "Age: 24 years\n",
+ "Height: 4.5 Feets\n",
+ "Weight: 50 kg.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.7, Page Number:458"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A1: #super Base class,have 2 protected data members\n",
+ " def __init__(self):\n",
+ " self._name=None\n",
+ " self._age=None\n",
+ "\n",
+ " \n",
+ "class A2(A1): #Public derivation\n",
+ " def __init(self):\n",
+ " self._height=None\n",
+ " self._weight=None\n",
+ "\n",
+ "class A3(A2): #public Derivation\n",
+ " def __init__(self):\n",
+ " self._sex=None\n",
+ " \n",
+ " \n",
+ " def get(self): #get input \n",
+ " self._name=raw_input(\"Name: \")\n",
+ " self._age=raw_input(\"Age: \")\n",
+ " self._sex=raw_input(\"Sex: \")\n",
+ " \n",
+ " self._height=raw_input(\"Height: \")\n",
+ " self._weight=raw_input(\"Weight: \")\n",
+ " \n",
+ " def show(self): #Display values of all the data members\n",
+ " print \"Name:\",self._name\n",
+ " print \"Age:\",self._age ,\"years\"\n",
+ " print \"Sex:\",self._sex\n",
+ " print \"Height:\",self._height ,\"Feet\"\n",
+ " print \"Weight:\",self._weight ,\"Kg.\"\n",
+ " \n",
+ "\n",
+ "x=A3()\n",
+ "x.get()\n",
+ "x.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Balaji\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age: 26\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sex: M\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Height: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Weight: 49.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Balaji\n",
+ "Age: 26 years\n",
+ "Sex: M\n",
+ "Height: 4 Feet\n",
+ "Weight: 49.5 Kg.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.8, Page Number:459"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example of multiple Inheritance\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self._a=None\n",
+ " \n",
+ "class B:\n",
+ " def __init__(self):\n",
+ " self._b=None\n",
+ " \n",
+ " \n",
+ "class C:\n",
+ " def __init__(self):\n",
+ " self._c=None\n",
+ " \n",
+ "class D:\n",
+ " def __init__(self):\n",
+ " self._d=None\n",
+ " \n",
+ "class E(A,B,C,D): #inherites all the base classes publically\n",
+ " def __init__(self):\n",
+ " self.e=None\n",
+ " \n",
+ " def getdata(self):\n",
+ " print \"Enter the value of a,b,c &d &e:\"\n",
+ " self._a=input()\n",
+ " self._b=input()\n",
+ " self._c=input()\n",
+ " self._d=input()\n",
+ " self._e=input()\n",
+ " \n",
+ " def show(self):\n",
+ " print\"a=\",self._a,\"b=\",self._b,\"c=\",self._c,\"d=\",self._d,\"e=\",self._e\n",
+ " \n",
+ " \n",
+ "x=E() #x is the instance of the derived class\n",
+ "x.getdata() #call the methods of derived class through x \n",
+ "x.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the value of a,b,c &d &e:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "16\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a= 1 b= 2 c= 4 d= 8 e= 16\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.9, Page Number:461"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class red: #these three base class\n",
+ " def __init__(self):\n",
+ " print \"Red\",\n",
+ " \n",
+ "class yellow:\n",
+ " def __init__(self):\n",
+ " print \"Yellow\",\n",
+ " \n",
+ "class blue:\n",
+ " def __init__(self):\n",
+ " print \"Blue\",\n",
+ " \n",
+ "class orange(red,yellow): #public multiple Derivation\n",
+ " def __init__(self):\n",
+ " red.__init__(self)\n",
+ " yellow.__init__(self)\n",
+ " print \"=Orange\",\n",
+ " \n",
+ "class green(blue,yellow): #public multiple Derivation\n",
+ " def __init__(self):\n",
+ " blue.__init__(self)\n",
+ " yellow.__init__(self)\n",
+ " print \"=Green\",\n",
+ " \n",
+ "class violet(red,blue): #public multiple Derivation\n",
+ " def __init__(self):\n",
+ " red.__init__(self)\n",
+ " blue.__init__(self)\n",
+ " print \"=Violet\",\n",
+ " \n",
+ "class reddishbrown(orange,violet): #public multiple & multilevel Derivation\n",
+ " def __init__(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self)\n",
+ " print \"=Reddishbrown\"\n",
+ " \n",
+ "class yellowishbrown(green,orange): #public multiple & multilevel Derivation\n",
+ " def __init__(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self)\n",
+ " print \"=Yellowishbrown\"\n",
+ " \n",
+ "class bluishbrown(violet,green): #public multiple & multilevel Derivation\n",
+ " def __init__(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self)\n",
+ " print \"=Bluishbrown\"\n",
+ " \n",
+ " \n",
+ " \n",
+ "r=reddishbrown() #create instances of the derived class\n",
+ "b=bluishbrown()\n",
+ "y=yellowishbrown()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Red Yellow =Orange Red Blue =Violet =Reddishbrown\n",
+ "Red Blue =Violet Blue Yellow =Green =Bluishbrown\n",
+ "Blue Yellow =Green Red Yellow =Orange =Yellowishbrown\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.10, Page Number:463"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# WAP to create a derived class from multiple base classes\n",
+ "\n",
+ "class PLAYER: #these three are the base classes\n",
+ " def __init__(self):\n",
+ " self._name=None\n",
+ " self._gender=None\n",
+ " self._age\n",
+ " \n",
+ "class PHYSIQUE(PLAYER):\n",
+ " def __init__(self):\n",
+ " self._height=None\n",
+ " self._weight=None\n",
+ " \n",
+ "class LOCATION:\n",
+ " def __init__(self):\n",
+ " self._city=None\n",
+ " self._pin=None\n",
+ " \n",
+ "class GAME(PHYSIQUE,LOCATION): #Multiple derivation\n",
+ " def __init__(self):\n",
+ " self._game=None\n",
+ " def getdata(self): #Method to take inputes\n",
+ " print\"Enter the following information\\n\\n\"\n",
+ " self._name=raw_input(\"Name:\")\n",
+ " self._gender=raw_input(\"Gender:\")\n",
+ " self._age=raw_input(\"Age:\")\n",
+ " self._height=raw_input(\"Height:\")\n",
+ " self._weight=raw_input(\"Weight:\")\n",
+ " self._city=raw_input(\"City:\")\n",
+ " self._pin=raw_input(\"Pin:\")\n",
+ " self._game=raw_input(\"game:\")\n",
+ " \n",
+ " \n",
+ " \n",
+ " def show(self): #Method for displaying inputes\n",
+ " print\"Entered Information!!\"\n",
+ " print\"Name:\",self._name\n",
+ " print \"Gender:\",self._gender\n",
+ " print \"Age:\",self._age\n",
+ " print \"Height:\",self._height\n",
+ " print \"Weight:\",self._weight\n",
+ " print \"City :\",self._city\n",
+ " print \"Pincode:\",self._pin\n",
+ " print \"Game :\",self._game\n",
+ " \n",
+ " \n",
+ "G=GAME() #create an instance of the derived class\n",
+ "G.getdata() #call the public methods by the created instances\n",
+ "G.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the following information\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name:Mahesh\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gender:M\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:25\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Height:4.9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Weight:55\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "City:Nanded\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pin:431603\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "game:Cricket\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Entered Information!!\n",
+ "Name: Mahesh\n",
+ "Gender: M\n",
+ "Age: 25\n",
+ "Height: 4.9\n",
+ "Weight: 55\n",
+ "City : Nanded\n",
+ "Pincode: 431603\n",
+ "Game : Cricket\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.11, Page Number:467"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Multipath Inheritance,concept of virtual classes\n",
+ "\n",
+ "class A1: #Super base class\n",
+ " def __init__(self):\n",
+ " self._a1=None\n",
+ " \n",
+ "class A2(A1): #base class 1,inherites Super Base class\n",
+ " def __init__(self):\n",
+ " self._a2=None\n",
+ " \n",
+ "class A3(A1): #base class 2,inherites Super Base class\n",
+ " def __init__(self):\n",
+ " self._a3=None\n",
+ " \n",
+ "class A4(A2,A3): #derived class ,public derivation of both the base classes\n",
+ " def __init__(self):\n",
+ " self.__a4=None\n",
+ " \n",
+ " def get(self):\n",
+ " print \"Enter the value of a1,a2,a3,and a4:\"\n",
+ " self._a1=input()\n",
+ " self._a2=input()\n",
+ " self._a3=input()\n",
+ " self.__a4=input()\n",
+ " \n",
+ " def put(self):\n",
+ " print \"a1=\",self._a1,\"a2=\",self._a2,\"a3=\",self._a3,\"a4=\",self.__a4\n",
+ " \n",
+ " \n",
+ " \n",
+ "a=A4() #create the instance of the derived class\n",
+ "a.get()\n",
+ "a.put()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the value of a1,a2,a3,and a4:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a1= 5 a2= 8 a3= 7 a4= 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.12, Page Number:469"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To show order of execution of the constructors and destructors in multiple inheritance\n",
+ "\n",
+ "#**NOTE:Python destuctor is called when program goes exit. So output may be differ than c++\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " print\"Zero argument Constructor of base class A\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Destructor of class A\"\n",
+ " \n",
+ "class B:\n",
+ " def __init__(self):\n",
+ " print\"Zero argument Constructor of base class B\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Destructor of class B\"\n",
+ "\n",
+ "class C(A,B):\n",
+ " def __init__(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self)\n",
+ " print\"Zero argument Constructor of base class C\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Destructor of class C\"\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__del__(self)\n",
+ " \n",
+ "c=C() #create instance of derived class"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Zero argument Constructor of base class A\n",
+ "Zero argument Constructor of base class B\n",
+ "Zero argument Constructor of base class C\n",
+ "Destructor of class C\n",
+ "Destructor of class A\n",
+ "Destructor of class B\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.13, Page Number:471"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#WAP to use constructor and destructor in all the classess\n",
+ "\n",
+ "class A1:\n",
+ " def __init__(self): #take name and age as input in super base class\n",
+ " self._name=raw_input(\"Name:\")\n",
+ " self._age=raw_input(\"Age:\")\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Name:\",self._name\n",
+ " print\"Age\",self._age\n",
+ " \n",
+ " \n",
+ "class A2(A1): #take height and weight as input in base base class,public derivation \n",
+ " def __init__(self):\n",
+ " A1.__init__(self)\n",
+ " self._height=raw_input(\"Height:\")\n",
+ " self._weight=raw_input(\"Weight:\")\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Height:\",self._height\n",
+ " print\"Weight:\",self._weight\n",
+ " A1.__del__(self)\n",
+ " \n",
+ " \n",
+ "class A3(A2): #take sex as input in derived class,derived from class A2\n",
+ " def __init__(self):\n",
+ " A2.__init__(self)\n",
+ " self.__sex=raw_input(\"Sex:\")\n",
+ " def __del__(self): #display all the input taken by all the base classes\n",
+ " print\"Sex:\",self.__sex\n",
+ " A2.__del__(self)\n",
+ " \n",
+ " \n",
+ "x=A3() #create instance x of the class A3\n",
+ "\n",
+ "del x #call the destructor"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name:Ajay\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Height:4.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Weight:40\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sex:M\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sex: M\n",
+ "Height: 4.5\n",
+ "Weight: 40\n",
+ "Name: Ajay\n",
+ "Age 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.14, Page Number:472"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To create derived class from the base class,by constructor and destructor\n",
+ "class in_t:\n",
+ " def __init__(self):\n",
+ " self._i=1\n",
+ " print\"Constructor in_t()\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Destructor in_t()\"\n",
+ " \n",
+ "class floa_t:\n",
+ " def __init__(self):\n",
+ " self._f=1.5\n",
+ " print\"Constructor floa_t()\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Destructor floa_t()\"\n",
+ " \n",
+ " \n",
+ "class cha_r(in_t,floa_t): #multiple derivation\n",
+ " def __init__(self):\n",
+ " self._c='A'\n",
+ " print\"Constructor cha_r()\"\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self)\n",
+ " \n",
+ " def show(self):\n",
+ " print\"i=\",self._i\n",
+ " print \"f=\",self._f\n",
+ " print \"c=\",self._c\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructing cha_r()\"\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__del__(self)\n",
+ " \n",
+ "a=cha_r() #create derived class instance and call the public method of the derived class\n",
+ "a.show() #**NOTE:Python destuctor is called when program goes exit. So output may be differ than c++"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor cha_r()\n",
+ "Constructor in_t()\n",
+ "Constructor floa_t()\n",
+ "i= 1\n",
+ "f= 1.5\n",
+ "c= A\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.15, Page Number:474"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " self.x=None\n",
+ " \n",
+ "class II(I):\n",
+ " def __init__(self):\n",
+ " self.__y=None\n",
+ " \n",
+ " def set(self,j,k):\n",
+ " self.x=j\n",
+ " self.__y=k\n",
+ " \n",
+ " def show(self):\n",
+ " print \"X=\",self.x, \"Y=\",self.__y\n",
+ " \n",
+ " \n",
+ "i=II()\n",
+ "i.set(4,5)\n",
+ "i.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X= 4 Y= 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.16, Page Number:475"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class I:\n",
+ " def __init__(self):\n",
+ " self.x=10\n",
+ " print \"In the Base class constuctor\"\n",
+ " \n",
+ "class II(I):\n",
+ " def __init__(self):\n",
+ " I.__init__(self)\n",
+ " self.__y=None\n",
+ " \n",
+ "i=II()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In the Base class constuctor\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.17, Page Number:475"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#base class without constructor and derived class with constructor\n",
+ "class I:\n",
+ " pass\n",
+ "class II(I):\n",
+ " def __init__(self):\n",
+ " print \"In derived class constructor\"\n",
+ " \n",
+ "i=II()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In derived class constructor\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.18, Page Number:476"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#both the class have constructor\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " print \"In base class Constructor\"\n",
+ " \n",
+ "class II(I):\n",
+ " def __init__(self):\n",
+ " I.__init__(self)\n",
+ " print \"In derived Class constructor\"\n",
+ " \n",
+ "i=II()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In base class Constructor\n",
+ "In derived Class constructor\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.19, Page Number:477"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#multiple constructor in base class and single constructor in the derived class\n",
+ "\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument base class construtor\"\n",
+ " \n",
+ " def __init__(self,k):\n",
+ " self.x=None\n",
+ " print \"One argument base class construtor\"\n",
+ " \n",
+ " \n",
+ "class II(I):\n",
+ " def __init__(self,j,k=None): #default constructor\n",
+ " I.__init__(self,k)\n",
+ " self.__y=j\n",
+ " print \"One argument derived class constructor\"\n",
+ " \n",
+ "i=II(2) #create the instance of the base class by passing initial value "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "One argument base class construtor\n",
+ "One argument derived class constructor\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.20, Page Number:478"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#base and derived class without default constructor\n",
+ "class I:\n",
+ " def __init__(self,k):\n",
+ " self.x=k\n",
+ " print \"One argument base class construtor\"\n",
+ " \n",
+ "class II(I):\n",
+ " def __init__(self,j):\n",
+ " I.__init__(self,j)\n",
+ " self.__y=j\n",
+ " print \"One argument derived class construtor\"\n",
+ " \n",
+ "i=II(2) #create the instance of the base class by passing initial value "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "One argument base class construtor\n",
+ "One argument derived class construtor\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.21, Page Number:479"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Constructors and multiple inheritance\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class I\"\n",
+ " \n",
+ "class II:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class II\"\n",
+ " \n",
+ "class III(II,I): #class III inhrites class II and I\n",
+ " def __init__(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self) \n",
+ " print \"Zero argument constructor of base class III\"\n",
+ " \n",
+ "i=III() #create an instance of the base class\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Zero argument constructor of base class II\n",
+ "Zero argument constructor of base class I\n",
+ "Zero argument constructor of base class III\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.22, Page Number:480"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Constructors in multiple inhritance with invoking constructor of the base classes\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class I\"\n",
+ " \n",
+ "class II:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class II\"\n",
+ " \n",
+ "class III(II,I):\n",
+ " def __init__(self):\n",
+ " II.__init__(self)\n",
+ " I.__init__(self)\n",
+ " print \"Zero argument constructor of base class III\"\n",
+ " \n",
+ "i=III()\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Zero argument constructor of base class II\n",
+ "Zero argument constructor of base class I\n",
+ "Zero argument constructor of base class III\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.23, Page Number:481"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#multiple inheritance,invoking the base classes explicitly\n",
+ "\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class I\"\n",
+ " \n",
+ "class II:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class II\"\n",
+ " \n",
+ "class III(II,I): #Class I is virtually inherited so its constructor called first\n",
+ " def __init__(self):\n",
+ " I.__init__(self)\n",
+ " II.__init__(self)\n",
+ " print \"Zero argument constructor of base class III\"\n",
+ " \n",
+ "i=III()\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Zero argument constructor of base class I\n",
+ "Zero argument constructor of base class II\n",
+ "Zero argument constructor of base class III\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.24, Page Number:482"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#multilevel Inheritance,observation of the execution of the constructors\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class I\"\n",
+ " \n",
+ "class II(I):\n",
+ " def __init__(self):\n",
+ " I.__init__(self)\n",
+ " print \"Zero argument constructor of base class II\"\n",
+ " \n",
+ "class III(II): #Class I is virtually inherited so its constructor called first\n",
+ " def __init__(self):\n",
+ " II.__init__(self)\n",
+ " print \"Zero argument constructor of base class III\"\n",
+ " \n",
+ "i=III()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Zero argument constructor of base class I\n",
+ "Zero argument constructor of base class II\n",
+ "Zero argument constructor of base class III\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.25, Page Number:484"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#use object of one class in another class as a member\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " self.x=20\n",
+ " print \"Constructor of class I\"\n",
+ " \n",
+ "class II:\n",
+ " \n",
+ " def __init__(self):\n",
+ " self.k=30\n",
+ " y=I()\n",
+ " print \"Constructor of class II\"\n",
+ " print \"x=\",y.x #print here because it become local variable in this scope only,it not visible to def show\n",
+ " \n",
+ " \n",
+ " def show(self):\n",
+ " print \"k=\",self.k\n",
+ " \n",
+ "ii=II()\n",
+ "ii.show() #**NOTE:Python destuctor is called when program goes exit. So output may be differ than c++"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class I\n",
+ "Constructor of class II\n",
+ "x= 20\n",
+ "k= 30\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.26, Page Number:484"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#access a member variable of base class using object,class name, and direct\n",
+ "\n",
+ "class A1:\n",
+ " def __init__(self):\n",
+ " self.name=None\n",
+ " self.age=None\n",
+ " \n",
+ "class A2(A1):\n",
+ " def __init__(self):\n",
+ " A1.__init__(self)\n",
+ " a=A1()\n",
+ " print \"Access using name of the class:\"\n",
+ " A1.name=raw_input(\"Name:\")\n",
+ " A1.age=raw_input(\"Age:\")\n",
+ " \n",
+ " print \"Access using object of the class\"\n",
+ " a.name=raw_input(\"Name:\")\n",
+ " a.age=raw_input(\"Age:\")\n",
+ " \n",
+ " print \"Access using direct member variables:\"\n",
+ " self.name=raw_input(\"Name:\")\n",
+ " self.age=raw_input(\"Age:\")\n",
+ " self.__height=raw_input(\"Height:\")\n",
+ " self.__weight=raw_input(\"Weight:\")\n",
+ " \n",
+ " print \"Display using object of the class\" #since object of class A1 has scope in constructor method so we can access it only \n",
+ " print \"Name:\",a.name # within this method.It is not visible in destructor function.\n",
+ " print \"Age:\",a.age\n",
+ " \n",
+ " \n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of Derived class\"\n",
+ " print \"Display using class name\"\n",
+ " print \"Name:\",A1.name\n",
+ " print \"Age:\",A1.age\n",
+ " \n",
+ " print \"Display using direct member variable\"\n",
+ " print \"Name:\",self.name\n",
+ " print \"Age\",self.age\n",
+ " print \"height:\",self.__height\n",
+ " print \"Weight:\",self.__weight\n",
+ " \n",
+ "x=A2()\n",
+ "\n",
+ "del x\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Access using name of the class:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name:Ajay\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:21\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Access using object of the class\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name:Amit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Access using direct member variables:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name:Arun\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:19\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Height:5.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Weight:31\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Display using object of the class\n",
+ "Name: Amit\n",
+ "Age: 20\n",
+ "Destructor of Derived class\n",
+ "Display using class name\n",
+ "Name: Ajay\n",
+ "Age: 21\n",
+ "Display using direct member variable\n",
+ "Name: Arun\n",
+ "Age 19\n",
+ "height: 5.5\n",
+ "Weight: 31\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.27, Page Number:488"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#derive a class from two base classes,object of these 2 classes is the member variable of the third class\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.a1=None\n",
+ " \n",
+ "class B:\n",
+ " def __init__(self):\n",
+ " self.b1=None\n",
+ " \n",
+ "class AB:\n",
+ " def __init__(self):\n",
+ " a=A()\n",
+ " b=B()\n",
+ " a.a1=65 #initialize the two data members of the class A and B and Display them\n",
+ " b.b1=66\n",
+ " print \"a1=\",a.a1, \"b1=\",b.b1\n",
+ " \n",
+ " def __del__(self):\n",
+ " pass\n",
+ " \n",
+ " \n",
+ "ab=AB()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a1= 65 b1= 66\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.28, Page Number:489"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#create derived class from qualifier class\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.x=None\n",
+ " \n",
+ " class B:\n",
+ " def __init__(self):\n",
+ " self.y=None\n",
+ " \n",
+ " \n",
+ "class C(A,A.B): #A.B is the inner class of the class A\n",
+ " def __init__(self,j,k,l):\n",
+ " self.x=j\n",
+ " self.y=k\n",
+ " self.z=l\n",
+ " \n",
+ " def show(self):\n",
+ " print \"x=\",self.x,\"y=\",self.y,\"z=\",self.z\n",
+ " \n",
+ " \n",
+ "c=C(4,7,1)\n",
+ "c.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 4 y= 7 z= 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.29, Page Number:490"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#initialize member variable of the base class and derived class using constructor of the derived class\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self._x=None #protected members\n",
+ " self._y=None\n",
+ " \n",
+ "class B(A):\n",
+ " def __init__(self):\n",
+ " self.z=3\n",
+ " self.__x=1 #private members\n",
+ " self.__y=2\n",
+ " \n",
+ " print \"x=\",self.__x,\"y=\",self.__y,\"z=\",self.z\n",
+ " \n",
+ "b=B()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 1 y= 2 z= 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.30, Page Number:491"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#access data members by object pointer\n",
+ "\n",
+ "from ctypes import *\n",
+ "import ctypes\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.x=1\n",
+ " self.y=2\n",
+ " \n",
+ "class B(A):\n",
+ " def __init__(self):\n",
+ " A.__init__(self)\n",
+ " self.z=3\n",
+ " \n",
+ "b=B()\n",
+ "\n",
+ "\n",
+ "i=c_int(b.z)\n",
+ "p=pointer(i)\n",
+ "print \"Address of z:\",addressof(p),\"Value of Z:\",p[0] #access the\n",
+ "\n",
+ "i = c_int(b.y)\n",
+ "p = pointer(i)\n",
+ "print \"Address of y:\",addressof(p),\"Value of y:\",p[0] \n",
+ "\n",
+ "i = c_int(b.x)\n",
+ "p = pointer(i)\n",
+ "print \"Address of x:\",addressof(p),\"Value of x:\",p[0] \n",
+ "\n",
+ "#**NOTE-In case of C++ the data members of the derived class and base class are stored in contigious memory locations so we can \n",
+ "#access the three variables by using a pointer of derived class and decrementing its value. But in case of Python they are NOT stored \n",
+ "#in contogious memory locations so for accessing each data member we have to create individual object pointer for each class."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address of z: 57077392 Value of Z: 3\n",
+ "Address of y: 57074448 Value of y: 2\n",
+ "Address of x: 57077648 Value of x: 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.31, Page Number:492"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#overload member function in base and derived class\n",
+ "\n",
+ "class B:\n",
+ " def show(self):\n",
+ " print \"In base class function\"\n",
+ " \n",
+ "class D(B):\n",
+ " def show(self):\n",
+ " \n",
+ " print \"In Derived class\"\n",
+ " \n",
+ " \n",
+ "b=B()\n",
+ "d=D()\n",
+ "\n",
+ "b.show()\n",
+ "d.show()\n",
+ "\n",
+ "bp=[B()] #create a base class pointer variable\n",
+ "bp[0]=d #assign address of the derived class object to the base class pointer\n",
+ "bp[0].show() #call the derived class method by base class pointer\n",
+ "b.show() #calling the base class method by base class object"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In base class function\n",
+ "In Derived class\n",
+ "In Derived class\n",
+ "In base class function\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.32, Page Number:495"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Constuctor and destructors in single inheritance\n",
+ "class Father:\n",
+ " def __init__(self):\n",
+ " print \"Base Class constructor.\"\n",
+ " self._name=raw_input(\"Enter Father Name:\")\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Base class Destructor.\"\n",
+ " \n",
+ "class Child(Father):\n",
+ " def __init__(self):\n",
+ " Father.__init__(self)\n",
+ " print \"Derived class constructor.\"\n",
+ " self.__cname=raw_input(\"Enter child name:\")\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Derived class destructor.\"\n",
+ " print \"\",self.__cname,\"\",self.__name\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__del__(self)\n",
+ " \n",
+ " \n",
+ " \n",
+ "C=Child()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base Class constructor.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Father Name:Manoj\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Derived class constructor.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter child name:Sanjay\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Derived class destructor.\n",
+ " Sanjay Manoj\n",
+ "Base class Destructor.\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.33, Page Number:496"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Constuctor and destructors in multilevel inheritance\n",
+ "\n",
+ "class Grandfather:\n",
+ " def __init__(self):\n",
+ " print\"Constructor of class grandfather\"\n",
+ " self._gname=raw_input(\"Enter Grandfather Name:\")\n",
+ " \n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class grandfather\"\n",
+ " \n",
+ " \n",
+ "class Father(Grandfather):\n",
+ " def __init__(self):\n",
+ " Grandfather.__init__(self)\n",
+ " print\"Constructor of class Father\"\n",
+ " self._name=raw_input(\"Enter Father Name:\")\n",
+ " \n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class Father\"\n",
+ " Grandfather.__del__(self)\n",
+ " \n",
+ "class Child(Father):\n",
+ " def __init__(self):\n",
+ " Father.__init__(self)\n",
+ " print\"Constructor of class Child\"\n",
+ " self.__cname=raw_input(\"Enter Child Name:\")\n",
+ " \n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class Child\"\n",
+ " print \"Grandfather:\",self._gname,\"Father:\",self._name,\"Child:\",self.__cname\n",
+ " Father.__del__(self) \n",
+ " \n",
+ " \n",
+ "C=Child()\n",
+ "\n",
+ "del C #call the destructor of the derived class\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class grandfather\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Grandfather Name:x\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class Father\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Father Name:y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class Child\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Child Name:z\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Destructor of class Child\n",
+ "Grandfather: x Father: y Child: z\n",
+ "Destructor of class Father\n",
+ "Destructor of class grandfather\n"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.34, Page Number:498"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#program to explain multilevel inheritance with member function\n",
+ "class Grandfather:\n",
+ " def __init__(self):\n",
+ " self.__gname=None\n",
+ " \n",
+ " def getg(self):\n",
+ " self.__gname=raw_input(\"Enter Grandfather Name:\")\n",
+ " \n",
+ " def showg(self):\n",
+ " print \"Grandfather Name:\",self.__gname\n",
+ " \n",
+ " \n",
+ "class Father(Grandfather):\n",
+ " def __init__(self):\n",
+ " self.__name=None\n",
+ " \n",
+ " def getf(self):\n",
+ " self.__name=raw_input(\"Enter Father Name:\")\n",
+ " \n",
+ " def showf(self):\n",
+ " print \"Father Name:\",self.__name\n",
+ " \n",
+ " \n",
+ "class Child(Father):\n",
+ " def __init__(self):\n",
+ " self.__cname=None\n",
+ " \n",
+ " def getc(self):\n",
+ " self.getg()\n",
+ " self.getf()\n",
+ " self.__cname=raw_input(\"Enter Child Name:\")\n",
+ " \n",
+ " def showc(self):\n",
+ " self.showg()\n",
+ " self.showf()\n",
+ " print \"child Name:\",self.__cname\n",
+ " \n",
+ "C=Child()\n",
+ "C.getc()\n",
+ "C.showc()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Grandfather Name:XXX\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Father Name:YYY\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Child Name:ZZZ\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Grandfather Name: XXX\n",
+ "Father Name: YYY\n",
+ "child Name: ZZZ\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.35, Page Number:499"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#execution of constructor and destructor in multilevel inheritance\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " print \"Constructor of class A\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class A\"\n",
+ " \n",
+ " \n",
+ "class B:\n",
+ " def __init__(self):\n",
+ " print \"Constructor of class B\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class B\"\n",
+ " \n",
+ "class C:\n",
+ " def __init__(self):\n",
+ " print \"Constructor of class C\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class C\"\n",
+ " \n",
+ " \n",
+ "class D(A,B,C):\n",
+ " def __init__(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self) \n",
+ " print \"Constructor of class D\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class D\"\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__del__(self)\n",
+ " \n",
+ "x=D() \n",
+ " #**NOTE:Python destuctor is called when program goes exit. So output may be differ than c++"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class A\n",
+ "Constructor of class B\n",
+ "Constructor of class C\n",
+ "Constructor of class D\n",
+ "Destructor of class D\n",
+ "Destructor of class A\n",
+ "Destructor of class B\n",
+ "Destructor of class C\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.37, Page Number:502"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#execution of constructor and destructor in multilevel inheritance\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " print \"Constructor of class A\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class A\"\n",
+ " \n",
+ " \n",
+ "class B(A):\n",
+ " def __init__(self):\n",
+ " A.__init__(self)\n",
+ " print \"Constructor of class B\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class B\"\n",
+ " A.__del__(self)\n",
+ " \n",
+ "class C:\n",
+ " def __init__(self):\n",
+ " print \"Constructor of class C\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class C\"\n",
+ " \n",
+ " \n",
+ "class D(B,C):\n",
+ " def __init__(self):\n",
+ " B.__init__(self)\n",
+ " C.__init__(self)\n",
+ " print \"Constructor of class D\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class D\"\n",
+ " B.__del__(self)\n",
+ " C.__del__(self)\n",
+ " \n",
+ "x=D() \n",
+ "del x\n",
+ " #**NOTE:Python destuctor is called when program goes exit. So output may be differ than c++"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class A\n",
+ "Constructor of class B\n",
+ "Constructor of class C\n",
+ "Constructor of class D\n",
+ "Destructor of class D\n",
+ "Destructor of class B\n",
+ "Destructor of class A\n",
+ "Destructor of class C\n"
+ ]
+ }
+ ],
+ "prompt_number": 54
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.37, Page Number:502"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#demonstrate single inheritance\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self,j=0):\n",
+ " self._c=j\n",
+ " \n",
+ " def show(self):\n",
+ " print \"c=\",self._c\n",
+ " \n",
+ " def inc(self):\n",
+ " self._c=self._c+1\n",
+ " return self._c\n",
+ " \n",
+ "class B(A):\n",
+ " \n",
+ " def __init_(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self)\n",
+ " \n",
+ " def dec(self):\n",
+ " self._c=self._c-1\n",
+ " return self._c\n",
+ " \n",
+ " \n",
+ "a=B()\n",
+ "a.inc()\n",
+ "a.show()\n",
+ "\n",
+ "\n",
+ "a.dec()\n",
+ "a.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c= 1\n",
+ "c= 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.38, Page Number:502"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#access method from private inheritance\n",
+ "class B:\n",
+ " def one(self):\n",
+ " print \"one\"\n",
+ " \n",
+ " def __two(self):\n",
+ " print \"two\"\n",
+ " \n",
+ "class D(B):\n",
+ " def __init__(self):\n",
+ " pass\n",
+ " \n",
+ "d=D()\n",
+ "d.one()\n",
+ "#d.two() #Not accesible"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "one\n"
+ ]
+ }
+ ],
+ "prompt_number": 45
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.39, Page Number:503"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#create a comman constructor in the lowermost class, in the multilevel inheritance\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.x=None\n",
+ " \n",
+ "class B(A):\n",
+ " def __init__(self):\n",
+ " self.y=None\n",
+ " \n",
+ "class C(B):\n",
+ " def __init__(self,j,k,l):\n",
+ " self.z=l\n",
+ " self.x=j\n",
+ " self.y=k\n",
+ " \n",
+ " def show(self):\n",
+ " print \"x=\",self.x,\"Y=\",self.y,\"z=\",self.z\n",
+ " \n",
+ "c=C(4,7,1)\n",
+ "c.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 4 Y= 7 z= 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.40, Page Number:504"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Explicitly call the base constructor in multiple inheritance\n",
+ "\n",
+ "class X:\n",
+ " def __init__(self,a):\n",
+ " print a,\n",
+ " \n",
+ "class Y:\n",
+ " def __init__(self,b):\n",
+ " print b,\n",
+ " \n",
+ "class Z(X,Y):\n",
+ " def __init__(self,p,q,r):\n",
+ " X.__init__(self,p)\n",
+ " Y.__init__(self,q)\n",
+ " print r\n",
+ " \n",
+ " \n",
+ "z=Z(1,2,3)\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 2 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/AJEET KUMARSINGH/Chapter_11_Inheritance_(1).ipynb b/sample_notebooks/AJEET KUMARSINGH/Chapter_11_Inheritance_(1).ipynb
new file mode 100755
index 00000000..4f69b243
--- /dev/null
+++ b/sample_notebooks/AJEET KUMARSINGH/Chapter_11_Inheritance_(1).ipynb
@@ -0,0 +1,2636 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e85379c4218575d4b069259557cffbbc2d0259e3ba5d0e030c11dd77aae5e38d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.1, Page Number:444"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#A simple classA having a public data member x\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.x=None\n",
+ "\n",
+ "#A simple classA having a public data member y \n",
+ "class B(A): #derived class\n",
+ " def __init__(self):\n",
+ " self.y=None\n",
+ " \n",
+ "b=B() #create a instance b of Derived class B\n",
+ "b.x=20\n",
+ "b.y=30\n",
+ "\n",
+ "print 'member of A:',b.x\n",
+ "print 'Member of B:',b.y"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "member of A: 20\n",
+ "Member of B: 30\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.2, Page Number:445"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A:\n",
+ " def __init__(self): #class A having x as a private data member\n",
+ " self.__x=20\n",
+ " \n",
+ " def showx(self):\n",
+ " print \"x=\",self.__x\n",
+ " \n",
+ " \n",
+ "class B(A): #Derived class\n",
+ " def __init__(self):\n",
+ " self.y=30 #class B having y as a public data member\n",
+ " \n",
+ " def show(self):\n",
+ " a=A()\n",
+ " a.showx()\n",
+ " print \"y=\",self.y\n",
+ " \n",
+ " \n",
+ "b=B() #declaration of object\n",
+ " #class the method of derived class object by a derived class instance\n",
+ "b.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 20\n",
+ "y= 30\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.3, Page Number:447"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#base class\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.x=None #x is a public member\n",
+ " \n",
+ " \n",
+ "#derived class\n",
+ "class B(A):\n",
+ " def __init__(self):\n",
+ " self.y=40 \n",
+ " A.__x=20 #since it is privately inherites base class ,x become private member of it\n",
+ " \n",
+ " def show(self):\n",
+ " print \"x=\",A.__x\n",
+ " print \"y=\",self.y\n",
+ " \n",
+ "b=B()\n",
+ "b.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 20\n",
+ "y= 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.4, Page Number:448"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.__x=20 #x is a privet member of it\n",
+ " \n",
+ " def showx(self): \n",
+ " print \"x=\",self.__x\n",
+ " \n",
+ " \n",
+ "class B(A):\n",
+ " def __init__(self):\n",
+ " self.y=40 #y is a public member of it\n",
+ " \n",
+ " def show(self):\n",
+ " a=A()\n",
+ " a.showx() #call the base class method\n",
+ " print \"y=\",self.y\n",
+ " \n",
+ " \n",
+ "b=B()\n",
+ "b.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 20\n",
+ "y= 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.5, Page Number:449"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A:\n",
+ " def __init__(self):\n",
+ " self._x=None #x is a protected member of the base class\n",
+ " \n",
+ " \n",
+ "class B(A): #private inheritance,x become a private member of the derived class\n",
+ " def __init__(self):\n",
+ " self.y=40\n",
+ " self.__x=30\n",
+ " \n",
+ " \n",
+ " def show(self):\n",
+ " print \"x=\",self.__x\n",
+ " print \"y=\",self.y\n",
+ " \n",
+ " \n",
+ "b=B()\n",
+ "b.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 30\n",
+ "y= 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.6, Page Number:456"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class ABC: #Base class\n",
+ " def __init__(self):\n",
+ " self._name=None #these 2 are protected data member\n",
+ " self._age=None\n",
+ " \n",
+ "class abc(ABC): #Derived class ,Public derivation\n",
+ " def __init__(self):\n",
+ " self.height=None\n",
+ " self.weight=None\n",
+ " \n",
+ " def getdata(self):\n",
+ " \n",
+ " self.name=raw_input(\"Enter a name: \") #take inputes to all the data members \n",
+ " self.age=raw_input(\"Enter a age: \") \n",
+ " self._height=raw_input(\"Enter a Height: \") \n",
+ " self._weight=raw_input(\"Enter a Weight: \") \n",
+ " \n",
+ " def show(self): #display the value of data members\n",
+ " print 'Name:',self.name \n",
+ " print 'Age:',self.age,\"years\"\n",
+ " print 'Height:',self._height,\"Feets\"\n",
+ " print 'Weight:',self._weight,\"kg.\"\n",
+ " \n",
+ " \n",
+ "x=abc()\n",
+ "x.getdata()\n",
+ "x.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a name: Santosh\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a age: 24\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a Height: 4.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a Weight: 50\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Santosh\n",
+ "Age: 24 years\n",
+ "Height: 4.5 Feets\n",
+ "Weight: 50 kg.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.7, Page Number:458"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A1: #super Base class,have 2 protected data members\n",
+ " def __init__(self):\n",
+ " self._name=None\n",
+ " self._age=None\n",
+ "\n",
+ " \n",
+ "class A2(A1): #Public derivation\n",
+ " def __init(self):\n",
+ " self._height=None\n",
+ " self._weight=None\n",
+ "\n",
+ "class A3(A2): #public Derivation\n",
+ " def __init__(self):\n",
+ " self._sex=None\n",
+ " \n",
+ " \n",
+ " def get(self): #get input \n",
+ " self._name=raw_input(\"Name: \")\n",
+ " self._age=raw_input(\"Age: \")\n",
+ " self._sex=raw_input(\"Sex: \")\n",
+ " \n",
+ " self._height=raw_input(\"Height: \")\n",
+ " self._weight=raw_input(\"Weight: \")\n",
+ " \n",
+ " def show(self): #Display values of all the data members\n",
+ " print \"Name:\",self._name\n",
+ " print \"Age:\",self._age ,\"years\"\n",
+ " print \"Sex:\",self._sex\n",
+ " print \"Height:\",self._height ,\"Feet\"\n",
+ " print \"Weight:\",self._weight ,\"Kg.\"\n",
+ " \n",
+ "\n",
+ "x=A3()\n",
+ "x.get()\n",
+ "x.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Balaji\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age: 26\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sex: M\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Height: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Weight: 49.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Balaji\n",
+ "Age: 26 years\n",
+ "Sex: M\n",
+ "Height: 4 Feet\n",
+ "Weight: 49.5 Kg.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.8, Page Number:459"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example of multiple Inheritance\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self._a=None\n",
+ " \n",
+ "class B:\n",
+ " def __init__(self):\n",
+ " self._b=None\n",
+ " \n",
+ " \n",
+ "class C:\n",
+ " def __init__(self):\n",
+ " self._c=None\n",
+ " \n",
+ "class D:\n",
+ " def __init__(self):\n",
+ " self._d=None\n",
+ " \n",
+ "class E(A,B,C,D): #inherites all the base classes publically\n",
+ " def __init__(self):\n",
+ " self.e=None\n",
+ " \n",
+ " def getdata(self):\n",
+ " print \"Enter the value of a,b,c &d &e:\"\n",
+ " self._a=input()\n",
+ " self._b=input()\n",
+ " self._c=input()\n",
+ " self._d=input()\n",
+ " self._e=input()\n",
+ " \n",
+ " def show(self):\n",
+ " print\"a=\",self._a,\"b=\",self._b,\"c=\",self._c,\"d=\",self._d,\"e=\",self._e\n",
+ " \n",
+ " \n",
+ "x=E() #x is the instance of the derived class\n",
+ "x.getdata() #call the methods of derived class through x \n",
+ "x.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the value of a,b,c &d &e:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "16\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a= 1 b= 2 c= 4 d= 8 e= 16\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.9, Page Number:461"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class red: #these three base class\n",
+ " def __init__(self):\n",
+ " print \"Red\",\n",
+ " \n",
+ "class yellow:\n",
+ " def __init__(self):\n",
+ " print \"Yellow\",\n",
+ " \n",
+ "class blue:\n",
+ " def __init__(self):\n",
+ " print \"Blue\",\n",
+ " \n",
+ "class orange(red,yellow): #public multiple Derivation\n",
+ " def __init__(self):\n",
+ " red.__init__(self)\n",
+ " yellow.__init__(self)\n",
+ " print \"=Orange\",\n",
+ " \n",
+ "class green(blue,yellow): #public multiple Derivation\n",
+ " def __init__(self):\n",
+ " blue.__init__(self)\n",
+ " yellow.__init__(self)\n",
+ " print \"=Green\",\n",
+ " \n",
+ "class violet(red,blue): #public multiple Derivation\n",
+ " def __init__(self):\n",
+ " red.__init__(self)\n",
+ " blue.__init__(self)\n",
+ " print \"=Violet\",\n",
+ " \n",
+ "class reddishbrown(orange,violet): #public multiple & multilevel Derivation\n",
+ " def __init__(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self)\n",
+ " print \"=Reddishbrown\"\n",
+ " \n",
+ "class yellowishbrown(green,orange): #public multiple & multilevel Derivation\n",
+ " def __init__(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self)\n",
+ " print \"=Yellowishbrown\"\n",
+ " \n",
+ "class bluishbrown(violet,green): #public multiple & multilevel Derivation\n",
+ " def __init__(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self)\n",
+ " print \"=Bluishbrown\"\n",
+ " \n",
+ " \n",
+ " \n",
+ "r=reddishbrown() #create instances of the derived class\n",
+ "b=bluishbrown()\n",
+ "y=yellowishbrown()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Red Yellow =Orange Red Blue =Violet =Reddishbrown\n",
+ "Red Blue =Violet Blue Yellow =Green =Bluishbrown\n",
+ "Blue Yellow =Green Red Yellow =Orange =Yellowishbrown\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.10, Page Number:463"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# WAP to create a derived class from multiple base classes\n",
+ "\n",
+ "class PLAYER: #these three are the base classes\n",
+ " def __init__(self):\n",
+ " self._name=None\n",
+ " self._gender=None\n",
+ " self._age\n",
+ " \n",
+ "class PHYSIQUE(PLAYER):\n",
+ " def __init__(self):\n",
+ " self._height=None\n",
+ " self._weight=None\n",
+ " \n",
+ "class LOCATION:\n",
+ " def __init__(self):\n",
+ " self._city=None\n",
+ " self._pin=None\n",
+ " \n",
+ "class GAME(PHYSIQUE,LOCATION): #Multiple derivation\n",
+ " def __init__(self):\n",
+ " self._game=None\n",
+ " def getdata(self): #Method to take inputes\n",
+ " print\"Enter the following information\\n\\n\"\n",
+ " self._name=raw_input(\"Name:\")\n",
+ " self._gender=raw_input(\"Gender:\")\n",
+ " self._age=raw_input(\"Age:\")\n",
+ " self._height=raw_input(\"Height:\")\n",
+ " self._weight=raw_input(\"Weight:\")\n",
+ " self._city=raw_input(\"City:\")\n",
+ " self._pin=raw_input(\"Pin:\")\n",
+ " self._game=raw_input(\"game:\")\n",
+ " \n",
+ " \n",
+ " \n",
+ " def show(self): #Method for displaying inputes\n",
+ " print\"Entered Information!!\"\n",
+ " print\"Name:\",self._name\n",
+ " print \"Gender:\",self._gender\n",
+ " print \"Age:\",self._age\n",
+ " print \"Height:\",self._height\n",
+ " print \"Weight:\",self._weight\n",
+ " print \"City :\",self._city\n",
+ " print \"Pincode:\",self._pin\n",
+ " print \"Game :\",self._game\n",
+ " \n",
+ " \n",
+ "G=GAME() #create an instance of the derived class\n",
+ "G.getdata() #call the public methods by the created instances\n",
+ "G.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the following information\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name:Mahesh\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gender:M\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:25\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Height:4.9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Weight:55\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "City:Nanded\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pin:431603\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "game:Cricket\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Entered Information!!\n",
+ "Name: Mahesh\n",
+ "Gender: M\n",
+ "Age: 25\n",
+ "Height: 4.9\n",
+ "Weight: 55\n",
+ "City : Nanded\n",
+ "Pincode: 431603\n",
+ "Game : Cricket\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.11, Page Number:467"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Multipath Inheritance,concept of virtual classes\n",
+ "\n",
+ "class A1: #Super base class\n",
+ " def __init__(self):\n",
+ " self._a1=None\n",
+ " \n",
+ "class A2(A1): #base class 1,inherites Super Base class\n",
+ " def __init__(self):\n",
+ " self._a2=None\n",
+ " \n",
+ "class A3(A1): #base class 2,inherites Super Base class\n",
+ " def __init__(self):\n",
+ " self._a3=None\n",
+ " \n",
+ "class A4(A2,A3): #derived class ,public derivation of both the base classes\n",
+ " def __init__(self):\n",
+ " self.__a4=None\n",
+ " \n",
+ " def get(self):\n",
+ " print \"Enter the value of a1,a2,a3,and a4:\"\n",
+ " self._a1=input()\n",
+ " self._a2=input()\n",
+ " self._a3=input()\n",
+ " self.__a4=input()\n",
+ " \n",
+ " def put(self):\n",
+ " print \"a1=\",self._a1,\"a2=\",self._a2,\"a3=\",self._a3,\"a4=\",self.__a4\n",
+ " \n",
+ " \n",
+ " \n",
+ "a=A4() #create the instance of the derived class\n",
+ "a.get()\n",
+ "a.put()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the value of a1,a2,a3,and a4:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a1= 5 a2= 8 a3= 7 a4= 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.12, Page Number:469"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To show order of execution of the constructors and destructors in multiple inheritance\n",
+ "\n",
+ "#**NOTE:Python destuctor is called when program goes exit. So output may be differ than c++\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " print\"Zero argument Constructor of base class A\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Destructor of class A\"\n",
+ " \n",
+ "class B:\n",
+ " def __init__(self):\n",
+ " print\"Zero argument Constructor of base class B\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Destructor of class B\"\n",
+ "\n",
+ "class C(A,B):\n",
+ " def __init__(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self)\n",
+ " print\"Zero argument Constructor of base class C\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Destructor of class C\"\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__del__(self)\n",
+ " \n",
+ "c=C() #create instance of derived class"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Zero argument Constructor of base class A\n",
+ "Zero argument Constructor of base class B\n",
+ "Zero argument Constructor of base class C\n",
+ "Destructor of class C\n",
+ "Destructor of class A\n",
+ "Destructor of class B\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.13, Page Number:471"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#WAP to use constructor and destructor in all the classess\n",
+ "\n",
+ "class A1:\n",
+ " def __init__(self): #take name and age as input in super base class\n",
+ " self._name=raw_input(\"Name:\")\n",
+ " self._age=raw_input(\"Age:\")\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Name:\",self._name\n",
+ " print\"Age\",self._age\n",
+ " \n",
+ " \n",
+ "class A2(A1): #take height and weight as input in base base class,public derivation \n",
+ " def __init__(self):\n",
+ " A1.__init__(self)\n",
+ " self._height=raw_input(\"Height:\")\n",
+ " self._weight=raw_input(\"Weight:\")\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Height:\",self._height\n",
+ " print\"Weight:\",self._weight\n",
+ " A1.__del__(self)\n",
+ " \n",
+ " \n",
+ "class A3(A2): #take sex as input in derived class,derived from class A2\n",
+ " def __init__(self):\n",
+ " A2.__init__(self)\n",
+ " self.__sex=raw_input(\"Sex:\")\n",
+ " def __del__(self): #display all the input taken by all the base classes\n",
+ " print\"Sex:\",self.__sex\n",
+ " A2.__del__(self)\n",
+ " \n",
+ " \n",
+ "x=A3() #create instance x of the class A3\n",
+ "\n",
+ "del x #call the destructor"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name:Ajay\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Height:4.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Weight:40\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sex:M\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sex: M\n",
+ "Height: 4.5\n",
+ "Weight: 40\n",
+ "Name: Ajay\n",
+ "Age 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.14, Page Number:472"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To create derived class from the base class,by constructor and destructor\n",
+ "class in_t:\n",
+ " def __init__(self):\n",
+ " self._i=1\n",
+ " print\"Constructor in_t()\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Destructor in_t()\"\n",
+ " \n",
+ "class floa_t:\n",
+ " def __init__(self):\n",
+ " self._f=1.5\n",
+ " print\"Constructor floa_t()\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print\"Destructor floa_t()\"\n",
+ " \n",
+ " \n",
+ "class cha_r(in_t,floa_t): #multiple derivation\n",
+ " def __init__(self):\n",
+ " self._c='A'\n",
+ " print\"Constructor cha_r()\"\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self)\n",
+ " \n",
+ " def show(self):\n",
+ " print\"i=\",self._i\n",
+ " print \"f=\",self._f\n",
+ " print \"c=\",self._c\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructing cha_r()\"\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__del__(self)\n",
+ " \n",
+ "a=cha_r() #create derived class instance and call the public method of the derived class\n",
+ "a.show() #**NOTE:Python destuctor is called when program goes exit. So output may be differ than c++"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor cha_r()\n",
+ "Constructor in_t()\n",
+ "Constructor floa_t()\n",
+ "i= 1\n",
+ "f= 1.5\n",
+ "c= A\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.15, Page Number:474"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " self.x=None\n",
+ " \n",
+ "class II(I):\n",
+ " def __init__(self):\n",
+ " self.__y=None\n",
+ " \n",
+ " def set(self,j,k):\n",
+ " self.x=j\n",
+ " self.__y=k\n",
+ " \n",
+ " def show(self):\n",
+ " print \"X=\",self.x, \"Y=\",self.__y\n",
+ " \n",
+ " \n",
+ "i=II()\n",
+ "i.set(4,5)\n",
+ "i.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X= 4 Y= 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.16, Page Number:475"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class I:\n",
+ " def __init__(self):\n",
+ " self.x=10\n",
+ " print \"In the Base class constuctor\"\n",
+ " \n",
+ "class II(I):\n",
+ " def __init__(self):\n",
+ " I.__init__(self)\n",
+ " self.__y=None\n",
+ " \n",
+ "i=II()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In the Base class constuctor\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.17, Page Number:475"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#base class without constructor and derived class with constructor\n",
+ "class I:\n",
+ " pass\n",
+ "class II(I):\n",
+ " def __init__(self):\n",
+ " print \"In derived class constructor\"\n",
+ " \n",
+ "i=II()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In derived class constructor\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.18, Page Number:476"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#both the class have constructor\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " print \"In base class Constructor\"\n",
+ " \n",
+ "class II(I):\n",
+ " def __init__(self):\n",
+ " I.__init__(self)\n",
+ " print \"In derived Class constructor\"\n",
+ " \n",
+ "i=II()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In base class Constructor\n",
+ "In derived Class constructor\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.19, Page Number:477"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#multiple constructor in base class and single constructor in the derived class\n",
+ "\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument base class construtor\"\n",
+ " \n",
+ " def __init__(self,k):\n",
+ " self.x=None\n",
+ " print \"One argument base class construtor\"\n",
+ " \n",
+ " \n",
+ "class II(I):\n",
+ " def __init__(self,j,k=None): #default constructor\n",
+ " I.__init__(self,k)\n",
+ " self.__y=j\n",
+ " print \"One argument derived class constructor\"\n",
+ " \n",
+ "i=II(2) #create the instance of the base class by passing initial value "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "One argument base class construtor\n",
+ "One argument derived class constructor\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.20, Page Number:478"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#base and derived class without default constructor\n",
+ "class I:\n",
+ " def __init__(self,k):\n",
+ " self.x=k\n",
+ " print \"One argument base class construtor\"\n",
+ " \n",
+ "class II(I):\n",
+ " def __init__(self,j):\n",
+ " I.__init__(self,j)\n",
+ " self.__y=j\n",
+ " print \"One argument derived class construtor\"\n",
+ " \n",
+ "i=II(2) #create the instance of the base class by passing initial value "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "One argument base class construtor\n",
+ "One argument derived class construtor\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.21, Page Number:479"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Constructors and multiple inheritance\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class I\"\n",
+ " \n",
+ "class II:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class II\"\n",
+ " \n",
+ "class III(II,I): #class III inhrites class II and I\n",
+ " def __init__(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self) \n",
+ " print \"Zero argument constructor of base class III\"\n",
+ " \n",
+ "i=III() #create an instance of the base class\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Zero argument constructor of base class II\n",
+ "Zero argument constructor of base class I\n",
+ "Zero argument constructor of base class III\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.22, Page Number:480"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Constructors in multiple inhritance with invoking constructor of the base classes\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class I\"\n",
+ " \n",
+ "class II:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class II\"\n",
+ " \n",
+ "class III(II,I):\n",
+ " def __init__(self):\n",
+ " II.__init__(self)\n",
+ " I.__init__(self)\n",
+ " print \"Zero argument constructor of base class III\"\n",
+ " \n",
+ "i=III()\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Zero argument constructor of base class II\n",
+ "Zero argument constructor of base class I\n",
+ "Zero argument constructor of base class III\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.23, Page Number:481"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#multiple inheritance,invoking the base classes explicitly\n",
+ "\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class I\"\n",
+ " \n",
+ "class II:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class II\"\n",
+ " \n",
+ "class III(II,I): #Class I is virtually inherited so its constructor called first\n",
+ " def __init__(self):\n",
+ " I.__init__(self)\n",
+ " II.__init__(self)\n",
+ " print \"Zero argument constructor of base class III\"\n",
+ " \n",
+ "i=III()\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Zero argument constructor of base class I\n",
+ "Zero argument constructor of base class II\n",
+ "Zero argument constructor of base class III\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.24, Page Number:482"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#multilevel Inheritance,observation of the execution of the constructors\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " print \"Zero argument constructor of base class I\"\n",
+ " \n",
+ "class II(I):\n",
+ " def __init__(self):\n",
+ " I.__init__(self)\n",
+ " print \"Zero argument constructor of base class II\"\n",
+ " \n",
+ "class III(II): #Class I is virtually inherited so its constructor called first\n",
+ " def __init__(self):\n",
+ " II.__init__(self)\n",
+ " print \"Zero argument constructor of base class III\"\n",
+ " \n",
+ "i=III()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Zero argument constructor of base class I\n",
+ "Zero argument constructor of base class II\n",
+ "Zero argument constructor of base class III\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.25, Page Number:484"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#use object of one class in another class as a member\n",
+ "class I:\n",
+ " def __init__(self):\n",
+ " self.x=20\n",
+ " print \"Constructor of class I\"\n",
+ " \n",
+ "class II:\n",
+ " \n",
+ " def __init__(self):\n",
+ " self.k=30\n",
+ " y=I()\n",
+ " print \"Constructor of class II\"\n",
+ " print \"x=\",y.x #print here because it become local variable in this scope only,it not visible to def show\n",
+ " \n",
+ " \n",
+ " def show(self):\n",
+ " print \"k=\",self.k\n",
+ " \n",
+ "ii=II()\n",
+ "ii.show() #**NOTE:Python destuctor is called when program goes exit. So output may be differ than c++"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class I\n",
+ "Constructor of class II\n",
+ "x= 20\n",
+ "k= 30\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.26, Page Number:484"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#access a member variable of base class using object,class name, and direct\n",
+ "\n",
+ "class A1:\n",
+ " def __init__(self):\n",
+ " self.name=None\n",
+ " self.age=None\n",
+ " \n",
+ "class A2(A1):\n",
+ " def __init__(self):\n",
+ " A1.__init__(self)\n",
+ " a=A1()\n",
+ " print \"Access using name of the class:\"\n",
+ " A1.name=raw_input(\"Name:\")\n",
+ " A1.age=raw_input(\"Age:\")\n",
+ " \n",
+ " print \"Access using object of the class\"\n",
+ " a.name=raw_input(\"Name:\")\n",
+ " a.age=raw_input(\"Age:\")\n",
+ " \n",
+ " print \"Access using direct member variables:\"\n",
+ " self.name=raw_input(\"Name:\")\n",
+ " self.age=raw_input(\"Age:\")\n",
+ " self.__height=raw_input(\"Height:\")\n",
+ " self.__weight=raw_input(\"Weight:\")\n",
+ " \n",
+ " print \"Display using object of the class\" #since object of class A1 has scope in constructor method so we can access it only \n",
+ " print \"Name:\",a.name # within this method.It is not visible in destructor function.\n",
+ " print \"Age:\",a.age\n",
+ " \n",
+ " \n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of Derived class\"\n",
+ " print \"Display using class name\"\n",
+ " print \"Name:\",A1.name\n",
+ " print \"Age:\",A1.age\n",
+ " \n",
+ " print \"Display using direct member variable\"\n",
+ " print \"Name:\",self.name\n",
+ " print \"Age\",self.age\n",
+ " print \"height:\",self.__height\n",
+ " print \"Weight:\",self.__weight\n",
+ " \n",
+ "x=A2()\n",
+ "\n",
+ "del x\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Access using name of the class:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name:Ajay\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:21\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Access using object of the class\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name:Amit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Access using direct member variables:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name:Arun\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:19\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Height:5.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Weight:31\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Display using object of the class\n",
+ "Name: Amit\n",
+ "Age: 20\n",
+ "Destructor of Derived class\n",
+ "Display using class name\n",
+ "Name: Ajay\n",
+ "Age: 21\n",
+ "Display using direct member variable\n",
+ "Name: Arun\n",
+ "Age 19\n",
+ "height: 5.5\n",
+ "Weight: 31\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.27, Page Number:488"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#derive a class from two base classes,object of these 2 classes is the member variable of the third class\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.a1=None\n",
+ " \n",
+ "class B:\n",
+ " def __init__(self):\n",
+ " self.b1=None\n",
+ " \n",
+ "class AB:\n",
+ " def __init__(self):\n",
+ " a=A()\n",
+ " b=B()\n",
+ " a.a1=65 #initialize the two data members of the class A and B and Display them\n",
+ " b.b1=66\n",
+ " print \"a1=\",a.a1, \"b1=\",b.b1\n",
+ " \n",
+ " def __del__(self):\n",
+ " pass\n",
+ " \n",
+ " \n",
+ "ab=AB()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a1= 65 b1= 66\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.28, Page Number:489"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#create derived class from qualifier class\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.x=None\n",
+ " \n",
+ " class B:\n",
+ " def __init__(self):\n",
+ " self.y=None\n",
+ " \n",
+ " \n",
+ "class C(A,A.B): #A.B is the inner class of the class A\n",
+ " def __init__(self,j,k,l):\n",
+ " self.x=j\n",
+ " self.y=k\n",
+ " self.z=l\n",
+ " \n",
+ " def show(self):\n",
+ " print \"x=\",self.x,\"y=\",self.y,\"z=\",self.z\n",
+ " \n",
+ " \n",
+ "c=C(4,7,1)\n",
+ "c.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 4 y= 7 z= 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.29, Page Number:490"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#initialize member variable of the base class and derived class using constructor of the derived class\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self._x=None #protected members\n",
+ " self._y=None\n",
+ " \n",
+ "class B(A):\n",
+ " def __init__(self):\n",
+ " self.z=3\n",
+ " self.__x=1 #private members\n",
+ " self.__y=2\n",
+ " \n",
+ " print \"x=\",self.__x,\"y=\",self.__y,\"z=\",self.z\n",
+ " \n",
+ "b=B()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 1 y= 2 z= 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.30, Page Number:491"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#access data members by object pointer\n",
+ "\n",
+ "from ctypes import *\n",
+ "import ctypes\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.x=1\n",
+ " self.y=2\n",
+ " \n",
+ "class B(A):\n",
+ " def __init__(self):\n",
+ " A.__init__(self)\n",
+ " self.z=3\n",
+ " \n",
+ "b=B()\n",
+ "\n",
+ "\n",
+ "i=c_int(b.z)\n",
+ "p=pointer(i)\n",
+ "print \"Address of z:\",addressof(p),\"Value of Z:\",p[0] #access the\n",
+ "\n",
+ "i = c_int(b.y)\n",
+ "p = pointer(i)\n",
+ "print \"Address of y:\",addressof(p),\"Value of y:\",p[0] \n",
+ "\n",
+ "i = c_int(b.x)\n",
+ "p = pointer(i)\n",
+ "print \"Address of x:\",addressof(p),\"Value of x:\",p[0] \n",
+ "\n",
+ "#**NOTE-In case of C++ the data members of the derived class and base class are stored in contigious memory locations so we can \n",
+ "#access the three variables by using a pointer of derived class and decrementing its value. But in case of Python they are NOT stored \n",
+ "#in contogious memory locations so for accessing each data member we have to create individual object pointer for each class."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address of z: 57077392 Value of Z: 3\n",
+ "Address of y: 57074448 Value of y: 2\n",
+ "Address of x: 57077648 Value of x: 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.31, Page Number:492"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#overload member function in base and derived class\n",
+ "\n",
+ "class B:\n",
+ " def show(self):\n",
+ " print \"In base class function\"\n",
+ " \n",
+ "class D(B):\n",
+ " def show(self):\n",
+ " \n",
+ " print \"In Derived class\"\n",
+ " \n",
+ " \n",
+ "b=B()\n",
+ "d=D()\n",
+ "\n",
+ "b.show()\n",
+ "d.show()\n",
+ "\n",
+ "bp=[B()] #create a base class pointer variable\n",
+ "bp[0]=d #assign address of the derived class object to the base class pointer\n",
+ "bp[0].show() #call the derived class method by base class pointer\n",
+ "b.show() #calling the base class method by base class object"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In base class function\n",
+ "In Derived class\n",
+ "In Derived class\n",
+ "In base class function\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.32, Page Number:495"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Constuctor and destructors in single inheritance\n",
+ "class Father:\n",
+ " def __init__(self):\n",
+ " print \"Base Class constructor.\"\n",
+ " self._name=raw_input(\"Enter Father Name:\")\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Base class Destructor.\"\n",
+ " \n",
+ "class Child(Father):\n",
+ " def __init__(self):\n",
+ " Father.__init__(self)\n",
+ " print \"Derived class constructor.\"\n",
+ " self.__cname=raw_input(\"Enter child name:\")\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Derived class destructor.\"\n",
+ " print \"\",self.__cname,\"\",self.__name\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__del__(self)\n",
+ " \n",
+ " \n",
+ " \n",
+ "C=Child()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base Class constructor.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Father Name:Manoj\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Derived class constructor.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter child name:Sanjay\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Derived class destructor.\n",
+ " Sanjay Manoj\n",
+ "Base class Destructor.\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.33, Page Number:496"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Constuctor and destructors in multilevel inheritance\n",
+ "\n",
+ "class Grandfather:\n",
+ " def __init__(self):\n",
+ " print\"Constructor of class grandfather\"\n",
+ " self._gname=raw_input(\"Enter Grandfather Name:\")\n",
+ " \n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class grandfather\"\n",
+ " \n",
+ " \n",
+ "class Father(Grandfather):\n",
+ " def __init__(self):\n",
+ " Grandfather.__init__(self)\n",
+ " print\"Constructor of class Father\"\n",
+ " self._name=raw_input(\"Enter Father Name:\")\n",
+ " \n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class Father\"\n",
+ " Grandfather.__del__(self)\n",
+ " \n",
+ "class Child(Father):\n",
+ " def __init__(self):\n",
+ " Father.__init__(self)\n",
+ " print\"Constructor of class Child\"\n",
+ " self.__cname=raw_input(\"Enter Child Name:\")\n",
+ " \n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class Child\"\n",
+ " print \"Grandfather:\",self._gname,\"Father:\",self._name,\"Child:\",self.__cname\n",
+ " Father.__del__(self) \n",
+ " \n",
+ " \n",
+ "C=Child()\n",
+ "\n",
+ "del C #call the destructor of the derived class\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class grandfather\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Grandfather Name:x\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class Father\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Father Name:y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class Child\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Child Name:z\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Destructor of class Child\n",
+ "Grandfather: x Father: y Child: z\n",
+ "Destructor of class Father\n",
+ "Destructor of class grandfather\n"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.34, Page Number:498"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#program to explain multilevel inheritance with member function\n",
+ "class Grandfather:\n",
+ " def __init__(self):\n",
+ " self.__gname=None\n",
+ " \n",
+ " def getg(self):\n",
+ " self.__gname=raw_input(\"Enter Grandfather Name:\")\n",
+ " \n",
+ " def showg(self):\n",
+ " print \"Grandfather Name:\",self.__gname\n",
+ " \n",
+ " \n",
+ "class Father(Grandfather):\n",
+ " def __init__(self):\n",
+ " self.__name=None\n",
+ " \n",
+ " def getf(self):\n",
+ " self.__name=raw_input(\"Enter Father Name:\")\n",
+ " \n",
+ " def showf(self):\n",
+ " print \"Father Name:\",self.__name\n",
+ " \n",
+ " \n",
+ "class Child(Father):\n",
+ " def __init__(self):\n",
+ " self.__cname=None\n",
+ " \n",
+ " def getc(self):\n",
+ " self.getg()\n",
+ " self.getf()\n",
+ " self.__cname=raw_input(\"Enter Child Name:\")\n",
+ " \n",
+ " def showc(self):\n",
+ " self.showg()\n",
+ " self.showf()\n",
+ " print \"child Name:\",self.__cname\n",
+ " \n",
+ "C=Child()\n",
+ "C.getc()\n",
+ "C.showc()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Grandfather Name:XXX\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Father Name:YYY\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Child Name:ZZZ\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Grandfather Name: XXX\n",
+ "Father Name: YYY\n",
+ "child Name: ZZZ\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.35, Page Number:499"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#execution of constructor and destructor in multilevel inheritance\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " print \"Constructor of class A\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class A\"\n",
+ " \n",
+ " \n",
+ "class B:\n",
+ " def __init__(self):\n",
+ " print \"Constructor of class B\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class B\"\n",
+ " \n",
+ "class C:\n",
+ " def __init__(self):\n",
+ " print \"Constructor of class C\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class C\"\n",
+ " \n",
+ " \n",
+ "class D(A,B,C):\n",
+ " def __init__(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self) \n",
+ " print \"Constructor of class D\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class D\"\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__del__(self)\n",
+ " \n",
+ "x=D() \n",
+ " #**NOTE:Python destuctor is called when program goes exit. So output may be differ than c++"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class A\n",
+ "Constructor of class B\n",
+ "Constructor of class C\n",
+ "Constructor of class D\n",
+ "Destructor of class D\n",
+ "Destructor of class A\n",
+ "Destructor of class B\n",
+ "Destructor of class C\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.37, Page Number:502"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#execution of constructor and destructor in multilevel inheritance\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " print \"Constructor of class A\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class A\"\n",
+ " \n",
+ " \n",
+ "class B(A):\n",
+ " def __init__(self):\n",
+ " A.__init__(self)\n",
+ " print \"Constructor of class B\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class B\"\n",
+ " A.__del__(self)\n",
+ " \n",
+ "class C:\n",
+ " def __init__(self):\n",
+ " print \"Constructor of class C\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class C\"\n",
+ " \n",
+ " \n",
+ "class D(B,C):\n",
+ " def __init__(self):\n",
+ " B.__init__(self)\n",
+ " C.__init__(self)\n",
+ " print \"Constructor of class D\"\n",
+ " \n",
+ " def __del__(self):\n",
+ " print \"Destructor of class D\"\n",
+ " B.__del__(self)\n",
+ " C.__del__(self)\n",
+ " \n",
+ "x=D() \n",
+ "del x\n",
+ " #**NOTE:Python destuctor is called when program goes exit. So output may be differ than c++"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class A\n",
+ "Constructor of class B\n",
+ "Constructor of class C\n",
+ "Constructor of class D\n",
+ "Destructor of class D\n",
+ "Destructor of class B\n",
+ "Destructor of class A\n",
+ "Destructor of class C\n"
+ ]
+ }
+ ],
+ "prompt_number": 54
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.37, Page Number:502"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#demonstrate single inheritance\n",
+ "\n",
+ "class A:\n",
+ " def __init__(self,j=0):\n",
+ " self._c=j\n",
+ " \n",
+ " def show(self):\n",
+ " print \"c=\",self._c\n",
+ " \n",
+ " def inc(self):\n",
+ " self._c=self._c+1\n",
+ " return self._c\n",
+ " \n",
+ "class B(A):\n",
+ " \n",
+ " def __init_(self):\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__init__(self)\n",
+ " \n",
+ " def dec(self):\n",
+ " self._c=self._c-1\n",
+ " return self._c\n",
+ " \n",
+ " \n",
+ "a=B()\n",
+ "a.inc()\n",
+ "a.show()\n",
+ "\n",
+ "\n",
+ "a.dec()\n",
+ "a.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c= 1\n",
+ "c= 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.38, Page Number:502"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#access method from private inheritance\n",
+ "class B:\n",
+ " def one(self):\n",
+ " print \"one\"\n",
+ " \n",
+ " def __two(self):\n",
+ " print \"two\"\n",
+ " \n",
+ "class D(B):\n",
+ " def __init__(self):\n",
+ " pass\n",
+ " \n",
+ "d=D()\n",
+ "d.one()\n",
+ "#d.two() #Not accesible"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "one\n"
+ ]
+ }
+ ],
+ "prompt_number": 45
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.39, Page Number:503"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#create a comman constructor in the lowermost class, in the multilevel inheritance\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " self.x=None\n",
+ " \n",
+ "class B(A):\n",
+ " def __init__(self):\n",
+ " self.y=None\n",
+ " \n",
+ "class C(B):\n",
+ " def __init__(self,j,k,l):\n",
+ " self.z=l\n",
+ " self.x=j\n",
+ " self.y=k\n",
+ " \n",
+ " def show(self):\n",
+ " print \"x=\",self.x,\"Y=\",self.y,\"z=\",self.z\n",
+ " \n",
+ "c=C(4,7,1)\n",
+ "c.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x= 4 Y= 7 z= 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.40, Page Number:504"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Explicitly call the base constructor in multiple inheritance\n",
+ "\n",
+ "class X:\n",
+ " def __init__(self,a):\n",
+ " print a,\n",
+ " \n",
+ "class Y:\n",
+ " def __init__(self,b):\n",
+ " print b,\n",
+ " \n",
+ "class Z(X,Y):\n",
+ " def __init__(self,p,q,r):\n",
+ " X.__init__(self,p)\n",
+ " Y.__init__(self,q)\n",
+ " print r\n",
+ " \n",
+ " \n",
+ "z=Z(1,2,3)\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 2 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/AbhishekGupta/Chapter02.ipynb b/sample_notebooks/AbhishekGupta/Chapter02.ipynb
new file mode 100755
index 00000000..e709048c
--- /dev/null
+++ b/sample_notebooks/AbhishekGupta/Chapter02.ipynb
@@ -0,0 +1,328 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:dd88e5202fe8cb4f62cee212896e4620a6a485517d90fb3c0293ab4baa871eef"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter02: Structure of atoms"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.1:pg-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example 2.1 : radius of the first bohr\"s orbit \n",
+ " \n",
+ "#given data :\n",
+ "\n",
+ "ep=8.854*10**-12;#\n",
+ "h=6.626*10**-34;#\n",
+ "m=9.1*10**-31;#in Kg\n",
+ "e=1.602*10**-19;#\n",
+ "r1=((ep*(h**2))/((math.pi*m*(e**2))));#\n",
+ "print round(r1*10**10,2),\"is radius,r1(in angstrom) \"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0.53 is radius,r1(in angstrom) \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.2:pg-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Example 2.2 : radius of the second bohr\"s orbit \n",
+ " \n",
+ "#given data :\n",
+ "\n",
+ "r1_h=0.529; # radius for hydrozen atom in Angstrum\n",
+ "n1=1;# for the first bohr's orbit of electron in hydrozen atom\n",
+ "Z1=1; # for the first bohr's orbit of electron in hydrozen atom\n",
+ "k=(r1_h*Z1)/n1**2; # where k is constant\n",
+ "n2=2; # for the second bohr orbit\n",
+ "Z2=2; #for the second bohr orbit\n",
+ "r2_he=k*(n2**2/Z2);\n",
+ "print r2_he,\" is radius of the second bohr orbit,r2 in (Angstrom) \"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1.058 is radius of the second bohr orbit,r2 in (Angstrom) \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.3:pg-13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Example 2.3: to prove\n",
+ " \n",
+ "Z=1;#assume\n",
+ "n1=1;#orbit 1\n",
+ "n2=2;#orbit 2\n",
+ "n3=3;#orbit 3\n",
+ "e1=((-13.6*Z)/(n1**2));#energy for the first orbit\n",
+ "e2=((-13.6*Z)/(n2**2));#energy for the second orbit\n",
+ "e3=((-13.6*Z)/(n3**2));#energy for the third orbit\n",
+ "e31=e3-e1;#energy emitted by an electron jumping from orbit nuber 3 to orbit nimber 1\n",
+ "e21=e2-e1;#energy emitted by an electron jumping from orbit nuber 2 to orbit nimber 1\n",
+ "re=e31/e21;#ratio of energy\n",
+ "print re,\" is equal to ratio of energy for an electron to jump from orbit 3 to orbit 1 and from orbit 2 to orbit 1 is 32/27 \\n hence proved\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1.18518518519 is equal to ratio of energy for an electron to jump from orbit 3 to orbit 1 and from orbit 2 to orbit 1 is 32/27 \n",
+ " hence proved\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.4:pg-13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example 2.4 : velocity\n",
+ " \n",
+ "#given data :\n",
+ "\n",
+ "h=6.626*10**-34;\n",
+ "e=1.6*10**-19;\n",
+ "epsilon_o=8.825*10**-12;\n",
+ "n=1;\n",
+ "Z=1;\n",
+ "vn=(Z*e**2)/(2*epsilon_o*n*h);\n",
+ "print vn,\" is velocity,vn in (m/s) \"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2188990.2342 is velocity,vn in (m/s) \n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.5:pg-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example 2.5 : velocity\n",
+ " \n",
+ "#given data :\n",
+ "n=1;\n",
+ "Z=1;\n",
+ "k=6.56*10**15; # k is constant\n",
+ "fn=k*(Z**2/n**3);\n",
+ "print fn,\" is orbital frequency,fn in (Hz) \"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6.56e+15 is orbital frequency,fn in (Hz) \n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.6.a:pg-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example 2.6.a : the energy of the photon emitted\n",
+ " \n",
+ "#given data :\n",
+ "Z=1;#for hydrozen\n",
+ "n1=3;\n",
+ "n2=2;\n",
+ "E3=-(13.6*Z**2)/n1**2;\n",
+ "E2=-(13.6*Z**2)/n2**2;\n",
+ "del_E=E3-E2;\n",
+ "print round(del_E,2),\" is the energy of photon emitted, del_E in (eV) \"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1.89 is the energy of photon emitted, del_E in (eV) \n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.6.b:pg-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example 2.6.b : frequency\n",
+ " \n",
+ "#given data :\n",
+ "\n",
+ "Z=1;#for hydrozen\n",
+ "n1=3;\n",
+ "n2=2;\n",
+ "m=6.626*10**-34;# mass of electron in kg\n",
+ "E3=-(13.6*Z**2)/n1**2;\n",
+ "E2=-(13.6*Z**2)/n2**2;\n",
+ "del_E=E3-E2;\n",
+ "E=del_E*1.6*10**-19;# in joules\n",
+ "v=(E/m);\n",
+ "print round(v,2),\"frequency of the photon emitted,v(Hz) \"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4.5611563873e+14 frequency of the photon emitted,v(Hz) \n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.6.c:pg-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example 2.6.c : wave length of the photon emitted\n",
+ " \n",
+ "#given data :\n",
+ "\n",
+ "Z=1;#for hydrozen\n",
+ "n1=3;\n",
+ "n2=2;\n",
+ "m=6.626*10**-34;# mass of electron in kg\n",
+ "C=3*10**8;\n",
+ "E3=-(13.6*Z**2)/n1**2;\n",
+ "E2=-(13.6*Z**2)/n2**2;\n",
+ "del_E=E3-E2;\n",
+ "E=del_E*1.6*10**-19;\n",
+ "v=E/m;\n",
+ "lamda=C/v;\n",
+ "print round(lamda,9),\" is wavelength of the photon emitted,(m) \"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6.58e-07 is wavelength of the photon emitted,(m) \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/AjayTheetla/Chapter_1.ipynb b/sample_notebooks/AjayTheetla/Chapter_1.ipynb
new file mode 100755
index 00000000..328727e3
--- /dev/null
+++ b/sample_notebooks/AjayTheetla/Chapter_1.ipynb
@@ -0,0 +1,208 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:628a3355094b4b8d081efb2e248a73ea4bad0a7cd7bbbadfae2b2aceebecc70b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1 - Molecular distances"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1 - pg 5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the Angle required\n",
+ "#Initialization of variables\n",
+ "import math\n",
+ "l=0.71 *10**-8 #cm\n",
+ "n=200. #lines/cm\n",
+ "v=0.00145 #radian\n",
+ "#calculations\n",
+ "d=1/n\n",
+ "phi2=2*l/d +v**2\n",
+ "phi=math.sqrt(phi2)\n",
+ "#results\n",
+ "print '%s %.2e %s' %('Angle required =',phi,'radian')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Angle required = 2.22e-03 radian\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2 - pg 6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the Interplanar distance\n",
+ "#Initialization of variables\n",
+ "import math\n",
+ "angle=37.25 #degrees\n",
+ "l=1.539 #A\n",
+ "n=1. #order\n",
+ "#calculations\n",
+ "d=n*l/(2*math.sin(angle/180.*math.pi))\n",
+ "#results\n",
+ "print '%s %.3f %s' %(\"Interplanar distance =\",d,\"A\")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Interplanar distance = 1.271 A\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5 - pg 9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the ratio of radii\n",
+ "#Initialization of variables\n",
+ "import math\n",
+ "r1=math.sqrt(3.)\n",
+ "r2=1\n",
+ "#calculations\n",
+ "ratio=r1-r2\n",
+ "#results\n",
+ "print '%s %.3f' %('Ratio of radii =',ratio)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ratio of radii = 0.732\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6 - pg 10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the Avagadro number\n",
+ "#Initialization of variables\n",
+ "d=2.64 #g/cc\n",
+ "l=4.016*10**-8 #cm\n",
+ "n=4\n",
+ "M=25.94 #g/mol\n",
+ "#calculations\n",
+ "m=d*l**3 /n\n",
+ "N0=M/m\n",
+ "#results\n",
+ "print '%s %.3e %s' %(\"Avagadro number =\",N0,\" molecule/mol\")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Avagadro number = 6.068e+23 molecule/mol\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10 - pg 15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the angle required\n",
+ "#Initialization of variables\n",
+ "import math\n",
+ "import numpy\n",
+ "A=numpy.array([-1, -1, -1 ])\n",
+ "B=numpy.array([1, 1, -1])\n",
+ "#calculations\n",
+ "Ad=math.sqrt(1+1+1)\n",
+ "Bd=math.sqrt(1+1+1)\n",
+ "dot=numpy.dot(A,B) /(Ad*Bd) \n",
+ "theta=math.acos(dot) *180./math.pi\n",
+ "#results\n",
+ "print '%s %.2f %s' %(\"Angle =\",theta,\" degrees\")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Angle = 109.47 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/AjayTheetla/Chapter_1_1.ipynb b/sample_notebooks/AjayTheetla/Chapter_1_1.ipynb
new file mode 100755
index 00000000..328727e3
--- /dev/null
+++ b/sample_notebooks/AjayTheetla/Chapter_1_1.ipynb
@@ -0,0 +1,208 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:628a3355094b4b8d081efb2e248a73ea4bad0a7cd7bbbadfae2b2aceebecc70b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1 - Molecular distances"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1 - pg 5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the Angle required\n",
+ "#Initialization of variables\n",
+ "import math\n",
+ "l=0.71 *10**-8 #cm\n",
+ "n=200. #lines/cm\n",
+ "v=0.00145 #radian\n",
+ "#calculations\n",
+ "d=1/n\n",
+ "phi2=2*l/d +v**2\n",
+ "phi=math.sqrt(phi2)\n",
+ "#results\n",
+ "print '%s %.2e %s' %('Angle required =',phi,'radian')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Angle required = 2.22e-03 radian\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2 - pg 6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the Interplanar distance\n",
+ "#Initialization of variables\n",
+ "import math\n",
+ "angle=37.25 #degrees\n",
+ "l=1.539 #A\n",
+ "n=1. #order\n",
+ "#calculations\n",
+ "d=n*l/(2*math.sin(angle/180.*math.pi))\n",
+ "#results\n",
+ "print '%s %.3f %s' %(\"Interplanar distance =\",d,\"A\")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Interplanar distance = 1.271 A\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5 - pg 9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the ratio of radii\n",
+ "#Initialization of variables\n",
+ "import math\n",
+ "r1=math.sqrt(3.)\n",
+ "r2=1\n",
+ "#calculations\n",
+ "ratio=r1-r2\n",
+ "#results\n",
+ "print '%s %.3f' %('Ratio of radii =',ratio)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ratio of radii = 0.732\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6 - pg 10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the Avagadro number\n",
+ "#Initialization of variables\n",
+ "d=2.64 #g/cc\n",
+ "l=4.016*10**-8 #cm\n",
+ "n=4\n",
+ "M=25.94 #g/mol\n",
+ "#calculations\n",
+ "m=d*l**3 /n\n",
+ "N0=M/m\n",
+ "#results\n",
+ "print '%s %.3e %s' %(\"Avagadro number =\",N0,\" molecule/mol\")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Avagadro number = 6.068e+23 molecule/mol\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10 - pg 15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the angle required\n",
+ "#Initialization of variables\n",
+ "import math\n",
+ "import numpy\n",
+ "A=numpy.array([-1, -1, -1 ])\n",
+ "B=numpy.array([1, 1, -1])\n",
+ "#calculations\n",
+ "Ad=math.sqrt(1+1+1)\n",
+ "Bd=math.sqrt(1+1+1)\n",
+ "dot=numpy.dot(A,B) /(Ad*Bd) \n",
+ "theta=math.acos(dot) *180./math.pi\n",
+ "#results\n",
+ "print '%s %.2f %s' %(\"Angle =\",theta,\" degrees\")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Angle = 109.47 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/AkshayPatil/chapter1.ipynb b/sample_notebooks/AkshayPatil/chapter1.ipynb
new file mode 100755
index 00000000..8411e8ec
--- /dev/null
+++ b/sample_notebooks/AkshayPatil/chapter1.ipynb
@@ -0,0 +1,190 @@
+{
+ "metadata": {
+ "name": "chapter1.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1:Introduction and Basic Concepts"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1-2,Page No:19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable Declaration\n",
+ "UnitCostOfEnergy=0.09 #Unit cost of Energy in $/kWh\n",
+ "TimeInterval=2200 # Time Interval in hours\n",
+ "EnergyperUnitTime=30 # Rated Power kW\n",
+ "\n",
+ "#Calculation\n",
+ "TotalEnergy=EnergyperUnitTime*TimeInterval # Total Energy in kWh\n",
+ " \n",
+ "#Money Saved\n",
+ "MoneySaved=TotalEnergy*UnitCostOfEnergy # Money Saved in $\n",
+ "\n",
+ "#Calculations in Joules\n",
+ "Tot=EnergyperUnitTime*TimeInterval*(3600) #Total Energy in kJ\n",
+ "\n",
+ "#Result\n",
+ "print\"The Total Energy Generated is\",round(TotalEnergy),\"kWh\"\n",
+ "print\"The Total Money Saved is\",round(MoneySaved),\"$\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Total Energy Generated is 66000.0 kWh\n",
+ "The Total Money Saved is 5940.0 $\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1-3,Page No:20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable Decleration\n",
+ "rho=850 #density of oil in kg/m^3\n",
+ "V=2 #Volume of tank in m^3\n",
+ "\n",
+ "#Calculations\n",
+ "#We intend to find m\n",
+ "m=rho*V #mass in the tank in kg\n",
+ "\n",
+ "#Result\n",
+ "print\"The mass in the tank is\", round(m),\"kg\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The mass in the tank is 1700.0 kg\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1-4,Page No:21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable Decleration\n",
+ "m=1 #mass in lbm\n",
+ "g=32.174 #Gravatational Acceleration in ft/s^2\n",
+ "\n",
+ "#Calculations\n",
+ "W=(m*g)*(1/g) #weight in lbf\n",
+ "\n",
+ "#Result\n",
+ "print\"The weight in lbf is \",round(W),\"lbf\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The weight in lbf is 1.0 lbf\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1-6, Page No:30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable Decleration\n",
+ "V=1.1 #Volume of water collected in gal \n",
+ "delt=45.62 # time required in s\n",
+ "gal_conv=3.785*10**-3 #Gal conversion constant\n",
+ "mi=60 #1 minute equals 60 seconds \n",
+ "\n",
+ "#Calculations\n",
+ "V_dot=(V/delt)*(gal_conv/1)*(mi/1) #Volume flow rate in m^3/min\n",
+ "\n",
+ "#Result\n",
+ "print\"The volume flow rate is \",round(V_dot,4), \"m^3/min\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The volume flow rate is 0.0055 m^3/min\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/AkshayPatil/chapter1_1.ipynb b/sample_notebooks/AkshayPatil/chapter1_1.ipynb
new file mode 100755
index 00000000..c989cf92
--- /dev/null
+++ b/sample_notebooks/AkshayPatil/chapter1_1.ipynb
@@ -0,0 +1,190 @@
+{
+ "metadata": {
+ "name": "chapter1.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1:Introduction and Basic Concepts"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.1-2 Page Number 19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable Declaration\n",
+ "UnitCostOfEnergy=0.09 #Unit cost of Energy in $/kWh\n",
+ "TimeInterval=2200 # Time Interval in hours\n",
+ "EnergyperUnitTime=30 # Rated Power kW\n",
+ "\n",
+ "#Calculation\n",
+ "TotalEnergy=EnergyperUnitTime*TimeInterval # Total Energy in kWh\n",
+ " \n",
+ "#Money Saved\n",
+ "MoneySaved=TotalEnergy*UnitCostOfEnergy # Money Saved in $\n",
+ "\n",
+ "#Calculations in Joules\n",
+ "Tot=EnergyperUnitTime*TimeInterval*(3600) #Total Energy in kJ\n",
+ "\n",
+ "#Result\n",
+ "print\"The Total Energy Generated is\",round(TotalEnergy),\"kWh\"\n",
+ "print\"The Total Money Saved is\",round(MoneySaved),\"$\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Total Energy Generated is 66000.0 kWh\n",
+ "The Total Money Saved is 5940.0 $\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.1-3, Page Number 20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable Decleration\n",
+ "rho=850 #density of oil in kg/m^3\n",
+ "V=2 #Volume of tank in m^3\n",
+ "\n",
+ "#Calculations\n",
+ "#We intend to find m\n",
+ "m=rho*V #mass in the tank in kg\n",
+ "\n",
+ "#Result\n",
+ "print\"The mass in the tank is\", round(m),\"kg\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The mass in the tank is 1700.0 kg\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.1-4, Page Number 21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable Decleration\n",
+ "m=1 #mass in lbm\n",
+ "g=32.174 #Gravatational Acceleration in ft/s^2\n",
+ "\n",
+ "#Calculations\n",
+ "W=(m*g)*(1/g) #weight in lbf\n",
+ "\n",
+ "#Result\n",
+ "print\"The weight in lbf is \",round(W),\"lbf\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The weight in lbf is 1.0 lbf\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.1-6, Page Number 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable Decleration\n",
+ "V=1.1 #Volume of water collected in gal \n",
+ "delt=45.62 # time required in s\n",
+ "gal_conv=3.785*10**-3 #Gal conversion constant\n",
+ "mi=60 #1 minute equals 60 seconds \n",
+ "\n",
+ "#Calculations\n",
+ "V_dot=(V/delt)*(gal_conv/1)*(mi/1) #Volume flow rate in m^3/min\n",
+ "\n",
+ "#Result\n",
+ "print\"The volume flow rate is \",round(V_dot,4), \"m^3/min\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The volume flow rate is 0.0055 m^3/min\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/Aman KumarJain/Chapter_6_Objects_and_Classes.ipynb b/sample_notebooks/Aman KumarJain/Chapter_6_Objects_and_Classes.ipynb
new file mode 100755
index 00000000..89a18f99
--- /dev/null
+++ b/sample_notebooks/Aman KumarJain/Chapter_6_Objects_and_Classes.ipynb
@@ -0,0 +1,934 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:bd4e7931ddf89d8dc8befb681e1e57c7a9c742cd8abe8e18a494a55156d56cee"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Objects and Classes"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.1, Page Number: 216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class smallobj: #define a class\n",
+ " \n",
+ " def setdata(self,d): #member function to set class variable somdata\n",
+ " self.__somedata = d\n",
+ " \n",
+ " def showdata(self): #member function to display somedata \n",
+ " print 'Data is ' , self.__somedata\n",
+ "\n",
+ "\n",
+ "#define two objects of class smallobj\n",
+ "s1=smallobj()\n",
+ "s2=smallobj()\n",
+ "\n",
+ "#call member function to set data \n",
+ "s1.setdata(1066)\n",
+ "s2.setdata(1776)\n",
+ "\n",
+ "#call member function to display data \n",
+ "s1.showdata()\n",
+ "s2.showdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Data is 1066\n",
+ "Data is 1776\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.2, Page Number: 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class part: #define class \n",
+ " \n",
+ " def setpart(self,mn,pn,c): #set data\n",
+ " self.__modelnumber = mn\n",
+ " self.__partnumber = pn\n",
+ " self.__cost = c\n",
+ " \n",
+ " def showpart(self): #display data \n",
+ " print 'Model' , self.__modelnumber ,\n",
+ " print ', part' , self.__partnumber , \n",
+ " print ', costs $',self.__cost\n",
+ " \n",
+ "#define object of class part \n",
+ "part1 = part()\n",
+ "\n",
+ "#call member function setpart\n",
+ "part1.setpart(6244,373,217.55)\n",
+ "\n",
+ "#call member function showpart\n",
+ "part1.showpart()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Model 6244 , part 373 , costs $ 217.55\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3, Page Number: 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import * #importing turtles library\n",
+ "\n",
+ "class circle: #defining circle class\n",
+ " \n",
+ " def set(self,x,y,r,fc): #sets circle attribute\n",
+ " self._xCo = x\n",
+ " self._yCo = y\n",
+ " self._radius = r\n",
+ " self._fillcolor = fc\n",
+ " \n",
+ " def draw(self): #draws the circle \n",
+ " setup() #set screen\n",
+ " turtle = Turtle() #object of Turtle class\n",
+ " turtle.begin_fill() #start filling color in circle\n",
+ " turtle.color(self._fillcolor) #color\n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo) #set center of circle\n",
+ " turtle.circle(self._radius) #draw circle of radius self.__radius\n",
+ " turtle.end_fill() #stop filling\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ "\n",
+ "#creating objects of class circle \n",
+ "c1 = circle()\n",
+ "c2 = circle()\n",
+ "c3 = circle()\n",
+ "\n",
+ "#sending the value to set fnction\n",
+ "c1.set(15,7,5,\"blue\")\n",
+ "c2.set(41,12,7,\"red\")\n",
+ "c3.set(65,18,4,\"green\")\n",
+ "\n",
+ "#draw circle\n",
+ "c1.draw()\n",
+ "c2.draw()\n",
+ "c3.draw()\n",
+ "\n",
+ "#In the above example the cirlcle's in the book are constructed using 'X' and 'O' but such feature is not available in Python.\n",
+ "#So i have created a simple circle filled with color"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.4, Page Number: 226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def setdist(self,ft,inc): #set distance to class variables\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get distance from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ "\n",
+ "#define two distance\n",
+ "dist1 = Distance()\n",
+ "dist2 = Distance()\n",
+ "\n",
+ "dist1.setdist(11,6.25) #set dist1\n",
+ "dist2.getdist() #set dist2 from user\n",
+ "\n",
+ "#show distances\n",
+ "print \"dist1 = \",\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:5.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dist1 = 11 ' - 6.25 \"\n",
+ "dist2 = 17 ' - 5.75 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.5, Page Number: 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter:\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__count = 0\n",
+ " \n",
+ " def inc_count(self): #increment count\n",
+ " self.__count = self.__count + 1\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self.__count\n",
+ "\n",
+ "#define and initialize class objects\n",
+ "c1=Counter()\n",
+ "c2=Counter()\n",
+ "\n",
+ "#display count for each object\n",
+ "print 'c1 =',c1.get_count()\n",
+ "print 'c2 =',c2.get_count()\n",
+ "\n",
+ "\n",
+ "c1.inc_count() #increment c1\n",
+ "c2.inc_count() #increment c2\n",
+ "c2.inc_count() #increment c2\n",
+ "\n",
+ "#display count again for each object\n",
+ "print 'c1 =',c1.get_count()\n",
+ "print 'c2 =',c2.get_count()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c2 = 0\n",
+ "c1 = 1\n",
+ "c2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6, Page Number: 231"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import * #importing turtles library\n",
+ "\n",
+ "class circle: #defining circle class\n",
+ " \n",
+ " def __init__(self,x,y,r,fc): #constructor for set circle attribute\n",
+ " self._xCo = x\n",
+ " self._yCo = y\n",
+ " self._radius = r\n",
+ " self._fillcolor = fc\n",
+ " \n",
+ " def draw(self): #draws the circle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " turtle.color(self._fillcolor)\n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.circle(self._radius)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ "\n",
+ "#creating objects of class circle \n",
+ "c1 = circle(15,7,5,\"blue\") \n",
+ "c2 = circle(41,12,7,\"red\")\n",
+ "c3 = circle(65,18,4,\"green\")\n",
+ "\n",
+ "#draw circle\n",
+ "c1.draw()\n",
+ "c2.draw()\n",
+ "c3.draw()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7, Page Number: 233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def add_dist(self,d2,d3): #add length d2 and d3\n",
+ " self.__inches = d2.__inches + d3.__inches #add inches\n",
+ " self.__feet = 0\n",
+ " if self.__inches >= 12.0: #if total exceeds 12.0\n",
+ " self.__inches = self.__inches - 12.0 #then decrease inches by 12.0\n",
+ " self.__feet = self.__feet + 1 #and increase feet by 1\n",
+ " self.__feet = self.__feet + d2.__feet + d3.__feet #add the feet\n",
+ "\n",
+ "#define two length\n",
+ "dist1 = Distance()\n",
+ "dist3 = Distance()\n",
+ "\n",
+ "#define and initialize dist2\n",
+ "dist2 = Distance(11,6.25)\n",
+ "\n",
+ "#get dist1 from user\n",
+ "dist1.getdist()\n",
+ "\n",
+ "#dist3 = dist1 + dist2\n",
+ "dist3.add_dist(dist1,dist2)\n",
+ "\n",
+ "#display all lengths\n",
+ "print 'dist1 = ',\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()\n",
+ "print 'dist3 = ',\n",
+ "dist3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:5.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dist1 = 17 ' - 5.75 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 29 ' - 0.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8, Page Number: 238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #overloaded constructor that takes no arguments or two args or one object(copy constructor)\n",
+ " if isinstance(ft,int):\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " else:\n",
+ " self.__feet = ft.__feet\n",
+ " self.__inches = ft.__inches\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ "\n",
+ "#two argument constructor\n",
+ "dist1 = Distance(11,6.25)\n",
+ "\n",
+ "#one argument(object) constructor explicitly pass\n",
+ "dist2 = Distance(dist1)\n",
+ "\n",
+ "#also one argument(object) constructor implicitly pass\n",
+ "dist3 = dist1\n",
+ "\n",
+ "#display all lengths\n",
+ "print 'dist1 = ',\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()\n",
+ "print 'dist3 = ',\n",
+ "dist3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dist1 = 11 ' - 6.25 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 11 ' - 6.25 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.9, Page Number: 240"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def add_dist(self,d2): #add this length to d2 and return object\n",
+ " temp = Distance() #temporary object\n",
+ " temp.__inches = self.__inches + d2.__inches\n",
+ " if temp.__inches >= 12.0:\n",
+ " temp.__inches = temp.__inches - 12.0\n",
+ " temp.__feet = 1\n",
+ " temp.__feet = temp.__feet + self.__feet + d2.__feet\n",
+ " return temp #return sum as object\n",
+ "\n",
+ "#define two length\n",
+ "dist1 = Distance()\n",
+ "dist3 = Distance()\n",
+ "\n",
+ "#define and initialize dist2\n",
+ "dist2 = Distance(11,6.25)\n",
+ "\n",
+ "#get dist1 from user\n",
+ "dist1.getdist()\n",
+ "\n",
+ "#dist3 = dist1 + dist2\n",
+ "dist3 = dist1.add_dist(dist2)\n",
+ "\n",
+ "#display all lengths\n",
+ "print 'dist1 = ',\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()\n",
+ "print 'dist3 = ',\n",
+ "dist3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:5.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dist1 = 17 ' - 5.75 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 29 ' - 0.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.10, Page Number: 243"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Suit = [\"clubs\",\"diamonds\",\"hearts\",\"spades\"] \n",
+ "\n",
+ "(clubs,diamonds,hearts,spades) = (0,1,2,3) #Atteching the names with number \n",
+ "\n",
+ "\n",
+ "#from 2 to 10 are integers without names\n",
+ "jack = 11 \n",
+ "queen = 12 \n",
+ "king = 13\n",
+ "ace = 14\n",
+ "\n",
+ "\n",
+ "class card: \n",
+ " \n",
+ " def __init__(self,n=None,s=None): #constructor\n",
+ " self.__number = n #2 to 10, jack, queen, king, ace\n",
+ " self.__suit = s #clubs, diamonds, hearts, spades\n",
+ " \n",
+ " def display(self): #display the cards\n",
+ " \n",
+ " if self.__number >= 2 and self.__number<=10:\n",
+ " print self.__number , 'of',\n",
+ " \n",
+ " else:\n",
+ " if self.__number == jack:\n",
+ " print 'jack of',\n",
+ " elif self.__number == queen:\n",
+ " print 'queen of',\n",
+ " elif self.__number == king:\n",
+ " print 'king of',\n",
+ " else:\n",
+ " print 'ace of',\n",
+ " \n",
+ " if self.__suit == clubs:\n",
+ " print 'clubs'\n",
+ " elif self.__suit == diamonds:\n",
+ " print 'diamonds'\n",
+ " elif self.__suit == hearts:\n",
+ " print 'hearts'\n",
+ " else:\n",
+ " print 'spades'\n",
+ " \n",
+ " def isEqual(self,c2): #return 1 if cards equal\n",
+ " \n",
+ " if self.__number == c2.__number and self.__suit == c2.__suit:\n",
+ " return 1\n",
+ " else:\n",
+ " return 0\n",
+ "\n",
+ "\n",
+ "#define various cards\n",
+ "temp = card()\n",
+ "chosen = card()\n",
+ "prize = card()\n",
+ "\n",
+ "\n",
+ "#define and initialize card1\n",
+ "card1 = card(7,clubs)\n",
+ "print 'card 1 is the',\n",
+ "card1.display() #display card1\n",
+ "\n",
+ "#define and initialize card2\n",
+ "card2 = card(jack,hearts)\n",
+ "print 'card 2 is the',\n",
+ "card2.display() #display card2\n",
+ "\n",
+ "#define and initialize card3\n",
+ "card3 = card(ace,spades)\n",
+ "print 'card 3 is the',\n",
+ "card3.display() #display card3\n",
+ "\n",
+ "\n",
+ "#prize is the card to guess\n",
+ "prize = card3\n",
+ "\n",
+ "\n",
+ "#swapping cards\n",
+ "print 'I\\'m swapping card 1 and card 3'\n",
+ "temp = card3\n",
+ "card3 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 2 and card 3'\n",
+ "temp = card2\n",
+ "card3 = card2\n",
+ "card2 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 1 and card 2'\n",
+ "temp = card2\n",
+ "card2 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "print 'Now, where (1,2, or 3) is the',\n",
+ "prize.display() #display prize\n",
+ "print '?'\n",
+ "\n",
+ "position = input() #get user's guess of position\n",
+ "\n",
+ "\n",
+ "#set chosen to user's choice \n",
+ "if position == 1:\n",
+ " chosen = card1\n",
+ "elif position == 2:\n",
+ " chosen = card2\n",
+ "else:\n",
+ " chosen = card3\n",
+ "\n",
+ "#is chosen card the prize?\n",
+ "\n",
+ "x=chosen.isEqual(prize)\n",
+ "\n",
+ "if x==1:\n",
+ " print 'That\\'s right! You win!'\n",
+ "else:\n",
+ " print 'Sorry. You lose.'\n",
+ "\n",
+ "print 'You choose the',\n",
+ "\n",
+ "#display chosen card\n",
+ "chosen.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "card 1 is the 7 of clubs\n",
+ "card 2 is the jack of hearts\n",
+ "card 3 is the ace of spades\n",
+ "I'm swapping card 1 and card 3\n",
+ "I'm swapping card 2 and card 3\n",
+ "I'm swapping card 1 and card 2\n",
+ "Now, where (1,2, or 3) is the ace of spades\n",
+ "?\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "That's right! You win!\n",
+ "You choose the ace of spades\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.11, Page Number: 249"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class foo: \n",
+ " \n",
+ " __count = 0 #only one data item for all objects\n",
+ " \n",
+ " def __init__(self):\n",
+ " foo.__count = foo.__count + 1 #increment count when object created\n",
+ " \n",
+ " def getcount(self): #returns count\n",
+ " return foo.__count\n",
+ "\n",
+ "#create three objecs\n",
+ "f1 = foo()\n",
+ "f2 = foo()\n",
+ "f3 = foo()\n",
+ "\n",
+ "#Each object displays the same count value\n",
+ "print 'count is', f1.getcount()\n",
+ "print 'count is', f2.getcount()\n",
+ "print 'count is', f3.getcount()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "count is 3\n",
+ "count is 3\n",
+ "count is 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.12, Page Number: 253"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0.0): #constructor \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ "\n",
+ "#There's no const keyword \n",
+ " \n",
+ " def add_dist(self,d2): #add this length to d2 and return object\n",
+ " \n",
+ " temp = Distance()\n",
+ " temp.__inches = self.__inches + d2.__inches\n",
+ " \n",
+ " if temp.__inches >= 12.0:\n",
+ " temp.__inches = temp.__inches - 12.0\n",
+ " temp.__feet = 1\n",
+ " \n",
+ " temp.__feet = temp.__feet + self.__feet + d2.__feet\n",
+ " \n",
+ " return temp #return sum as object\n",
+ " \n",
+ "dist1 = Distance()\n",
+ "dist3 = Distance()\n",
+ "dist2 = Distance(11,6.25)\n",
+ "\n",
+ "dist1.getdist()\n",
+ "\n",
+ "dist3 = dist1.add_dist(dist2)\n",
+ "\n",
+ "print 'dist1 = ',\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()\n",
+ "print 'dist3 = ',\n",
+ "dist3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:5.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dist1 = 17 ' - 5.75 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 29 ' - 0.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.13, Page Number: 255"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance:\n",
+ " \n",
+ " def __init__(self,ft,inc):\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self):\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self):\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ "\n",
+ "football = Distance(300,0)\n",
+ "\n",
+ "print 'football = ',\n",
+ "football.showdist()\n",
+ "\n",
+ "#There's no const keyword in python"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "football = 300 ' - 0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/ApurvaBhushan/Chapter_3.ipynb b/sample_notebooks/ApurvaBhushan/Chapter_3.ipynb
new file mode 100755
index 00000000..777522bb
--- /dev/null
+++ b/sample_notebooks/ApurvaBhushan/Chapter_3.ipynb
@@ -0,0 +1,195 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 3: Elements of the Theory of Plasticity"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Example 3.1, True Stress and True Strain, Page No. 76"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Engineering Stress at maximum load = 99852.1 psi\n",
+ "True Fracture Stress = 112785 psi\n",
+ "True Strain at fracture = 0.344939\n",
+ "Engineering strain at fracture = 0.411903\n"
+ ]
+ }
+ ],
+ "source": [
+ "from math import pi\n",
+ "from math import log\n",
+ "from math import exp\n",
+ "\n",
+ "#variable declaration\n",
+ "D_i=0.505;\n",
+ "L=2;\n",
+ "P_max=20000;\n",
+ "P_f=16000;\n",
+ "D_f=0.425;\n",
+ "\n",
+ "#calculation\n",
+ "E_St= P_max*4/(pi*D_i**2);\n",
+ "T_fr_St= P_f*4/(pi*D_f**2);\n",
+ "e_f=log(D_i**2/D_f**2);\n",
+ "e=exp(e_f)-1;\n",
+ "\n",
+ "#result\n",
+ "print('\\nEngineering Stress at maximum load = %g psi\\nTrue Fracture Stress = %g psi\\nTrue Strain at fracture = %g\\nEngineering strain at fracture = %g')%(E_St,T_fr_St,e_f,e);\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Example 3.2, Yielding Criteria for Ductile Metals, Page No. 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "\n",
+ "\n",
+ "from math import sqrt\n",
+ "\n",
+ "#variable declaration\n",
+ "sigma00=500;\n",
+ "sigma_z=-50;\n",
+ "sigma_y=100;\n",
+ "sigma_x=200;\n",
+ "T_xy=30;\n",
+ "T_yz=0;\n",
+ "T_xz=0;\n",
+ "\n",
+ "#calculation\n",
+ "sigma0=sqrt((sigma_x-sigma_y)**2+(sigma_y-sigma_z)**2+(sigma_z-sigma_x)**2+6*(T_xy**2+T_yz**2+T_xz**2))/sqrt(2);\n",
+ "s=sigma00/sigma0;\n",
+ "\n",
+ "#result\n",
+ "print('\\nSince the calculated value of sigma0 = %g MPa, which is less than the yield strength of the aluminium alloy\\nThus safety factor is = %g')%(sigma0,s);\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Example 3.3, Tresca Criterion, Page No. 81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "\n",
+ "\n",
+ "#variable declaration\n",
+ "sigma00=500;\n",
+ "sigma_z=-50;\n",
+ "sigma_y=100;\n",
+ "sigma_x=200;\n",
+ "T_xy=30;\n",
+ "T_yz=0;\n",
+ "T_xz=0;\n",
+ "\n",
+ "#calculation\n",
+ "sigma0=sigma_x-sigma_z;\n",
+ "s=sigma00/sigma0;\n",
+ "\n",
+ "#result\n",
+ "print('\\nSince the calculated value of sigma0 = %g MPa, which is less than the yield strength of the aluminium alloy\\nThus safety factor is = %g')%(sigma0,s);\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "Example 3.4, Levy-Mises Equation, Page No. 91"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Plastic Strain = 0.199532\n"
+ ]
+ }
+ ],
+ "source": [
+ "from math import sqrt\n",
+ "\n",
+ "#variable declaration\n",
+ "r_t=20;\n",
+ "p=1000;\n",
+ "\n",
+ "#calculation\n",
+ "sigma1=p*r_t;\n",
+ "sigma1=sigma1/1000; #conversion to ksi\n",
+ "sigma=sqrt(3)*sigma1/2;\n",
+ "e=(sigma/25)**(1/0.25);\n",
+ "e1=sqrt(3)*e/2;\n",
+ "\n",
+ "#result\n",
+ "print('\\nPlastic Strain = %g')%(e1);\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
+}
diff --git a/sample_notebooks/ArchanaDharmasagar Kalidas/chapter3.ipynb b/sample_notebooks/ArchanaDharmasagar Kalidas/chapter3.ipynb
new file mode 100755
index 00000000..0ace7f2d
--- /dev/null
+++ b/sample_notebooks/ArchanaDharmasagar Kalidas/chapter3.ipynb
@@ -0,0 +1,560 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c2cfd770b64ff6a5a34b3865d707320d0a14506274eb94013c7282c3c39c74ee"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "3 : Mechanics of rigid body"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1, Page number A 3.32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#import modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#given data\n",
+ "t = 20 # tow is given in N-m\n",
+ "k = 0.5 # radius of gyration is given in meters\n",
+ "m = 10 # mass is given in Kgs\n",
+ "# alpha = ? alpha is angular acceleration\n",
+ "#alpha = tow / (((gyration)**2) * mass)\n",
+ "\n",
+ "#calculation\n",
+ "alpha = t / ((k**2) * m)\n",
+ "\n",
+ "#result\n",
+ "print \"the angular acceleration is\", alpha ,\"rad /(sec**2)\"\n",
+ "print \"answer given in the book is wrong\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the angular acceleration is 8.0 rad /(sec**2)\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2, Page number A 3.32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#import modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#given data\n",
+ "pi = 22/7\n",
+ "m = 6 * 10**24 # mass is given in kgs\n",
+ "r = 6.4 * 10**6 # radius is given in meters \n",
+ "r1 = 1.5 * 10**11 # orbital radius in meters\n",
+ "t = 24*60*60 # number of seconds in a day\n",
+ "T = 365*24*60*60 # number of seconds in a year\n",
+ "\n",
+ "I = (2/5) * m * r**2 # inertia in kg-m**2\n",
+ "I1 = m * r1**2 # inertia in kg-m**2\n",
+ "omega = (2* pi) / t # angular velocity in rad / sec\n",
+ "omega1 = (2* pi) / T\n",
+ "\n",
+ "#calculation\n",
+ "L = I * omega # spin angular momentum (Kg -m**2) / sec\n",
+ "L1 = I1 * omega1 # Orbital angular momentum ((Kg -m**2) / sec)\n",
+ "\n",
+ "#Result\n",
+ "print \"the spin angular momentum is \", round(L/10**33,3), \"*10**33 Kg m**2 / sec\"\n",
+ "print \"answer varies due to rounding off errors\"\n",
+ "print \"the spin angular momentum is \", round(L1/10**40,2), \"*10**40 Kg m**2 / sec\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the spin angular momentum is 7.152 *10**33 Kg m**2 / sec\n",
+ "answer varies due to rounding off errors\n",
+ "the spin angular momentum is 2.69 *10**40 Kg m**2 / sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4, Page number A 3.33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#import modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#given data\n",
+ "m = 0.1 # mass is converted into kgs from grams\n",
+ "d = 0.01 # diameter is given in meters\n",
+ "r = d/2 # radius is half of diameter\n",
+ "v = 0.05 # velocity is given in m / s\n",
+ "\n",
+ "I = (2/5) * m *r**2 # inertia is given in Kg - m**2\n",
+ "omega = v/r # angular velocity is given in rad/sec\n",
+ "\n",
+ "#calculation\n",
+ "KE = (1/2)* I * omega**2 # kinetic energy is given in joules\n",
+ "\n",
+ "#Result\n",
+ "print \"the kinetic energy of the sphere is\", round(KE*10**5), \"*10**-5 j\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the kinetic energy of the sphere is 5.0 *10**-5 j\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 5, Page number A 3.34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#import modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#given data\n",
+ "d = .02 # diameter is converted to meters from centimeters\n",
+ "r = d/2 # radius is half of diameter\n",
+ "I = 2 * 10**(-6) # inertia is given in kg - mtr**2\n",
+ "v = .05 # velocity is converted into mtrs/sec from cms / sec\n",
+ "omega = v/r # omega is angular velocity in rad / sec\n",
+ "\n",
+ "#calculation\n",
+ "KE = (1/2) * I * omega**2 # kinetic energy is calculated in joules\n",
+ "\n",
+ "#Result \n",
+ "print \"the kinetic energy calculated is\" ,KE*10**6, \"*10**-6 j\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the kinetic energy calculated is 25.0 *10**-6 j\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 6, Page number A 3.34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#import modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#given data\n",
+ "m = 100 # mass is given in Kgs\n",
+ "r = 1 # radius is given in meters\n",
+ "n = 120 # number of rotations is equall to 120 rotations per minute\n",
+ "pi = 3.14\n",
+ "t = 60 # time t is given in seconds as the rotations are given according to minute\n",
+ "\n",
+ "#calculation\n",
+ "I = (1/2) * m * r**2 # inertia is calculated in Kg - mtr**2\n",
+ "omega = (2*pi*n)/t # omega is angular velocity\n",
+ "\n",
+ "KE = (1/2) * I * omega**2 # kinetic energy is calculated in joules\n",
+ "\n",
+ "#Result\n",
+ "print \"the kinetic energy is \", round(KE), \"j\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the kinetic energy is 3944.0 j\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 8, Page number A 3.35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#import modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#given data\n",
+ "f = 40 # frequency is given in revolutions per sec\n",
+ "b = 0.1 # base is given in cetimeters which is converted into meters\n",
+ "# inertia (I) is given as (3/10)* m * r**2\n",
+ "\n",
+ "# omega = (m*g*r)/L\n",
+ "\n",
+ "#Calculation\n",
+ "omega = (10*9.8*20*10**(-2))/(4*25*10**(-4) * 6.28 * 40) # angular velocity is cal in rad /sec\n",
+ "\n",
+ "#reuslt\n",
+ "print \"the angular velocity\", round(omega,4), \"rad/sec\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the angular velocity 7.8025 rad/sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 9, Page number A 3.36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#import modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#given data\n",
+ "m = 1.5 # mass is given in Kgs\n",
+ "k = 0.3 # radius of gyration is given in mtrs\n",
+ "n = 240 # number of revolutions per miute\n",
+ "t = 60 # time is taken in seconds as the revolutioni is given per minute\n",
+ "L = 0.1 # pivoted point length is given in meters\n",
+ "g = 9.8 # gravitational constant is 9.8 mtrs/sec**2\n",
+ "\n",
+ "#calculation\n",
+ "omega = (2*pi*n) / t # omega is calculated in rad /sec\n",
+ "\n",
+ "omegap = (g * L) / (k**2 *omega)\n",
+ "\n",
+ "#result\n",
+ "print \"the precessional speed of the wheel is\", round(omegap,2), \"red / sec\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the precessional speed of the wheel is 0.43 red / sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 10, Page number A 3.36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#import modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#given data\n",
+ "m = 1 # mass is given in kgs\n",
+ "r = 0.1 # radius is given in meters\n",
+ "omega = 20 * 3.14 # omega(angular velocity) is given in rad/ sec\n",
+ "I = (1/2)*m*r**2 # inertia is calcuated in kg - m**2\n",
+ "\n",
+ "#calculation\n",
+ "\n",
+ "L= I* omega #L agular momentum is calculated in m**2 / sec\n",
+ "KE = (1/2) * I * (omega**2) # kineticc energy is calculated in joules\n",
+ "\n",
+ "#result\n",
+ "print \"the angular momentum is\", L, \"m**2 / sec\"\n",
+ "print \"the kinetic energy is\", KE, \"j\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the angular momentum is 0.314 m**2 / sec\n",
+ "the kinetic energy is 9.8596 j\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 12, Page number A 3.38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#import modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#given data\n",
+ "m = 0.2 # mass is given in kgs\n",
+ "r = 0.5 # radius is given in meters\n",
+ "a = 0.2 # rate of change of velocity is acceleration which ig given in mtr / sec**2\n",
+ "\n",
+ "# calculation\n",
+ "\n",
+ "# tow is rate of change of angular momentum\n",
+ "# L = m* v * r\n",
+ "# by differentiating L we have to differentiate v that is velocity which gives us acceleration a \n",
+ "\n",
+ "t = m * r * a # tow is calculated in N/m\n",
+ "\n",
+ "#Result\n",
+ "print \"the torque acting is\",t , \"N - m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the torque acting is 0.02 N - m\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 13, Page number A 3.38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#import modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#given data\n",
+ "m = 2 # mass is given in kgs\n",
+ "r = 0.5 # radius is given in meters\n",
+ "v = 24*1000/(60*60) # velocity is given in Km / hr which is cinverted into mtrs / sec\n",
+ "t = 0.1 # time is given in sec\n",
+ "omega = v/r # angular velocity is calc in rad/sec\n",
+ "theta = 1 # angular change\n",
+ "\n",
+ "# calculation\n",
+ "L = m * r**2 * omega # angular momentum Kg -m**2/sec\n",
+ "#t = d/dt(L)\n",
+ "t= L * theta/t # torque in N -m\n",
+ "\n",
+ "#result\n",
+ "print \"the angular momentum\",round(L,3),\"in KG - m**2/sec\"\n",
+ "print \"the torque required is\",round(t,2),\"N - m\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the angular momentum 6.667 in KG - m**2/sec\n",
+ "the torque required is 66.67 N - m\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 14, Page number A 3.38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#import modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#given data\n",
+ "KE = 80 # kinetic energy is calculated in joules\n",
+ "I = 8 * 10 **(-7) # inertia is given in kg-m**2\n",
+ "\n",
+ "# calculation\n",
+ "L = (2* I * KE)**(0.5) # the angular momentum is given in Kg -m**2/sec\n",
+ "\n",
+ "# result\n",
+ "print \"the angular momentum is\", round(L*10**2,2) , \"*10**-2 Kg - m**2/sec\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the angular momentum is 1.13 *10**-2 Kg - m**2/sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 15, Page number A 3.39\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#import modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#given data\n",
+ "n = 30 # numb of revolution is given in rev / sec\n",
+ "t = 1 # time t is in seconds\n",
+ "theta = 30 # angle theta is 30 degrees\n",
+ "m = 0.5 # mass is given in Kgs \n",
+ "I = 5 * 10**-4 # rotational inertia is given in Kg -m**2\n",
+ "l = 0.04 # length pivoted from the center of mass is given in cms which is converted into meters\n",
+ "pi= 3.14\n",
+ "g = 9.8 # gravitational const is given in m/sec**2\n",
+ "\n",
+ "#calculation\n",
+ "omega = (2*pi*n)/t # angular velocity is calculated in rad/ sec\n",
+ "omegap = (m*g*l)/(I* omega) # angular velocity of precession is calculated in rad/ sec\n",
+ "\n",
+ "#Result\n",
+ "print \"the angular velocity of precession is\",round(omegap,2),\"rad/sec\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the angular velocity of precession is 2.08 rad/sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/AvinashReddy/Chapter6.ipynb b/sample_notebooks/AvinashReddy/Chapter6.ipynb
new file mode 100755
index 00000000..50287885
--- /dev/null
+++ b/sample_notebooks/AvinashReddy/Chapter6.ipynb
@@ -0,0 +1,424 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:bd93f1663667ee07f8c4bdf99d82cf6a60f9abb18ce0de8906898bec0afa103e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6 - Optical Sources"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3.1 :Pg 6.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# variable initialisation\n",
+ "x=0.07\n",
+ "\n",
+ "# calculations\n",
+ "Eg=1.424+1.266*x+0.266*math.pow(x,2)\n",
+ "lamda=1.24/Eg # computing wavelength\n",
+ "\n",
+ "# Results\n",
+ "print '%s %.3f %s' %(\"\\nWavlength is \",lamda,\"micrometer \")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Wavlength is 0.819 micrometer \n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3.2 : Pg 6.12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable initialisation\n",
+ "n=1.7 #refractive index\n",
+ "L=5*pow(10,-2) #distance between mirror\n",
+ "c=3*pow(10,8) #speed of light\n",
+ "lamda=0.45*pow(10,-6) #wavelength\n",
+ "\n",
+ "# Calculations\n",
+ "k=2*n*L/lamda #computing number of modes\n",
+ "delf=c/(2*n*L) #computing mode separation\n",
+ "delf=delf*pow(10,-9)\n",
+ "\n",
+ "# Results\n",
+ "print '%s %.2e %s %.2f %s'%(\"\\nNumber of modes are \",k,\"\\nFrequency separation is \",delf,\" GHz.\")\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Number of modes are 3.78e+05 \n",
+ "Frequency separation is 1.76 GHz.\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.21.1 : Pg 6.59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable initialisation\n",
+ "tr=50.0 #radiative recombination lifetime\n",
+ "tnr=85.0 #non-radiative recombination lifetime\n",
+ "h=6.624*pow(10,-34) #plank's constant\n",
+ "c=3*pow(10,8) #speed of light\n",
+ "q=1.6*pow(10,-19) #charge of electron\n",
+ "i=35*pow(10,-3) #current\n",
+ "lamda=0.85*pow(10,-6) #wavelength\n",
+ "\n",
+ "# Calculations\n",
+ "t=tr*tnr/(tr+tnr) #computing total recombination time\n",
+ "eta=t/tr #computing internal quantum efficiency\n",
+ "Pint=eta*h*c*i/(q*lamda) #computing internally generated power\n",
+ "Pint=Pint*pow(10,3)\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print '%s %.2f %s %.3f %s %.1f %s' %(\"\\nTotal recombinaiton time is \",t,\" ns.\\nInternal quantum efficiency is \",eta,\".\\nInternally generated power is \",Pint,\" mW.\")\n",
+ "\n",
+ "#answer in the book for Internal quantum efficiency is 0.629, deviation of 0.001.\n",
+ "#answer in the book for Internally generated power is 32.16 mW, deviation of 0.04 mW.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total recombinaiton time is 31.48 ns.\n",
+ "Internal quantum efficiency is 0.630 .\n",
+ "Internally generated power is 32.2 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.21.2 : Pg 6.59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable initialisation\n",
+ "tr=30.0 #radiative recombination lifetime\n",
+ "tnr=100.0 #non-radiative recombination lifetime\n",
+ "h=6.624*pow(10,-34) #plank's constant\n",
+ "c=3*pow(10,8) #speed of light\n",
+ "q=1.6*pow(10,-19) #charge of electron\n",
+ "i=40*pow(10,-3) #current\n",
+ "lamda=1310*pow(10,-9) #wavelength\n",
+ "\n",
+ "# Calculations\n",
+ "t=tr*tnr/(tr+tnr) #computing total recombination time\n",
+ "eta=t/tr #computing internal quantum efficiency\n",
+ "Pint=eta*h*c*i/(q*lamda) #computing internally generated power\n",
+ "Pint=Pint*pow(10,3)\n",
+ "\n",
+ "print '%s %.2f %s %.3f %s %.2f %s' %(\"\\nTotal recombinaiton time is \",t,\" ns.\\nInternal quantum efficiency is \",eta,\".\\nInternally generated power is \",Pint,\" mW.\")\n",
+ "\n",
+ "#answer in the book for Total recombinaiton time is 23.07 ns, deviation of 0.01ns.\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total recombinaiton time is 23.08 ns.\n",
+ "Internal quantum efficiency is 0.769 .\n",
+ "Internally generated power is 29.17 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.21.3 : Pg 6.60"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Example 6.21.3 page 6.60\n",
+ "\n",
+ "import math\n",
+ "# Variable initialisation\n",
+ "\n",
+ "tr=50.0 #radiative recombination lifetime\n",
+ "tnr=110.0 #non-radiative recombination lifetime\n",
+ "h=6.624*pow(10,-34) #plank's constant\n",
+ "c=3*pow(10,8) #speed of light\n",
+ "q=1.6*pow(10,-19) #charge of electron\n",
+ "i=40*pow(10,-3) #current\n",
+ "lamda=0.87*pow(10,-6) #wavelength\n",
+ "\n",
+ "# Calculations\n",
+ "t=tr*tnr/(tr+tnr) #computing total recombination time\n",
+ "eta=t/tr #computing internal quantum efficiency\n",
+ "Pint=eta*h*c*i/(q*lamda) #computing internally generated power\n",
+ "Pint=Pint*pow(10,3)\n",
+ "\n",
+ "print '%s %.2f %s %.4f %s %.2f %s' %(\"\\nTotal recombinaiton time is \",t,\"ns.\\nInternal quantum efficiency is \",eta,\".\\nInternally generated power is \",Pint,\"mW.\")\n",
+ "\n",
+ "#answers in the book with slight deviaitons\n",
+ "#Total recombinaiton time is 34.37 ns, deviation of 0.01ns.\n",
+ "#Internal quantum efficiency is 0.6874, deviaiton of 0.0001.\n",
+ "#Internally generated power is 39.24 mW, deviation of 0.02mW.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total recombinaiton time is 34.38 ns.\n",
+ "Internal quantum efficiency is 0.6875 .\n",
+ "Internally generated power is 39.26 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.22.1 : Pg 6.68"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable initialisation\n",
+ "f1=10*pow(10,6) #frequency\n",
+ "f2=100*pow(10,6)\n",
+ "t=4*pow(10,-9)\n",
+ "Pdc=280*pow(10,-6) #optincal output power\n",
+ "\n",
+ "# Calculations\n",
+ "w1=2*math.pi*f1 #computing omega\n",
+ "Pout1=Pdc*pow(10,6)/(math.sqrt(1+pow((w1*t),2))) #computing output power\n",
+ "\n",
+ "w2=2*math.pi*f2 #computing omega\n",
+ "Pout2=Pdc*pow(10,6)/(math.sqrt(1+pow((w2*t),2))) #computing output power\n",
+ "\n",
+ "print '%s %.2f %s %.2f %s' %(\"Ouput power at 10 MHz is \",Pout1,\"microwatt.\\nOuput power at 100 MHz is \",Pout2,\"microwatt.\\nConclusion when device is drive at higher frequency the optical power reduces.\\nNOTE - calculation error. In the book square term in the denominator is not taken.\")\n",
+ "BWopt = math.sqrt(3)/(2*math.pi*t)\n",
+ "BWelec = BWopt/math.sqrt(2)\n",
+ "BWopt=BWopt*pow(10,-6)\n",
+ "BWelec=BWelec*pow(10,-6)\n",
+ "\n",
+ "print '%s %.2f %s %.2f %s' %(\"\\n3 dB optical power is \",BWopt,\" MHz.\\n3 dB electrical power is \",BWelec,\" MHz.\")\n",
+ "\n",
+ "\n",
+ "#calculation error. In the book square term in the denominater is not taken.\n",
+ "#answers in the book - \n",
+ "#Ouput power at 10 MHz is 228.7 microwatt.(incorrect)\n",
+ "#Ouput power at 100 MHz is 175 microwatt.(incorrect)\n",
+ "#3 dB optical power is 68.8 MHz, deviation of 0.12\n",
+ "#3 dB electrical power is 48.79 MHz, deviation of 0.06 \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ouput power at 10 MHz is 271.55 microwatt.\n",
+ "Ouput power at 100 MHz is 103.52 microwatt.\n",
+ "Conclusion when device is drive at higher frequency the optical power reduces.\n",
+ "NOTE - calculation error. In the book square term in the denominator is not taken.\n",
+ "\n",
+ "3 dB optical power is 68.92 MHz.\n",
+ "3 dB electrical power is 48.73 MHz.\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.22.2 : Pg 6.69"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable initialisation\n",
+ "n1=3.5 #refractive index\n",
+ "n=1 #refractive index of air\n",
+ "F=0.69 #transmission factor\n",
+ "\n",
+ "# Calculations\n",
+ "eta = 100*pow((n1*pow((n1+1),2)),-1) #computing eta\n",
+ "\n",
+ "# Results\n",
+ "print '%s %.1f %s' %(\"\\neta external is \",eta,\" percent i.e. small fraction of intrnally generated opticalpower is emitted from the device.\")\n",
+ "print \"\\n\\n OR we can also arrive at solution,\\n\" \n",
+ "\n",
+ "r= 100*F*pow(n,2)/(4*pow(n1,2)) #computing ratio of Popt/Pint\n",
+ "\n",
+ "print '%s %.1f %s' %(\"\\n Popt/Pint is \",r,\"percent\")\n",
+ "\n",
+ "print \"\\nNOTE - printing mistake at final answer.\\nThey have printed 40 percent it should be 1.4 percent\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "eta external is 1.4 percent i.e. small fraction of intrnally generated opticalpower is emitted from the device.\n",
+ "\n",
+ "\n",
+ " OR we can also arrive at solution,\n",
+ "\n",
+ "\n",
+ " Popt/Pint is 1.4 percent\n",
+ "\n",
+ "NOTE - printing mistake at final answer.\n",
+ "They have printed 40 percent it should be 1.4 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.22.3 : Pg 6.73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable initialisation\n",
+ "beta0=1.85*pow(10,7)\n",
+ "T=293 #temperature\n",
+ "k=1.38*pow(10,-23) #Boltzman constant\n",
+ "Ea=0.9*1.6*pow(10,-19)\n",
+ "theta=0.65 #threshold\n",
+ "\n",
+ "# Calculations\n",
+ "betar=beta0*pow(math.e,(-Ea/(k*T)))\n",
+ "t=-math.log(theta)/betar\n",
+ "\n",
+ "# Result\n",
+ "print '%s %.2e %s %.1e %s' %(\"\\nDegradation rate is \",betar,\" per hour.\\nOperating lifetime is \",t,\" hour.\")\n",
+ "\n",
+ "#answer in the book for Degradation rate is 6.4e-09 per hour, deviation of 0.08e-9\n",
+ "#answer in the book for Operating lifetime is 6.7e+07 hour, deviaiton of 0.1e1\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Degradation rate is 6.32e-09 per hour.\n",
+ "Operating lifetime is 6.8e+07 hour.\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/AvinashReddy/Chapter6_1.ipynb b/sample_notebooks/AvinashReddy/Chapter6_1.ipynb
new file mode 100755
index 00000000..cb976487
--- /dev/null
+++ b/sample_notebooks/AvinashReddy/Chapter6_1.ipynb
@@ -0,0 +1,424 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:a9319dae2c5d735f752461f1c0fd8a354f31bcf1559eeff72f9ee135bfdbd607"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6 - Optical Sources"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3.1 :Pg 6.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# variable initialisation\n",
+ "x=0.07\n",
+ "\n",
+ "# calculations\n",
+ "Eg=1.424+1.266*x+0.266*math.pow(x,2)\n",
+ "lamda=1.24/Eg # computing wavelength\n",
+ "\n",
+ "# Results\n",
+ "print '%s %.3f %s' %(\"\\nWavlength is \",lamda,\"micrometer \")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Wavlength is 0.819 micrometer \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3.2 : Pg 6.12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable initialisation\n",
+ "n=1.7 #refractive index\n",
+ "L=5*math.pow(10,-2) #distance between mirror\n",
+ "c=3*math.pow(10,8) #speed of light\n",
+ "lamda=0.45*math.pow(10,-6) #wavelength\n",
+ "\n",
+ "# Calculations\n",
+ "k=2*n*L/lamda #computing number of modes\n",
+ "delf=c/(2*n*L) #computing mode separation\n",
+ "delf=delf*math.pow(10,-9)\n",
+ "\n",
+ "# Results\n",
+ "print '%s %.2e %s %.2f %s' %(\"\\nNumber of modes are \",k,\"\\nFrequency separation is \",delf,\" GHz.\")\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Number of modes are 3.78e+05 \n",
+ "Frequency separation is 1.76 GHz.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.21.1 : Pg 6.59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable initialisation\n",
+ "tr=50.0 #radiative recombination lifetime\n",
+ "tnr=85.0 #non-radiative recombination lifetime\n",
+ "h=6.624*math.pow(10,-34) #plank's constant\n",
+ "c=3*math.pow(10,8) #speed of light\n",
+ "q=1.6*math.pow(10,-19) #charge of electron\n",
+ "i=35*math.pow(10,-3) #current\n",
+ "lamda=0.85*math.pow(10,-6) #wavelength\n",
+ "\n",
+ "# Calculations\n",
+ "t=tr*tnr/(tr+tnr) #computing total recombination time\n",
+ "eta=t/tr #computing internal quantum efficiency\n",
+ "Pint=eta*h*c*i/(q*lamda) #computing internally generated power\n",
+ "Pint=Pint*math.pow(10,3)\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print '%s %.2f %s %.3f %s %.1f %s' %(\"\\nTotal recombinaiton time is \",t,\" ns.\\nInternal quantum efficiency is \",eta,\".\\nInternally generated power is \",Pint,\" mW.\")\n",
+ "\n",
+ "#answer in the book for Internal quantum efficiency is 0.629, deviation of 0.001.\n",
+ "#answer in the book for Internally generated power is 32.16 mW, deviation of 0.04 mW.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total recombinaiton time is 31.48 ns.\n",
+ "Internal quantum efficiency is 0.630 .\n",
+ "Internally generated power is 32.2 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.21.2 : Pg 6.59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable initialisation\n",
+ "tr=30.0 #radiative recombination lifetime\n",
+ "tnr=100.0 #non-radiative recombination lifetime\n",
+ "h=6.624*math.pow(10,-34) #plank's constant\n",
+ "c=3*math.pow(10,8) #speed of light\n",
+ "q=1.6*math.pow(10,-19) #charge of electron\n",
+ "i=40*math.pow(10,-3) #current\n",
+ "lamda=1310*math.pow(10,-9) #wavelength\n",
+ "\n",
+ "# Calculations\n",
+ "t=tr*tnr/(tr+tnr) #computing total recombination time\n",
+ "eta=t/tr #computing internal quantum efficiency\n",
+ "Pint=eta*h*c*i/(q*lamda) #computing internally generated power\n",
+ "Pint=Pint*math.pow(10,3)\n",
+ "\n",
+ "print '%s %.2f %s %.3f %s %.2f %s' %(\"\\nTotal recombinaiton time is \",t,\" ns.\\nInternal quantum efficiency is \",eta,\".\\nInternally generated power is \",Pint,\" mW.\")\n",
+ "\n",
+ "#answer in the book for Total recombinaiton time is 23.07 ns, deviation of 0.01ns.\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total recombinaiton time is 23.08 ns.\n",
+ "Internal quantum efficiency is 0.769 .\n",
+ "Internally generated power is 29.17 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.21.3 : Pg 6.60"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Example 6.21.3 page 6.60\n",
+ "\n",
+ "import math\n",
+ "# Variable initialisation\n",
+ "\n",
+ "tr=50.0 #radiative recombination lifetime\n",
+ "tnr=110.0 #non-radiative recombination lifetime\n",
+ "h=6.624*math.pow(10,-34) #plank's constant\n",
+ "c=3*math.pow(10,8) #speed of light\n",
+ "q=1.6*math.pow(10,-19) #charge of electron\n",
+ "i=40*math.pow(10,-3) #current\n",
+ "lamda=0.87*math.pow(10,-6) #wavelength\n",
+ "\n",
+ "# Calculations\n",
+ "t=tr*tnr/(tr+tnr) #computing total recombination time\n",
+ "eta=t/tr #computing internal quantum efficiency\n",
+ "Pint=eta*h*c*i/(q*lamda) #computing internally generated power\n",
+ "Pint=Pint*math.pow(10,3)\n",
+ "\n",
+ "print '%s %.2f %s %.4f %s %.2f %s' %(\"\\nTotal recombinaiton time is \",t,\"ns.\\nInternal quantum efficiency is \",eta,\".\\nInternally generated power is \",Pint,\"mW.\")\n",
+ "\n",
+ "#answers in the book with slight deviaitons\n",
+ "#Total recombinaiton time is 34.37 ns, deviation of 0.01ns.\n",
+ "#Internal quantum efficiency is 0.6874, deviaiton of 0.0001.\n",
+ "#Internally generated power is 39.24 mW, deviation of 0.02mW.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total recombinaiton time is 34.38 ns.\n",
+ "Internal quantum efficiency is 0.6875 .\n",
+ "Internally generated power is 39.26 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.22.1 : Pg 6.68"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable initialisation\n",
+ "f1=10*math.pow(10,6) #frequency\n",
+ "f2=100*math.pow(10,6)\n",
+ "t=4*math.pow(10,-9)\n",
+ "Pdc=280*math.pow(10,-6) #optincal output power\n",
+ "\n",
+ "# Calculations\n",
+ "w1=2*math.pi*f1 #computing omega\n",
+ "Pout1=Pdc*math.pow(10,6)/(math.sqrt(1+math.pow((w1*t),2))) #computing output power\n",
+ "\n",
+ "w2=2*math.pi*f2 #computing omega\n",
+ "Pout2=Pdc*math.pow(10,6)/(math.sqrt(1+math.pow((w2*t),2))) #computing output power\n",
+ "\n",
+ "print '%s %.2f %s %.2f %s' %(\"Ouput power at 10 MHz is \",Pout1,\"microwatt.\\nOuput power at 100 MHz is \",Pout2,\"microwatt.\\nConclusion when device is drive at higher frequency the optical power reduces.\\nNOTE - calculation error. In the book square term in the denominator is not taken.\")\n",
+ "BWopt = math.sqrt(3)/(2*math.pi*t)\n",
+ "BWelec = BWopt/math.sqrt(2)\n",
+ "BWopt=BWopt*math.pow(10,-6)\n",
+ "BWelec=BWelec*math.pow(10,-6)\n",
+ "\n",
+ "print '%s %.2f %s %.2f %s' %(\"\\n3 dB optical power is \",BWopt,\" MHz.\\n3 dB electrical power is \",BWelec,\" MHz.\")\n",
+ "\n",
+ "\n",
+ "#calculation error. In the book square term in the denominater is not taken.\n",
+ "#answers in the book - \n",
+ "#Ouput power at 10 MHz is 228.7 microwatt.(incorrect)\n",
+ "#Ouput power at 100 MHz is 175 microwatt.(incorrect)\n",
+ "#3 dB optical power is 68.8 MHz, deviation of 0.12\n",
+ "#3 dB electrical power is 48.79 MHz, deviation of 0.06 \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ouput power at 10 MHz is 271.55 microwatt.\n",
+ "Ouput power at 100 MHz is 103.52 microwatt.\n",
+ "Conclusion when device is drive at higher frequency the optical power reduces.\n",
+ "NOTE - calculation error. In the book square term in the denominator is not taken.\n",
+ "\n",
+ "3 dB optical power is 68.92 MHz.\n",
+ "3 dB electrical power is 48.73 MHz.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.22.2 : Pg 6.69"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable initialisation\n",
+ "n1=3.5 #refractive index\n",
+ "n=1 #refractive index of air\n",
+ "F=0.69 #transmission factor\n",
+ "\n",
+ "# Calculations\n",
+ "eta = 100*math.pow((n1*math.pow((n1+1),2)),-1) #computing eta\n",
+ "\n",
+ "# Results\n",
+ "print '%s %.1f %s' %(\"\\neta external is \",eta,\" percent i.e. small fraction of intrnally generated opticalpower is emitted from the device.\")\n",
+ "print \"\\n\\n OR we can also arrive at solution,\\n\" \n",
+ "\n",
+ "r= 100*F*math.pow(n,2)/(4*math.pow(n1,2)) #computing ratio of Popt/Pint\n",
+ "\n",
+ "print '%s %.1f %s' %(\"\\n Popt/Pint is \",r,\"percent\")\n",
+ "\n",
+ "print \"\\nNOTE - printing mistake at final answer.\\nThey have printed 40 percent it should be 1.4 percent\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "eta external is 1.4 percent i.e. small fraction of intrnally generated opticalpower is emitted from the device.\n",
+ "\n",
+ "\n",
+ " OR we can also arrive at solution,\n",
+ "\n",
+ "\n",
+ " Popt/Pint is 1.4 percent\n",
+ "\n",
+ "NOTE - printing mistake at final answer.\n",
+ "They have printed 40 percent it should be 1.4 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.22.3 : Pg 6.73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable initialisation\n",
+ "beta0=1.85*math.pow(10,7)\n",
+ "T=293 #temperature\n",
+ "k=1.38*math.pow(10,-23) #Boltzman constant\n",
+ "Ea=0.9*1.6*math.pow(10,-19)\n",
+ "theta=0.65 #threshold\n",
+ "\n",
+ "# Calculations\n",
+ "betar=beta0*math.pow(math.e,(-Ea/(k*T)))\n",
+ "t=-math.log(theta)/betar\n",
+ "\n",
+ "# Result\n",
+ "print '%s %.2e %s %.1e %s' %(\"\\nDegradation rate is \",betar,\" per hour.\\nOperating lifetime is \",t,\" hour.\")\n",
+ "\n",
+ "#answer in the book for Degradation rate is 6.4e-09 per hour, deviation of 0.08e-9\n",
+ "#answer in the book for Operating lifetime is 6.7e+07 hour, deviaiton of 0.1e1\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Degradation rate is 6.32e-09 per hour.\n",
+ "Operating lifetime is 6.8e+07 hour.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/Ershad AhamedChemmalasseri/chapter1.ipynb b/sample_notebooks/Ershad AhamedChemmalasseri/chapter1.ipynb
new file mode 100755
index 00000000..251df967
--- /dev/null
+++ b/sample_notebooks/Ershad AhamedChemmalasseri/chapter1.ipynb
@@ -0,0 +1,556 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:65f02fae284344ccd8037c2004c0386b9cc4ee681cfc1240a77e3be2fe2aff5e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 1: Introductory Concepts"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.1, Page number 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Express absolute viscosity of fluids in SI units and calculate the kinematic viscosity\n",
+ "\n",
+ "# Import required modules\n",
+ "\n",
+ "import numpy as np\n",
+ "from prettytable import PrettyTable\n",
+ "\n",
+ "# Given\n",
+ "\n",
+ "mu = np.array([1,0.018,100]) # Absolute viscosities in centipoise\n",
+ "mu_poise = np.array([1,0.018,100])/100 # Absolute viscosities in poise\n",
+ "rho = np.array([1.0,0.0012,0.930]) # Densities in gm/cm^3\n",
+ "mu_SI = mu/1000 # Absolute viscosities in SI units\n",
+ "rho_SI = rho*1000 # Densities in SI units\n",
+ "nu = mu_poise/rho # Kinematic viscosities in Stokes\n",
+ "nu_SI = mu_SI/rho_SI # Kinematic viscosities in SI units\n",
+ "\n",
+ "# Tabulate results\n",
+ "\n",
+ "table = PrettyTable([\"Property\", \"Water\", \"Air\", \"Lube Oil\"])\n",
+ "table.add_row(['Absolute Viscosity mu',' ',' ',' '])\n",
+ "table.add_row([\"centipoise cP\",mu[0],mu[1],mu[2]])\n",
+ "table.add_row([\"SI units (Ns/m^2)\",mu_SI[0],mu_SI[1],mu_SI[2]])\n",
+ "table.add_row([' ',' ',' ',' '])\n",
+ "table.add_row(['Mass Density rho',' ',' ',' '])\n",
+ "table.add_row([\"g/cm^3\",rho[0],rho[1],rho[2]])\n",
+ "table.add_row([\"SI units (kg/m^3)\",rho_SI[0],rho_SI[1],rho_SI[2]])\n",
+ "table.add_row([' ',' ',' ',' '])\n",
+ "table.add_row(['Kinematic Viscosity nu',' ',' ',' '])\n",
+ "table.add_row([\"St\",nu[0],nu[1],round(nu[2],2)])\n",
+ "table.add_row([\"SI units (m^2/s)\",nu_SI[0],nu_SI[1],\"{:.2e}\".format(nu_SI[2])])\n",
+ "print table"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "+------------------------+--------+---------+----------+\n",
+ "| Property | Water | Air | Lube Oil |\n",
+ "+------------------------+--------+---------+----------+\n",
+ "| Absolute Viscosity mu | | | |\n",
+ "| centipoise cP | 1.0 | 0.018 | 100.0 |\n",
+ "| SI units (Ns/m^2) | 0.001 | 1.8e-05 | 0.1 |\n",
+ "| | | | |\n",
+ "| Mass Density rho | | | |\n",
+ "| g/cm^3 | 1.0 | 0.0012 | 0.93 |\n",
+ "| SI units (kg/m^3) | 1000.0 | 1.2 | 930.0 |\n",
+ "| | | | |\n",
+ "| Kinematic Viscosity nu | | | |\n",
+ "| St | 0.01 | 0.15 | 1.08 |\n",
+ "| SI units (m^2/s) | 1e-06 | 1.5e-05 | 1.08e-04 |\n",
+ "+------------------------+--------+---------+----------+\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.2, Page number 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate the force and power required to maintain the velocity\n",
+ "\n",
+ "# Given\n",
+ "A = 0.1 # Area of the flat plate (m^2)\n",
+ "U = 0.3 # Velocity of the flat plate (m/s)\n",
+ "mu = 0.001 # viscosity of the fluid separating the plates (m)\n",
+ "du = U - 0 # relative velocity between the plates\n",
+ "dy = 0.0001 # relative distance between the plates\n",
+ "\n",
+ "tau = mu*du/dy # Shear stress (N/m^2)\n",
+ "F = tau * A # Shear force (N)\n",
+ "Power = F * U # Power required (W)\n",
+ "print(\"The force required to maintain the velocity is %.2f N.\" %F)\n",
+ "print(\"The power required is %.2f W.\" %Power)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The force required to maintain the velocity is 0.30 N.\n",
+ "The power required is 0.09 W.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.3, Page number 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Determine the torque and power\n",
+ "\n",
+ "# Import required modules\n",
+ "\n",
+ "import math \n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "l = 0.10 # length of the shaft (m)\n",
+ "d = 0.05 # diameter of the shaft (m)\n",
+ "D = 0.051 # diameter of the concentric bearing (m)\n",
+ "N = 500 # Rotational speed of the shaft (rpm)\n",
+ "mu = 0.1 # Viscosity of the lubricating oil (Ns/m^2)\n",
+ "theta = sympy.Symbol('theta')\n",
+ "\n",
+ "u = round(math.pi*d*N/60,2) # Peripheral speed of the shaft (m/s)\n",
+ "du = u - 0 \n",
+ "dy = (D-d)/2\n",
+ "tau = round(mu*du/dy,0) # Shear stress (N/m^2)\n",
+ "T = sympy.integrate(tau*d/2*d/2*l,(theta,0,2*math.pi)) # Torque required to turn the shaft (Nm)\n",
+ "omega = u/(d/2) # Angular speed of the shaft\n",
+ "Power = round(T,3)*omega # Power required to turn the shaft (W)\n",
+ "\n",
+ "print(\"The power required to turn the shaft is %1.3f W.\" %Power)\n",
+ "# Wrong rounding-off of Torque T in textbook. Hence, the difference in value of power. Textbook answer Power = 5.387 W"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The power required to turn the shaft is 5.397 W.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.4, Page number 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# The power dissipated in the bearing\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "R = 0.1/2 # Radius of the bearing (m)\n",
+ "mu = 0.08 # Viscosity of oil film (Ns/m^2)\n",
+ "dy = 0.0015 # separation distance (m)\n",
+ "N = 100 # Rotational speed of the bearing (rpm)\n",
+ "r = sympy.Symbol('r')\n",
+ "theta = sympy.Symbol('theta')\n",
+ "\n",
+ "omega = round(2*math.pi*100/60,2) # Angular velocity of the bearing (rad/s)\n",
+ "u = r*omega # Linear velocity of the bearing (m/s)\n",
+ "du = u - 0 # Relative velocity \n",
+ "tau = mu * du/dy # Shear stress (N/m^2)\n",
+ "T = sympy.integrate(tau*r*r,(theta,0,2*math.pi),(r,0,R)) # Total torque on the shaft (Nm)\n",
+ "Power = round(T,5)*omega # Power dissipated (W)\n",
+ "print(\"The power dissipated by the bearing is %.4f W.\" %Power)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The power dissipated by the bearing is 0.0574 W.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.5, Page number 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Determine shear stress for r/R ratios and calculate drag force per meter length of the pipe\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "import math\n",
+ "from tabulate import tabulate\n",
+ "\n",
+ "# Given\n",
+ "r = sympy.Symbol('r') # Radial distance for the point\n",
+ "R = sympy.Symbol('R') # Radial distance for the wall\n",
+ "U = 10 # Centreline velocity (m/s)\n",
+ "mu = 0.002 # Viscosity (Ns/m^2)\n",
+ "r_R = [0.0,0.2,0.5,0.8,1.0] # r/R ratios\n",
+ "u = U*(1-(r/R)**2) # Expression for velocity in a pipe-flow\n",
+ "y = R-r # Distance from the wall\n",
+ "\n",
+ "du = sympy.diff(u,r) # Derivative of 'u' expression\n",
+ "dy = sympy.diff(y,r) \n",
+ "tau = mu*du/dy # Newton's law of viscosity (N/m^2)\n",
+ "F = 2*math.pi*R*tau # Drag force (N)\n",
+ "\n",
+ "# Substitution of r/R ratios\n",
+ "table = []\n",
+ "for i, r_R in enumerate(r_R): \n",
+ " table.append([r_R,round(tau.subs([(R,1.0/2.0),(r,r_R*1.0/2.0)]),4),\n",
+ " round(F.subs([(R,1.0/2.0),(r,r_R*1.0/2.0)]),4)])\n",
+ "print tabulate(table, headers=['r/R', 'Shear stress, tau (N/m^2)', 'Drag force, F (N)'],tablefmt='grid',numalign=\"center\")\n",
+ "# The Drag force printed in the textbook for the r/R = 0.8 is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "+-------+-----------------------------+---------------------+\n",
+ "| r/R | Shear stress, tau (N/m^2) | Drag force, F (N) |\n",
+ "+=======+=============================+=====================+\n",
+ "| 0 | 0 | 0 |\n",
+ "+-------+-----------------------------+---------------------+\n",
+ "| 0.2 | 0.016 | 0.0503 |\n",
+ "+-------+-----------------------------+---------------------+\n",
+ "| 0.5 | 0.04 | 0.1257 |\n",
+ "+-------+-----------------------------+---------------------+\n",
+ "| 0.8 | 0.064 | 0.2011 |\n",
+ "+-------+-----------------------------+---------------------+\n",
+ "| 1 | 0.08 | 0.2513 |\n",
+ "+-------+-----------------------------+---------------------+\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.6, Page number 27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Determine average thickness of the film\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "n = 800 # Normal reaction by the ice on the skater (N)\n",
+ "f = 0.02 # Coefficient of friction between the skates and the ice \n",
+ "u = 54*1000/3600 # Speed of the skater (m/s)\n",
+ "A = 10e-4 # Skating area (m^2)\n",
+ "mu = 0.001 # Viscosity of water (Ns/m^2)\n",
+ "h = sympy.Symbol('h') # average thickness of the film\n",
+ "\n",
+ "F = f*n # Frictional reaction (N)\n",
+ "du_dy = (u-0)/h # Velocity gradient\n",
+ "tau = mu*du_dy # Shear stress (N/m^2)\n",
+ "print('The average thickness of the film is %.3e m.'\n",
+ " %sympy.solve(sympy.Eq(tau*A,F),h)[0]) # Solve for h by equating drag force to frictional reaction"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The average thickness of the film is 9.375e-07 m.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7, Page number 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Determine necessary increase of pressure\n",
+ "\n",
+ "# Given\n",
+ "K = 2.07e6 # Bulk modulus of water (kN/m^2)\n",
+ "gamma = 1.4 # Specific heat ratio\n",
+ "p = 101.324 # Atmospheric pressure (kN/m^2)\n",
+ "vol_red = 0.01 # Volume reduction \n",
+ "\n",
+ "# (a) At same temperature\n",
+ "dp = vol_red * K # increase in pressure (kN/m^2)\n",
+ "print('The increase in pressure required for water is %d kN/m^2.' %dp)\n",
+ "# (b) isentropic compression of air\n",
+ "K = gamma * p # Bulk modulus of air (kN/m^2)\n",
+ "dp = vol_red * K # increase in pressure (kN/m^2)\n",
+ "print('The increase in pressure required for air is %.2f kN/m^2.' %dp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The increase in pressure required for water is 20700 kN/m^2.\n",
+ "The increase in pressure required for air is 1.42 kN/m^2.\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Height of capillary rise\n",
+ "\n",
+ "# Import required modules\n",
+ "import math\n",
+ "\n",
+ "# Given\n",
+ "sigma = 0.0736 # Surface tension between water and glass (N/m)\n",
+ "theta = 0 # Angle of contact\n",
+ "d = 2e-3 # Diameter of the glass tube (m)\n",
+ "g = 9.81 # Acceleration due to gravity (m/s^2)\n",
+ "rho = 1000 # Density of water (kg/m^3)\n",
+ "\n",
+ "h = 4*sigma*math.cos(theta)/(rho*g*d) # height of capillary rise (m)\n",
+ "print('The water in the glass tube rises through a height of %0.3f m'%h)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The water in the glass tube rises through a height of 0.015 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.8, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Gauge pressure and absolute pressure within a droplet and a jet\n",
+ "\n",
+ "# Given\n",
+ "d_droplet = 0.004 # Diamter of the droplet (m)\n",
+ "d_jet = 0.004 # Diameter of the jet (m)\n",
+ "sigma = 0.073 # Viscosity of water (Ns/m^2)\n",
+ "P_atm = 101300 # Atmospheric pressure (N/m^2)\n",
+ "\n",
+ "# (a) For the droplet\n",
+ "P_gauge = 4*sigma/d_droplet # Gauge pressure for droplet (N/m^2)\n",
+ "P_abs = P_atm + P_gauge # Absolute pressure (N/m^2)\n",
+ "print('The gauge pressure and absolute pressure within a droplet is %d N/m^2 and %.3f kN/m^2 respectively.' %(P_gauge,P_abs/1000))\n",
+ "\n",
+ "# (a) For the jet\n",
+ "P_gauge = 2*sigma/d_jet # Gauge pressure for jet (N/m^2)\n",
+ "P_abs = P_atm + P_gauge # Absolute pressure (N/m^2)\n",
+ "print('The gauge pressure and absolute pressure within a jet is %.1f N/m^2 and %.2f kN/m^2 respectively.' %(P_gauge,P_abs/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The gauge pressure and absolute pressure within a droplet is 73 N/m^2 and 101.373 kN/m^2 respectively.\n",
+ "The gauge pressure and absolute pressure within a jet is 36.5 N/m^2 and 101.34 kN/m^2 respectively.\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Difference in level of the miniscii\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "d_1 = 1.0e-3 # Diameter of capillary (m)\n",
+ "d_2 = 1.5e-3 # Diameter of another capillary (m)\n",
+ "sigma = 0.0075 # Surface tension of water (Ns/m^2)\n",
+ "g = 9.81 # Acceleration due to gravity (m/s^2)\n",
+ "rho = 1000 # Density of water (kg/m^3)\n",
+ "h = sympy.Symbol('h') # Difference in level of the miniscii (m)\n",
+ "\n",
+ "h = sympy.solve(sympy.Eq(math.pi*d_2*sigma-math.pi*d_1*sigma,math.pi*d_2**2*h*rho*g/4),h)[0]*1000 # Solve for h\n",
+ "print('The difference in level of the miniscii is %.2f mm' %h)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The difference in level of the miniscii is 0.68 mm\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.10, Page number 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Shear stress calculation and estimate the viscosity\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "U_max = 0.2 # Maximum velocity (m/s)\n",
+ "h = 0.01 # film thickness (m)\n",
+ "mu = 0.5 # Viscosity of the non-Newtonian fluid (Ns/m^2)\n",
+ "y = sympy.Symbol('y') \n",
+ "u = sympy.Symbol('u') \n",
+ "u = U_max * (2*(y/h)-(y/h)**3/3) # Expression for velocity\n",
+ "\n",
+ "# (a) Shear stress calculation\n",
+ "du_dy = sympy.diff(u,y) # Velocity gradient\n",
+ "tau = mu*(round(du_dy.subs(y,h)))**1.3 # Shear stress of the non-Newtonian fluid (N/m^2)\n",
+ "print('The shear stress at the solid surface is %.2f N/m^2.' %tau)\n",
+ "\n",
+ "# (b) Estimation of the viscosity of the Newtonian fluid\n",
+ "mu = sympy.Symbol('mu')\n",
+ "mu = sympy.solve(sympy.Eq(round(tau,2),mu*round(du_dy.subs(y,h))))[0] # Solve for mu for the same shear stress using Newton's law of viscosity\n",
+ "print('The viscosity of a Newtonian fluid to induce the same shear stress is %.2f Ns/m^2.' %mu)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The shear stress at the solid surface is 24.56 N/m^2.\n",
+ "The viscosity of a Newtonian fluid to induce the same shear stress is 1.23 Ns/m^2.\n"
+ ]
+ }
+ ],
+ "prompt_number": 69
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/Ershad AhamedChemmalasseri/chapter1_1.ipynb b/sample_notebooks/Ershad AhamedChemmalasseri/chapter1_1.ipynb
new file mode 100755
index 00000000..251df967
--- /dev/null
+++ b/sample_notebooks/Ershad AhamedChemmalasseri/chapter1_1.ipynb
@@ -0,0 +1,556 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:65f02fae284344ccd8037c2004c0386b9cc4ee681cfc1240a77e3be2fe2aff5e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 1: Introductory Concepts"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.1, Page number 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Express absolute viscosity of fluids in SI units and calculate the kinematic viscosity\n",
+ "\n",
+ "# Import required modules\n",
+ "\n",
+ "import numpy as np\n",
+ "from prettytable import PrettyTable\n",
+ "\n",
+ "# Given\n",
+ "\n",
+ "mu = np.array([1,0.018,100]) # Absolute viscosities in centipoise\n",
+ "mu_poise = np.array([1,0.018,100])/100 # Absolute viscosities in poise\n",
+ "rho = np.array([1.0,0.0012,0.930]) # Densities in gm/cm^3\n",
+ "mu_SI = mu/1000 # Absolute viscosities in SI units\n",
+ "rho_SI = rho*1000 # Densities in SI units\n",
+ "nu = mu_poise/rho # Kinematic viscosities in Stokes\n",
+ "nu_SI = mu_SI/rho_SI # Kinematic viscosities in SI units\n",
+ "\n",
+ "# Tabulate results\n",
+ "\n",
+ "table = PrettyTable([\"Property\", \"Water\", \"Air\", \"Lube Oil\"])\n",
+ "table.add_row(['Absolute Viscosity mu',' ',' ',' '])\n",
+ "table.add_row([\"centipoise cP\",mu[0],mu[1],mu[2]])\n",
+ "table.add_row([\"SI units (Ns/m^2)\",mu_SI[0],mu_SI[1],mu_SI[2]])\n",
+ "table.add_row([' ',' ',' ',' '])\n",
+ "table.add_row(['Mass Density rho',' ',' ',' '])\n",
+ "table.add_row([\"g/cm^3\",rho[0],rho[1],rho[2]])\n",
+ "table.add_row([\"SI units (kg/m^3)\",rho_SI[0],rho_SI[1],rho_SI[2]])\n",
+ "table.add_row([' ',' ',' ',' '])\n",
+ "table.add_row(['Kinematic Viscosity nu',' ',' ',' '])\n",
+ "table.add_row([\"St\",nu[0],nu[1],round(nu[2],2)])\n",
+ "table.add_row([\"SI units (m^2/s)\",nu_SI[0],nu_SI[1],\"{:.2e}\".format(nu_SI[2])])\n",
+ "print table"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "+------------------------+--------+---------+----------+\n",
+ "| Property | Water | Air | Lube Oil |\n",
+ "+------------------------+--------+---------+----------+\n",
+ "| Absolute Viscosity mu | | | |\n",
+ "| centipoise cP | 1.0 | 0.018 | 100.0 |\n",
+ "| SI units (Ns/m^2) | 0.001 | 1.8e-05 | 0.1 |\n",
+ "| | | | |\n",
+ "| Mass Density rho | | | |\n",
+ "| g/cm^3 | 1.0 | 0.0012 | 0.93 |\n",
+ "| SI units (kg/m^3) | 1000.0 | 1.2 | 930.0 |\n",
+ "| | | | |\n",
+ "| Kinematic Viscosity nu | | | |\n",
+ "| St | 0.01 | 0.15 | 1.08 |\n",
+ "| SI units (m^2/s) | 1e-06 | 1.5e-05 | 1.08e-04 |\n",
+ "+------------------------+--------+---------+----------+\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.2, Page number 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate the force and power required to maintain the velocity\n",
+ "\n",
+ "# Given\n",
+ "A = 0.1 # Area of the flat plate (m^2)\n",
+ "U = 0.3 # Velocity of the flat plate (m/s)\n",
+ "mu = 0.001 # viscosity of the fluid separating the plates (m)\n",
+ "du = U - 0 # relative velocity between the plates\n",
+ "dy = 0.0001 # relative distance between the plates\n",
+ "\n",
+ "tau = mu*du/dy # Shear stress (N/m^2)\n",
+ "F = tau * A # Shear force (N)\n",
+ "Power = F * U # Power required (W)\n",
+ "print(\"The force required to maintain the velocity is %.2f N.\" %F)\n",
+ "print(\"The power required is %.2f W.\" %Power)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The force required to maintain the velocity is 0.30 N.\n",
+ "The power required is 0.09 W.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.3, Page number 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Determine the torque and power\n",
+ "\n",
+ "# Import required modules\n",
+ "\n",
+ "import math \n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "l = 0.10 # length of the shaft (m)\n",
+ "d = 0.05 # diameter of the shaft (m)\n",
+ "D = 0.051 # diameter of the concentric bearing (m)\n",
+ "N = 500 # Rotational speed of the shaft (rpm)\n",
+ "mu = 0.1 # Viscosity of the lubricating oil (Ns/m^2)\n",
+ "theta = sympy.Symbol('theta')\n",
+ "\n",
+ "u = round(math.pi*d*N/60,2) # Peripheral speed of the shaft (m/s)\n",
+ "du = u - 0 \n",
+ "dy = (D-d)/2\n",
+ "tau = round(mu*du/dy,0) # Shear stress (N/m^2)\n",
+ "T = sympy.integrate(tau*d/2*d/2*l,(theta,0,2*math.pi)) # Torque required to turn the shaft (Nm)\n",
+ "omega = u/(d/2) # Angular speed of the shaft\n",
+ "Power = round(T,3)*omega # Power required to turn the shaft (W)\n",
+ "\n",
+ "print(\"The power required to turn the shaft is %1.3f W.\" %Power)\n",
+ "# Wrong rounding-off of Torque T in textbook. Hence, the difference in value of power. Textbook answer Power = 5.387 W"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The power required to turn the shaft is 5.397 W.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.4, Page number 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# The power dissipated in the bearing\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "R = 0.1/2 # Radius of the bearing (m)\n",
+ "mu = 0.08 # Viscosity of oil film (Ns/m^2)\n",
+ "dy = 0.0015 # separation distance (m)\n",
+ "N = 100 # Rotational speed of the bearing (rpm)\n",
+ "r = sympy.Symbol('r')\n",
+ "theta = sympy.Symbol('theta')\n",
+ "\n",
+ "omega = round(2*math.pi*100/60,2) # Angular velocity of the bearing (rad/s)\n",
+ "u = r*omega # Linear velocity of the bearing (m/s)\n",
+ "du = u - 0 # Relative velocity \n",
+ "tau = mu * du/dy # Shear stress (N/m^2)\n",
+ "T = sympy.integrate(tau*r*r,(theta,0,2*math.pi),(r,0,R)) # Total torque on the shaft (Nm)\n",
+ "Power = round(T,5)*omega # Power dissipated (W)\n",
+ "print(\"The power dissipated by the bearing is %.4f W.\" %Power)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The power dissipated by the bearing is 0.0574 W.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.5, Page number 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Determine shear stress for r/R ratios and calculate drag force per meter length of the pipe\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "import math\n",
+ "from tabulate import tabulate\n",
+ "\n",
+ "# Given\n",
+ "r = sympy.Symbol('r') # Radial distance for the point\n",
+ "R = sympy.Symbol('R') # Radial distance for the wall\n",
+ "U = 10 # Centreline velocity (m/s)\n",
+ "mu = 0.002 # Viscosity (Ns/m^2)\n",
+ "r_R = [0.0,0.2,0.5,0.8,1.0] # r/R ratios\n",
+ "u = U*(1-(r/R)**2) # Expression for velocity in a pipe-flow\n",
+ "y = R-r # Distance from the wall\n",
+ "\n",
+ "du = sympy.diff(u,r) # Derivative of 'u' expression\n",
+ "dy = sympy.diff(y,r) \n",
+ "tau = mu*du/dy # Newton's law of viscosity (N/m^2)\n",
+ "F = 2*math.pi*R*tau # Drag force (N)\n",
+ "\n",
+ "# Substitution of r/R ratios\n",
+ "table = []\n",
+ "for i, r_R in enumerate(r_R): \n",
+ " table.append([r_R,round(tau.subs([(R,1.0/2.0),(r,r_R*1.0/2.0)]),4),\n",
+ " round(F.subs([(R,1.0/2.0),(r,r_R*1.0/2.0)]),4)])\n",
+ "print tabulate(table, headers=['r/R', 'Shear stress, tau (N/m^2)', 'Drag force, F (N)'],tablefmt='grid',numalign=\"center\")\n",
+ "# The Drag force printed in the textbook for the r/R = 0.8 is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "+-------+-----------------------------+---------------------+\n",
+ "| r/R | Shear stress, tau (N/m^2) | Drag force, F (N) |\n",
+ "+=======+=============================+=====================+\n",
+ "| 0 | 0 | 0 |\n",
+ "+-------+-----------------------------+---------------------+\n",
+ "| 0.2 | 0.016 | 0.0503 |\n",
+ "+-------+-----------------------------+---------------------+\n",
+ "| 0.5 | 0.04 | 0.1257 |\n",
+ "+-------+-----------------------------+---------------------+\n",
+ "| 0.8 | 0.064 | 0.2011 |\n",
+ "+-------+-----------------------------+---------------------+\n",
+ "| 1 | 0.08 | 0.2513 |\n",
+ "+-------+-----------------------------+---------------------+\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.6, Page number 27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Determine average thickness of the film\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "n = 800 # Normal reaction by the ice on the skater (N)\n",
+ "f = 0.02 # Coefficient of friction between the skates and the ice \n",
+ "u = 54*1000/3600 # Speed of the skater (m/s)\n",
+ "A = 10e-4 # Skating area (m^2)\n",
+ "mu = 0.001 # Viscosity of water (Ns/m^2)\n",
+ "h = sympy.Symbol('h') # average thickness of the film\n",
+ "\n",
+ "F = f*n # Frictional reaction (N)\n",
+ "du_dy = (u-0)/h # Velocity gradient\n",
+ "tau = mu*du_dy # Shear stress (N/m^2)\n",
+ "print('The average thickness of the film is %.3e m.'\n",
+ " %sympy.solve(sympy.Eq(tau*A,F),h)[0]) # Solve for h by equating drag force to frictional reaction"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The average thickness of the film is 9.375e-07 m.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7, Page number 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Determine necessary increase of pressure\n",
+ "\n",
+ "# Given\n",
+ "K = 2.07e6 # Bulk modulus of water (kN/m^2)\n",
+ "gamma = 1.4 # Specific heat ratio\n",
+ "p = 101.324 # Atmospheric pressure (kN/m^2)\n",
+ "vol_red = 0.01 # Volume reduction \n",
+ "\n",
+ "# (a) At same temperature\n",
+ "dp = vol_red * K # increase in pressure (kN/m^2)\n",
+ "print('The increase in pressure required for water is %d kN/m^2.' %dp)\n",
+ "# (b) isentropic compression of air\n",
+ "K = gamma * p # Bulk modulus of air (kN/m^2)\n",
+ "dp = vol_red * K # increase in pressure (kN/m^2)\n",
+ "print('The increase in pressure required for air is %.2f kN/m^2.' %dp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The increase in pressure required for water is 20700 kN/m^2.\n",
+ "The increase in pressure required for air is 1.42 kN/m^2.\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Height of capillary rise\n",
+ "\n",
+ "# Import required modules\n",
+ "import math\n",
+ "\n",
+ "# Given\n",
+ "sigma = 0.0736 # Surface tension between water and glass (N/m)\n",
+ "theta = 0 # Angle of contact\n",
+ "d = 2e-3 # Diameter of the glass tube (m)\n",
+ "g = 9.81 # Acceleration due to gravity (m/s^2)\n",
+ "rho = 1000 # Density of water (kg/m^3)\n",
+ "\n",
+ "h = 4*sigma*math.cos(theta)/(rho*g*d) # height of capillary rise (m)\n",
+ "print('The water in the glass tube rises through a height of %0.3f m'%h)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The water in the glass tube rises through a height of 0.015 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.8, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Gauge pressure and absolute pressure within a droplet and a jet\n",
+ "\n",
+ "# Given\n",
+ "d_droplet = 0.004 # Diamter of the droplet (m)\n",
+ "d_jet = 0.004 # Diameter of the jet (m)\n",
+ "sigma = 0.073 # Viscosity of water (Ns/m^2)\n",
+ "P_atm = 101300 # Atmospheric pressure (N/m^2)\n",
+ "\n",
+ "# (a) For the droplet\n",
+ "P_gauge = 4*sigma/d_droplet # Gauge pressure for droplet (N/m^2)\n",
+ "P_abs = P_atm + P_gauge # Absolute pressure (N/m^2)\n",
+ "print('The gauge pressure and absolute pressure within a droplet is %d N/m^2 and %.3f kN/m^2 respectively.' %(P_gauge,P_abs/1000))\n",
+ "\n",
+ "# (a) For the jet\n",
+ "P_gauge = 2*sigma/d_jet # Gauge pressure for jet (N/m^2)\n",
+ "P_abs = P_atm + P_gauge # Absolute pressure (N/m^2)\n",
+ "print('The gauge pressure and absolute pressure within a jet is %.1f N/m^2 and %.2f kN/m^2 respectively.' %(P_gauge,P_abs/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The gauge pressure and absolute pressure within a droplet is 73 N/m^2 and 101.373 kN/m^2 respectively.\n",
+ "The gauge pressure and absolute pressure within a jet is 36.5 N/m^2 and 101.34 kN/m^2 respectively.\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Difference in level of the miniscii\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "d_1 = 1.0e-3 # Diameter of capillary (m)\n",
+ "d_2 = 1.5e-3 # Diameter of another capillary (m)\n",
+ "sigma = 0.0075 # Surface tension of water (Ns/m^2)\n",
+ "g = 9.81 # Acceleration due to gravity (m/s^2)\n",
+ "rho = 1000 # Density of water (kg/m^3)\n",
+ "h = sympy.Symbol('h') # Difference in level of the miniscii (m)\n",
+ "\n",
+ "h = sympy.solve(sympy.Eq(math.pi*d_2*sigma-math.pi*d_1*sigma,math.pi*d_2**2*h*rho*g/4),h)[0]*1000 # Solve for h\n",
+ "print('The difference in level of the miniscii is %.2f mm' %h)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The difference in level of the miniscii is 0.68 mm\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.10, Page number 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Shear stress calculation and estimate the viscosity\n",
+ "\n",
+ "# Import required modules\n",
+ "import sympy\n",
+ "\n",
+ "# Given\n",
+ "U_max = 0.2 # Maximum velocity (m/s)\n",
+ "h = 0.01 # film thickness (m)\n",
+ "mu = 0.5 # Viscosity of the non-Newtonian fluid (Ns/m^2)\n",
+ "y = sympy.Symbol('y') \n",
+ "u = sympy.Symbol('u') \n",
+ "u = U_max * (2*(y/h)-(y/h)**3/3) # Expression for velocity\n",
+ "\n",
+ "# (a) Shear stress calculation\n",
+ "du_dy = sympy.diff(u,y) # Velocity gradient\n",
+ "tau = mu*(round(du_dy.subs(y,h)))**1.3 # Shear stress of the non-Newtonian fluid (N/m^2)\n",
+ "print('The shear stress at the solid surface is %.2f N/m^2.' %tau)\n",
+ "\n",
+ "# (b) Estimation of the viscosity of the Newtonian fluid\n",
+ "mu = sympy.Symbol('mu')\n",
+ "mu = sympy.solve(sympy.Eq(round(tau,2),mu*round(du_dy.subs(y,h))))[0] # Solve for mu for the same shear stress using Newton's law of viscosity\n",
+ "print('The viscosity of a Newtonian fluid to induce the same shear stress is %.2f Ns/m^2.' %mu)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The shear stress at the solid surface is 24.56 N/m^2.\n",
+ "The viscosity of a Newtonian fluid to induce the same shear stress is 1.23 Ns/m^2.\n"
+ ]
+ }
+ ],
+ "prompt_number": 69
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/ManikandanD/Chapter1.ipynb b/sample_notebooks/ManikandanD/Chapter1.ipynb
new file mode 100755
index 00000000..56736e6b
--- /dev/null
+++ b/sample_notebooks/ManikandanD/Chapter1.ipynb
@@ -0,0 +1,248 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c711f301926e36cf02f99393ea24acbb9b052c829159da80a195eb0ad85a92da"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1:Bonding in Solids"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.3 , Page no:15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "r=2; #in angstrom(distance)\n",
+ "e=1.6E-19; # in C (charge of electron)\n",
+ "E_o= 8.85E-12;# absolute premittivity\n",
+ "\n",
+ "#calculate\n",
+ "r=2*1*10**-10; # since r is in angstrom\n",
+ "V=-e**2/(4*3.14*E_o*r); # calculate potential\n",
+ "V1=V/e; # changing to eV\n",
+ "\n",
+ "#result\n",
+ "print \"\\nThe potential energy is V = \",V,\"J\";\n",
+ "print \"In electron-Volt V = \",round(V,3),\"eV\"; \n",
+ "print \"Note: the answer in the book is wrong due to calculation mistake\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The potential energy is V = -1.15153477995e-18 J\n",
+ "In electron-Volt V = -0.0 eV\n",
+ "Note: the answer in the book is wrong due to calculation mistake\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.4 , Page no:15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "#given\n",
+ "r0=0.236; #in nanometer(interionic distance)\n",
+ "e=1.6E-19; # in C (charge of electron)\n",
+ "E_o= 8.85E-12;# absolute premittivity\n",
+ "N=8; # Born constant\n",
+ "IE=5.14;# in eV (ionisation energy of sodium)\n",
+ "EA=3.65;# in eV (electron affinity of Chlorine)\n",
+ "pi=3.14; # value of pi used in the solution\n",
+ "\n",
+ "#calculate\n",
+ "r0=r0*1E-9; # since r is in nanometer\n",
+ "PE=(e**2/(4*pi*E_o*r0))*(1-1/N); # calculate potential energy\n",
+ "PE=PE/e; #changing unit from J to eV\n",
+ "NE=IE-EA;# calculation of Net energy\n",
+ "BE=PE-NE;# calculation of Bond Energy\n",
+ "\n",
+ "#result\n",
+ "print\"The potential energy is PE= \",round(PE,2),\"eV\";\n",
+ "print\"The net energy is NE= \",round(NE,2),\"eV\";\n",
+ "print\"The bond energy is BE= \",round(BE,2),\"eV\";\n",
+ "# Note: (1)-In order to make the answer prcatically feasible and avoid the unusual answer, I have used r_0=0.236 nm instead of 236 nm. because using this value will give very much irrelevant answer.\n",
+ "# Note: (2) There is slight variation in the answer due to round off."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The potential energy is PE= 5.34 eV\n",
+ "The net energy is NE= 1.49 eV\n",
+ "The bond energy is BE= 3.85 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.5 , Page no:16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "r_0=.41; #in mm(lattice constant)\n",
+ "e=1.6E-19; #in C (charge of electron)\n",
+ "E_o= 8.85E-12; #absolute premittivity\n",
+ "n=0.5; #repulsive exponent value\n",
+ "alpha=1.76; #Madelung constant\n",
+ "pi=3.14; # value of pi used in the solution\n",
+ "\n",
+ "#calculate\n",
+ "r=.41*1E-3; #since r is in mm\n",
+ "Beta=72*pi*E_o*r**4/(alpha*e**2*(n-1)); #calculation compressibility\n",
+ "\n",
+ "#result\n",
+ "print\"The compressibility is Beta=\",round(Beta);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The compressibility is Beta= -2.50967916144e+15\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.6 , Page no:16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "r_0=3.56; #in Angstrom\n",
+ "e=1.6E-19; #in C (charge of electron)\n",
+ "IE=3.89; #in eV (ionisation energy of Cs)\n",
+ "EA=-3.61; #in eV (electron affinity of Cl)\n",
+ "n=10.5; #Born constant\n",
+ "E_o= 8.85E-12; #absolute premittivity\n",
+ "alpha=1.763; #Madelung constant\n",
+ "pi=3.14; #value of pi used in the solution\n",
+ "\n",
+ "#calculate\n",
+ "r_0=r_0*1E-10; #since r is in nanometer\n",
+ "U=-alpha*(e**2/(4*pi*E_o*r_0))*(1-1/n); #calculate potential energy\n",
+ "U=U/e; #changing unit from J to eV\n",
+ "ACE=U+EA+IE; #calculation of atomic cohesive energy\n",
+ "\n",
+ "#result\n",
+ "print\"The ionic cohesive energy is \",round(U),\"eV\";\n",
+ "print\"The atomic cohesive energy is\",round(ACE),\"eV\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The ionic cohesive energy is -6.0 eV\n",
+ "The atomic cohesive energy is -6.0 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7 , Page no:17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "r_0=2.81; #in Angstrom\n",
+ "e=1.6E-19; #in C (charge of electron)\n",
+ "n=9; #Born constant\n",
+ "E_o= 8.85E-12; #absolute premittivity\n",
+ "alpha=1.748; #Madelung constant\n",
+ "pi=3.14; #value of pi used in the solution\n",
+ "\n",
+ "#calculate\n",
+ "r_0=r_0*1E-10; #since r is in nanometer\n",
+ "V=-alpha*(e**2/(4*pi*E_o*r_0))*(1-1/n); #calculate potential energy\n",
+ "V=V/e; #changing unit from J to eV\n",
+ "V_1=V/2; #Since only half of the energy contribute per ion to the cohecive energy therfore\n",
+ "\n",
+ "#result\n",
+ "print\"The potential energy is V=\",round(V,2),\"eV\";\n",
+ "print\"The energy contributing per ions to the cohesive energy is \",round(V_1,2),\"eV\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The potential energy is V= -7.96 eV\n",
+ "The energy contributing per ions to the cohesive energy is -3.98 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/ManikandanD/chapter_1_.ipynb b/sample_notebooks/ManikandanD/chapter_1_.ipynb
new file mode 100755
index 00000000..e79571af
--- /dev/null
+++ b/sample_notebooks/ManikandanD/chapter_1_.ipynb
@@ -0,0 +1,256 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d769dfed1de81f32faa9bbbfcfead0c5e629ef3b47c5b247ff782d0972a27a01"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1:Bonding in Solids"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.3 , Page no:15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "r=2; #in angstrom(distance)\n",
+ "e=1.6E-19; # in C (charge of electron)\n",
+ "E_o= 8.85E-12;# absolute premittivity\n",
+ "\n",
+ "#calculate\n",
+ "r=2*1*10**-10; # since r is in angstrom\n",
+ "V=-e**2/(4*3.14*E_o*r); # calculate potential\n",
+ "V1=V/e; # changing to eV\n",
+ "\n",
+ "#result\n",
+ "print \"\\nThe potential energy is V = \",V,\"J\";\n",
+ "print \"In electron-Volt V = \",round(V,3),\"eV\"; \n",
+ "print \"Note: the answer in the book is wrong due to calculation mistake\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The potential energy is V = -1.15153477995e-18 J\n",
+ "In electron-Volt V = -0.0 eV\n",
+ "Note: the answer in the book is wrong due to calculation mistake\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.4 , Page no:15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "#given\n",
+ "r0=0.236; #in nanometer(interionic distance)\n",
+ "e=1.6E-19; # in C (charge of electron)\n",
+ "E_o= 8.85E-12;# absolute premittivity\n",
+ "N=8; # Born constant\n",
+ "IE=5.14;# in eV (ionisation energy of sodium)\n",
+ "EA=3.65;# in eV (electron affinity of Chlorine)\n",
+ "pi=3.14; # value of pi used in the solution\n",
+ "\n",
+ "#calculate\n",
+ "r0=r0*1E-9; # since r is in nanometer\n",
+ "PE=(e**2/(4*pi*E_o*r0))*(1-1/N); # calculate potential energy\n",
+ "PE=PE/e; #changing unit from J to eV\n",
+ "NE=IE-EA;# calculation of Net energy\n",
+ "BE=PE-NE;# calculation of Bond Energy\n",
+ "\n",
+ "#result\n",
+ "print\"The potential energy is PE= \",round(PE,2),\"eV\";\n",
+ "print\"The net energy is NE= \",round(NE,2),\"eV\";\n",
+ "print\"The bond energy is BE= \",round(BE,2),\"eV\";\n",
+ "# Note: (1)-In order to make the answer prcatically feasible and avoid the unusual answer, I have used r_0=0.236 nm instead of 236 nm. because using this value will give very much irrelevant answer.\n",
+ "# Note: (2) There is slight variation in the answer due to round off."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The potential energy is PE= 5.34 eV\n",
+ "The net energy is NE= 1.49 eV\n",
+ "The bond energy is BE= 3.85 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.5 , Page no:16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "r_0=.41; #in mm(lattice constant)\n",
+ "e=1.6E-19; #in C (charge of electron)\n",
+ "E_o= 8.85E-12; #absolute premittivity\n",
+ "n=0.5; #repulsive exponent value\n",
+ "alpha=1.76; #Madelung constant\n",
+ "pi=3.14; # value of pi used in the solution\n",
+ "\n",
+ "#calculate\n",
+ "r=.41*1E-3; #since r is in mm\n",
+ "Beta=72*pi*E_o*r**4/(alpha*e**2*(n-1)); #calculation compressibility\n",
+ "\n",
+ "#result\n",
+ "print\"The compressibility is\tBeta=\",round(Beta);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The compressibility is\tBeta= -2.50967916144e+15\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.6 , Page no:16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "r_0=3.56; #in Angstrom\n",
+ "e=1.6E-19; #in C (charge of electron)\n",
+ "IE=3.89; #in eV (ionisation energy of Cs)\n",
+ "EA=-3.61; #in eV (electron affinity of Cl)\n",
+ "n=10.5; #Born constant\n",
+ "E_o= 8.85E-12; #absolute premittivity\n",
+ "alpha=1.763; #Madelung constant\n",
+ "pi=3.14; #value of pi used in the solution\n",
+ "\n",
+ "#calculate\n",
+ "r_0=r_0*1E-10; #since r is in nanometer\n",
+ "U=-alpha*(e**2/(4*pi*E_o*r_0))*(1-1/n); #calculate potential energy\n",
+ "U=U/e; #changing unit from J to eV\n",
+ "ACE=U+EA+IE; #calculation of atomic cohesive energy\n",
+ "\n",
+ "#result\n",
+ "print\"The ionic cohesive energy is \",round(U),\"eV\";\n",
+ "print\"The atomic cohesive energy is\",round(ACE),\"eV\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The ionic cohesive energy is -6.0 eV\n",
+ "The atomic cohesive energy is -6.0 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7 , Page no:17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "r_0=2.81; #in Angstrom\n",
+ "e=1.6E-19; #in C (charge of electron)\n",
+ "n=9; #Born constant\n",
+ "E_o= 8.85E-12; #absolute premittivity\n",
+ "alpha=1.748; #Madelung constant\n",
+ "pi=3.14; #value of pi used in the solution\n",
+ "\n",
+ "#calculate\n",
+ "r_0=r_0*1E-10; #since r is in nanometer\n",
+ "V=-alpha*(e**2/(4*pi*E_o*r_0))*(1-1/n); #calculate potential energy\n",
+ "V=V/e; #changing unit from J to eV\n",
+ "V_1=V/2; #Since only half of the energy contribute per ion to the cohecive energy therfore\n",
+ "\n",
+ "#result\n",
+ "print\"The potential energy is V=\",round(V,2),\"eV\";\n",
+ "print\"The energy contributing per ions to the cohesive energy is \",round(V_1,2),\"eV\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The potential energy is V= -7.96 eV\n",
+ "The energy contributing per ions to the cohesive energy is -3.98 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/MayankSahu/Chapter1_.ipynb b/sample_notebooks/MayankSahu/Chapter1_.ipynb
new file mode 100755
index 00000000..530c71c7
--- /dev/null
+++ b/sample_notebooks/MayankSahu/Chapter1_.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "#Chapter1 : Concepts of electric current and Laws", "cell_type": "markdown", "metadata": {}}, {"source": "## Example1.1, Page number 4", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "#variable declaration\nL =12 #meter\nA=0.01*10**-4 #m**2\nR=0.2 #ohm\n\n#calculation\np=R*A/L #specific resistance\n\n#result\nprint \"specific resistance = \" , p, \"ohm-metre\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "specific resistance = 1.66666666667e-08 ohm-metre\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example1.2, Page number 5", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "\n#variable declaration\na0=0.0043 \nt1=27 #degree celsius\nt2=40\nR1=1.5 #ohm\n\n#calculation\nR2=R1*(1+a0*t2)/(1+a0*t1) #ohm\n\n#result\nprint \"The resistance of armature winding at 40 degree celcius =\" , round(R2,3) ,\"ohm\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The resistance of armature winding at 40 degree celcius = 1.575 ohm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example1.3, Page number 13", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "#variable decdlaration\nR1=5 #ohm \nR2=10\nR3=15\nV=120 #volt\n\n#calculation\nR=R1+R2+R3 #ohm\nI=V/R # ampere\nV1=I*R1 #volt\nV2=I*R2\nV3=I*R3\n\n#result\nprint \"Resistance = \" , R , \"ohm\"\nprint \"cureent = \" , I , \"amperes\"\nprint \"Voltage V1 = \" , V1 , \"volts\"\nprint \"Voltage V2 = \" , V2 , \"volts\"\nprint \"Voltage V3 = \" , V3 , \"volts\"\n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Resistance = 30 ohm\ncureent = 4 amperes\nVoltage V1 = 20 volts\nVoltage V2 = 40 volts\nVoltage V3 = 60 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example1.4, Page number 14", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "#varaiable declaration\nRab =(2.0*4.0)/(2+4) #ohms\nRbc =(6.0*8.0)/(6+8)\n\n#calculation\nRac = Rab+Rbc #ohms\n\n#result\nprint \"resistance across AC = \" , round(Rac,2) , \"ohms\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "resistance across AC = 4.76 ohms\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example1.5, Page number 14", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "#variable declaration\nRab=4 #ohm\nRbc=(12.0*8.0)/(12+8)\nRcd=(3.0*6.0)/(3+6)\n\n#calculation\nRad=Rab+Rbc+Rcd #ohm\n\n#result\nprint \"resistance across AC = \" , Rad, \"ohms\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "resistance across AC = 10.8 ohms\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example1.6, Page number 15", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "#variable declaration\nR1=8 #ohms\nR=6\n#calculations\nR2 = 48/2 # R = R1*R2/(R1+R2)\n\n#result\nprint \" Resistance R2 = \" , R2, \"ohms\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " Resistance R2 = 24 ohms\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example1.7, Page number 15", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "#variable declaration\nI=12.0 #ampere\nR1=6.0 #ohms\nR2=8.0\n\n#calculations\nI1=I*R2/(R1+R2) #amperes\nI2=I*R1/(R1+R2)\n\n#result\nprint \"I1= \" , round(I1,3) , \"amperes\" \nprint \"I2= \" , round(I2,2) , \"amperes\" \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "I1= 6.857 amperes\nI2= 5.14 amperes\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example1.9, Page number 17", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "#variable declaration\nR1=0.02 #ohms\nR2=0.03\nI = 10 #amperes\n\n#Calculations\nI1=(I*R2)/(R1+R2)\nI2=(I*R1)/(R1+R2)\n\n#result\nprint \" I1= \" , I1 , \"amperes \"\nprint \" I2= \" , I2 , \"amperes \" \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " I1= 6.0 amperes \n I2= 4.0 amperes \n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example1.10, Page number 18", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "#variable declaration\nV=200.0 #volts\nI=25.0 #amperes\nP1=1500.0 #watts\n\n#calculations \nR1=(V*V)/P1 #ohms\nR=V/I #total resistance\nR2=R*R1/(R1-R) #ohms\n\n#result\nprint \"R1 = \" ,round(R1,2) , \"ohms\" \nprint \"R2 = \" , round(R2,2) , \"ohms\" \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "R1 = 26.67 ohms\nR2 = 11.43 ohms\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example1.11, Page number 19", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "#variable declaration\nV=100.0 #volts \nP=1500.0 #watts\n\n#calculations\nR=(V**2/P)/2 #ohms\nRa=R\nRb=R\nRc=R\nR1=((Ra*Rc)/(Ra+Rc))+Rb\nI=V/R1 #amperes\nI1=(I*Ra)/(Ra+Rc)\nI2=(I*Ra)/(Ra+Rc)\nPb=I*I*Ra #watts\nPa=I1*I1*Rb\nPc=I2*I2*Rc\n\n#result\nprint \"power dissipated in coil Pa = \" , round(Pa,2) , \"watts\"\nprint \"power dissipated in coil Pb = \" , round(Pb,2), \"watts\"\nprint \"power dissipated in coil Pc = \" , round(Pc,2) , \"watts\"\n\n#Round off error in book \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "power dissipated in coil Pa = 333.33 watts\npower dissipated in coil Pb = 1333.33 watts\npower dissipated in coil Pc = 333.33 watts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example1.12, Page number 20", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "#variable declaration\nL=3600 #six lamp 1000 watt each for six days\nH=3000 # heater\nM=735.5 # single phase motor\nF=2400 #four fans 75W\nC=0.9 #cost of energy\n\n#Calculations\nT=L+H+M+F #total energy consumed in watt \nTE=T*30/1000\nB=TE*C #Bill amount in Rs\n\n#result\nprint \"Bill amount = Rs \" , round(B) \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Bill amount = Rs 263.0\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example1.18, Page number 34", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "#variable declaration\nRry=4.0 #ohm\nRyb=1.0\nRbr=5.0\n\n#calculation\nRr=(Rbr*Rry)/(Rry+Rbr+Ryb)\nRy=(Rry*Ryb)/(Rry+Rbr+Ryb)\nRb=(Rbr*Ryb)/(Rry+Rbr+Ryb)\n\n#result\nprint \"Rr = \" , Rr , \"ohms\"\nprint \"Ry = \" , Ry , \"ohms\"\nprint \"Rb= \" , Rb , \"ohms\"\n\n#Value of Rr in book is printed wrong \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Rr = 2.0 ohms\nRy = 0.4 ohms\nRb= 0.5 ohms\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example1.19, Page number 34", "cell_type": "markdown", "metadata": {}}, {"execution_count": 13, "cell_type": "code", "source": "#variable declaration\nRr=2.0 #ohms\nRy=0.67\nRb=1.0\n\n#calculations\nRry=(Rr*Ry)+(Ry*Rb)+(Rb*Rr)/Rb\nRyb=((Rr*Ry)+(Ry*Rb)+(Rb*Rr))/Rr\nRbr=((Rr*Ry)+(Ry*Rb)+(Rb*Rr))/Ry\n\n#result\nprint \"Rry = \" , round(Rry) , \"ohms\"\nprint \"Ryb = \" , round(Ryb) , \"ohms\"\nprint \"Rbr = \" , round(Rbr) , \"ohms\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Rry = 4.0 ohms\nRyb = 2.0 ohms\nRbr = 6.0 ohms\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.8", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/sample_notebooks/MayankSahu/Chapter5_.ipynb b/sample_notebooks/MayankSahu/Chapter5_.ipynb
new file mode 100755
index 00000000..7738b9ee
--- /dev/null
+++ b/sample_notebooks/MayankSahu/Chapter5_.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "#Chapter5 : Electrical Machines", "cell_type": "markdown", "metadata": {}}, {"source": "##Example 5.1 , Page number 178", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "#determine the induced emf in the armature\n\n#varaible declaration\nP=4 #poles\nA=2 #wave wound\nn=50 #number of slots\nSc=24 #slots/conductor\nN=600 #speed of armature \nF=10e-3 #webers\n\n#calculations\nZ=Sc*n #total conductor\nE=F*Z*N*P/(60*A) #emf induced\n\nprint \" emf induced E = \" , E , \"volts\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " emf induced E = 240.0 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.2 , Page number 178", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "#determine the induced emf in the armature\n\n#variable declaration\nP=4 #poles\nA=4 #wave wound\nn=50 #number of slots\nSc=24 #slots/conductor\nN=600 #rpm \nF=10e-3 #webers\n\n#calculations\nZ=Sc*n;#total conductor\nE=F*Z*N*P/(60*A) #emf induced\n\n#result\nprint \"e.m.f induced E = \" , E, \"volts\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "e.m.f induced E = 120.0 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.3 , Page number 179", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "#determine the speed\n\n#variable declaration\nP=6 #poles\nA1=2 #wave wound\nZ=780 #armature conductors\nF=12*10**-3 #webers \nE=400 #volt\nA2=6 #wave wound\n#calculation\nN=(E*60*A1)/(F*Z*P) #rpm\nN2=(E*60*A2)/(F*Z*P) #rpm\n\n#result\nprint \" Speed of the armature = \" , round(N,2) , \"rpm\"\nprint \" Speed when lap is wound = \" , round(N2,1) , \"rpm\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " Speed of the armature = 854.7 rpm\n Speed when lap is wound = 2564.1 rpm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.4 , Page number 182", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "#determine the emf induced\n\n#variable declaration\nR=0.5 #ohm\nRs=100.0 \nV=250.0 #volts\nP=10000.0 #watts\n\n#calculation\nI=P/V #ampere\nIs=V/Rs \nIa=I+Is \nEg=V+(R*Ia) #volts\n\n#result\nprint \" emf induced Eg = \" , Eg , \"volts\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " emf induced Eg = 271.25 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.5 , Page number 183", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "#calculate the emf induced in the armature\n\n#variable declaration\nIl=200 #amperes\nVl=500 #volts\nRa=0.03 #ohm\nRs=0.015\nR=150\nBCD=2 #one volt per brush\n\n#calculation\nI=Vl/R #ampere\nIa=Il+I \nEg=Vl+(Ia*Ra)+(Ia*Rs)+BCD #volts\n\n#result\nprint \" emf induced Eg = \" , round(Eg,2) , \"volts\"\n\n#round off error in book\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " emf induced Eg = 511.13 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.6 , Page number 184", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "#calculate the emf induced in the armature\n\n#variable declaration\nI1=200 #ampere\nVl=500 #volts\nRa=0.03 #ohm\nRs=0.015\nIs=200 #ampere\nR=150 #ohm\n\n#calculation\nBCD=2 #one volt per brush\nI=(Vl+(Is*Rs))/R #ampere\nIa = I1 + I\nEg=Vl+(Ia*Ra)+(Ia*Rs)+BCD #volts\n\n#result\nprint \" emf induced Eg = \" , round(Eg,2) ,\"volts\"\n\n#Error in book\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " emf induced Eg = 511.15 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.7 , Page number 196", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "#calculate the back emf induced on full load\n\n#variable declaration\nRa=0.5 #armature resistance\nRs=250 #shunt resistance\nVl=250 #line volt\nIl=40 #ampere\n\n#calculation\nIs=Vl/Rs #amperes\nIa=Il-Is\nEb=Vl-(Ia*Ra) #volts\n\n#result\nprint \"emf induced Eb = \", Eb, \"volts\" \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "emf induced Eb = 230.5 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.8 , Page number 196", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "#find the power developed in circiut\n\n#variable declaration\nPl=20e3 #watts\nVl=200.0 #volts \nRa=0.05 #ohms\nR=150.0\n\n#calculation\nI=Vl/R #ampere\nIl=Pl/Vl\nIa=Il+I\nEg=Vl+(Ia*Ra) #volts\nP=Eg*Ia #watts\n\n#result\nprint \"power developed = \" , round(P,2) , \"watt\"\n\n#round off error in book\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "power developed = 20780.09 watt\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.9 , Page number 197", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "#calculate the speed of the machine when running\n\n#variable declaration\nN1=1000 #speed of generator\nE1=205.06 #emf generator\nE2=195.06 #emf of motor\n\n#calculation\nN2=(E2*N1)/E1 #speed of generator\n\n#result\nprint\"speed of motor = \" , round(N2,2) ,\"rpm\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "speed of motor = 951.23 rpm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.10 , Page number 198", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "#dtermine its speed when its take crnt 25 amps\n\n#variable declaration\nVl=250.0 #volts\nRa=0.05 #ohm\nR=0.02 #ohm\nIa=30.0 #ampere\nI1=30.0\nN1=400.0\nI2=25.0\n\n#calculation\nE1=Vl-(Ia*Ra)-(Ia*R) #volts\nN2=(N1*E1*I1)/(E1*I2) #rpm\n\n#result\nprint \"speed of motor = \" , round(N2,2) ,\"rpm\"\n\n#round off error in book\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "speed of motor = 480.0 rpm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.11 , Page number 199", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "#find the torque whn its take scurnt 60amprs\n\n#variable declaration\nVl=200 #volts\nIl=60 #amperes\nR=50 #ohm\nf=0.03 # flux \nZ=700 #armature conductors\nP=4 #pole\nA=2\n\n#calculation\nI=Vl/R # amperes\nIa=Il-I #amperes\nT=(0.159*f*Z*Ia*P)/A\n\n#result\nprint \" Torque = \" , round(T,2) , \"N-m\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " Torque = 373.97 N-m\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.12 , Page number 214", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "#calcute the num of prim turns and prim $sec current\n\n#variable declaration\nKVA = 50.0\nE1 = 6000.0 #volts\nE2 = 250.0 #volts\nN2 = 52.0 #number of turns\n\n#calculation\nN1=N2*E1/E2\nI2=KVA*1000/E2 #ampere\nI1=KVA*1000/E1 #ampere\n\n#result\nprint \" primary number of turns = \" , N1 , \"turns\"\nprint \" secondary current = \" , I2, \"amperes\"\nprint \" primary current = \" , round(I1,2), \"amperes\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " primary number of turns = 1248.0 turns\n secondary current = 200.0 amperes\n primary current = 8.33 amperes\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.13 , Page number 215", "cell_type": "markdown", "metadata": {}}, {"execution_count": 13, "cell_type": "code", "source": "#determine the emf induced in the secondry max value of flux density\n\n#calculation\nf=50 #Hz\nN1=350 #turns\nN2=800 #turns\nE1=400 #volts\nA=75e-4 #m**2\n\n#calculation\nE2=(N2*E1)/N1 #volts\nBm=E1/(4.44*f*A*N1) #Wb/m**2\n\n#result\nprint \" flux density = \" , round(Bm,3) , \"wb/m**2\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " flux density = 0.686 wb/m**2\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.14 , Page number 215", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "import math\n\n#find the magnetic nd iron loss component of current\n\n#variable declaration\nE1=440 #volts\nE2=200 #volts\nI=0.2 #amperea\ncoso=0.18 #p.f.\n\n#calculation\nsino= math.sqrt(1-coso**2) \nIw=I*coso #ampere\nIu=I*sino #ampere\n\n#result\nprint \" Magnetising compenet of current = \" , round(Iw,3), \"amperes\"\nprint \" iron loss compenet of current = \" , round(Iu,4), \"amperes\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " Magnetising compenet of current = 0.036 amperes\n iron loss compenet of current = 0.1967 amperes\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.15 , Page number 216", "cell_type": "markdown", "metadata": {}}, {"execution_count": 15, "cell_type": "code", "source": "#calculate the efficiency at loads\n\n#variable declaration\nKVA=20\nIl=350 #iron loss\nCl=400 #copper loss\nx=1 # fraction of load\npf=0.8 # at full load\npf1=0.4 #at half load\nx1=0.5 #fraction of load\n\n#calculation\nop=KVA*1000*x*pf\nop1=KVA*1000*x1*pf1\nTl=Il+(Cl*x*x)\nTl1=Il+(Cl*x1*x1)\nip=op+Tl\nip1=op1+Tl1\nn=op/ip*100\nn1=op1/ip1*100\n\n#result\nprint \"efficiency at half load = \" , round(n,2) \nprint \"efficiency at full load = \" , round(n1,2) \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "efficiency at half load = 95.52\nefficiency at full load = 89.89\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.16 , Page number 221", "cell_type": "markdown", "metadata": {}}, {"execution_count": 16, "cell_type": "code", "source": "#calculate the synchronous speed ,slip,frequncy induced emf\n\n#variable declaration\nf=50.0 #Hz\np=4 #poles \nN=1460.0 #rpm\n\n#calculation\nNs=120*f/p #rpm\ns=(Ns-N)/Ns #slip\nf1=(s*f) #Hz\n\n#result\nprint \"synchronous speed Ns = \" , Ns , \"rpm\"\nprint \"slip s = \" , round(s,3)\nprint \" Frequency of rotor induced emf f = \" , round(f1,2) , \"Hz\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "synchronous speed Ns = 1500.0 rpm\nslip s = 0.027\n Frequency of rotor induced emf f = 1.33 Hz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.17 , Page number 222", "cell_type": "markdown", "metadata": {}}, {"execution_count": 17, "cell_type": "code", "source": "#determine the value of slip nd speed of motor\n\n#variable declaration\nP=6 #pole\nf=50 #Hz\nf1=1.5\n\n#calculation\nNs=120*f/P\ns=f1/f\nN=Ns*(1-s)\n\n#result\nprint \" speed of motor = \", N, \" RPM\"\nprint \" slip = \" , round(s,3)\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " speed of motor = 970.0 RPM\n slip = 0.03\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.18 , Page number 222", "cell_type": "markdown", "metadata": {}}, {"execution_count": 18, "cell_type": "code", "source": "#calculate the numbers of poles ,slip at full load,frequncy rotor,speed of motor\n\n#variable declaration\nNs=1000.0 #rpm\nN=960\nf=50 #Hz\n\n#calculation\nP=120*f/Ns #synchronous speed\ns=(Ns-N)/Ns #slip \nf1=s*f #Hz\nN=Ns*(1-0.08) #speed of motor at 8% slip\n\n#result\nprint \" number of poles p = \" , P\nprint \" slip s = \" , round(s,2)\nprint \" Frequency of rotor emf f = \" , f , \"Hz\"\nprint \" Speed of motor at 8% slip N = \" , N , \"RPM\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " number of poles p = 6.0\n slip s = 0.04\n Frequency of rotor emf f = 50 Hz\n Speed of motor at 8% slip N = 920.0 RPM\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.19 , Page number 231", "cell_type": "markdown", "metadata": {}}, {"execution_count": 19, "cell_type": "code", "source": "#calculate the induced emf per phase\n\n#variable declaration\nf=50 #Hz\nP=16 #poles\nN=160 #rpm\nS=6 #slip\nF=0.025 #flux\n\n#calculation\nn=N*S #conductors\nZ=n/3 \ne=2.22*F*f*Z #rms value\n\n#result\nprint \"Induced emf per phase e = \" , e , \"volts\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Induced emf per phase e = 888.0 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.8", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/sample_notebooks/MayankSahu/Chapter5__1.ipynb b/sample_notebooks/MayankSahu/Chapter5__1.ipynb
new file mode 100755
index 00000000..7738b9ee
--- /dev/null
+++ b/sample_notebooks/MayankSahu/Chapter5__1.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "#Chapter5 : Electrical Machines", "cell_type": "markdown", "metadata": {}}, {"source": "##Example 5.1 , Page number 178", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "#determine the induced emf in the armature\n\n#varaible declaration\nP=4 #poles\nA=2 #wave wound\nn=50 #number of slots\nSc=24 #slots/conductor\nN=600 #speed of armature \nF=10e-3 #webers\n\n#calculations\nZ=Sc*n #total conductor\nE=F*Z*N*P/(60*A) #emf induced\n\nprint \" emf induced E = \" , E , \"volts\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " emf induced E = 240.0 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.2 , Page number 178", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "#determine the induced emf in the armature\n\n#variable declaration\nP=4 #poles\nA=4 #wave wound\nn=50 #number of slots\nSc=24 #slots/conductor\nN=600 #rpm \nF=10e-3 #webers\n\n#calculations\nZ=Sc*n;#total conductor\nE=F*Z*N*P/(60*A) #emf induced\n\n#result\nprint \"e.m.f induced E = \" , E, \"volts\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "e.m.f induced E = 120.0 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.3 , Page number 179", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "#determine the speed\n\n#variable declaration\nP=6 #poles\nA1=2 #wave wound\nZ=780 #armature conductors\nF=12*10**-3 #webers \nE=400 #volt\nA2=6 #wave wound\n#calculation\nN=(E*60*A1)/(F*Z*P) #rpm\nN2=(E*60*A2)/(F*Z*P) #rpm\n\n#result\nprint \" Speed of the armature = \" , round(N,2) , \"rpm\"\nprint \" Speed when lap is wound = \" , round(N2,1) , \"rpm\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " Speed of the armature = 854.7 rpm\n Speed when lap is wound = 2564.1 rpm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.4 , Page number 182", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "#determine the emf induced\n\n#variable declaration\nR=0.5 #ohm\nRs=100.0 \nV=250.0 #volts\nP=10000.0 #watts\n\n#calculation\nI=P/V #ampere\nIs=V/Rs \nIa=I+Is \nEg=V+(R*Ia) #volts\n\n#result\nprint \" emf induced Eg = \" , Eg , \"volts\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " emf induced Eg = 271.25 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.5 , Page number 183", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "#calculate the emf induced in the armature\n\n#variable declaration\nIl=200 #amperes\nVl=500 #volts\nRa=0.03 #ohm\nRs=0.015\nR=150\nBCD=2 #one volt per brush\n\n#calculation\nI=Vl/R #ampere\nIa=Il+I \nEg=Vl+(Ia*Ra)+(Ia*Rs)+BCD #volts\n\n#result\nprint \" emf induced Eg = \" , round(Eg,2) , \"volts\"\n\n#round off error in book\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " emf induced Eg = 511.13 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.6 , Page number 184", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "#calculate the emf induced in the armature\n\n#variable declaration\nI1=200 #ampere\nVl=500 #volts\nRa=0.03 #ohm\nRs=0.015\nIs=200 #ampere\nR=150 #ohm\n\n#calculation\nBCD=2 #one volt per brush\nI=(Vl+(Is*Rs))/R #ampere\nIa = I1 + I\nEg=Vl+(Ia*Ra)+(Ia*Rs)+BCD #volts\n\n#result\nprint \" emf induced Eg = \" , round(Eg,2) ,\"volts\"\n\n#Error in book\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " emf induced Eg = 511.15 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.7 , Page number 196", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "#calculate the back emf induced on full load\n\n#variable declaration\nRa=0.5 #armature resistance\nRs=250 #shunt resistance\nVl=250 #line volt\nIl=40 #ampere\n\n#calculation\nIs=Vl/Rs #amperes\nIa=Il-Is\nEb=Vl-(Ia*Ra) #volts\n\n#result\nprint \"emf induced Eb = \", Eb, \"volts\" \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "emf induced Eb = 230.5 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.8 , Page number 196", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "#find the power developed in circiut\n\n#variable declaration\nPl=20e3 #watts\nVl=200.0 #volts \nRa=0.05 #ohms\nR=150.0\n\n#calculation\nI=Vl/R #ampere\nIl=Pl/Vl\nIa=Il+I\nEg=Vl+(Ia*Ra) #volts\nP=Eg*Ia #watts\n\n#result\nprint \"power developed = \" , round(P,2) , \"watt\"\n\n#round off error in book\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "power developed = 20780.09 watt\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.9 , Page number 197", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "#calculate the speed of the machine when running\n\n#variable declaration\nN1=1000 #speed of generator\nE1=205.06 #emf generator\nE2=195.06 #emf of motor\n\n#calculation\nN2=(E2*N1)/E1 #speed of generator\n\n#result\nprint\"speed of motor = \" , round(N2,2) ,\"rpm\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "speed of motor = 951.23 rpm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.10 , Page number 198", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "#dtermine its speed when its take crnt 25 amps\n\n#variable declaration\nVl=250.0 #volts\nRa=0.05 #ohm\nR=0.02 #ohm\nIa=30.0 #ampere\nI1=30.0\nN1=400.0\nI2=25.0\n\n#calculation\nE1=Vl-(Ia*Ra)-(Ia*R) #volts\nN2=(N1*E1*I1)/(E1*I2) #rpm\n\n#result\nprint \"speed of motor = \" , round(N2,2) ,\"rpm\"\n\n#round off error in book\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "speed of motor = 480.0 rpm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.11 , Page number 199", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "#find the torque whn its take scurnt 60amprs\n\n#variable declaration\nVl=200 #volts\nIl=60 #amperes\nR=50 #ohm\nf=0.03 # flux \nZ=700 #armature conductors\nP=4 #pole\nA=2\n\n#calculation\nI=Vl/R # amperes\nIa=Il-I #amperes\nT=(0.159*f*Z*Ia*P)/A\n\n#result\nprint \" Torque = \" , round(T,2) , \"N-m\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " Torque = 373.97 N-m\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.12 , Page number 214", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "#calcute the num of prim turns and prim $sec current\n\n#variable declaration\nKVA = 50.0\nE1 = 6000.0 #volts\nE2 = 250.0 #volts\nN2 = 52.0 #number of turns\n\n#calculation\nN1=N2*E1/E2\nI2=KVA*1000/E2 #ampere\nI1=KVA*1000/E1 #ampere\n\n#result\nprint \" primary number of turns = \" , N1 , \"turns\"\nprint \" secondary current = \" , I2, \"amperes\"\nprint \" primary current = \" , round(I1,2), \"amperes\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " primary number of turns = 1248.0 turns\n secondary current = 200.0 amperes\n primary current = 8.33 amperes\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.13 , Page number 215", "cell_type": "markdown", "metadata": {}}, {"execution_count": 13, "cell_type": "code", "source": "#determine the emf induced in the secondry max value of flux density\n\n#calculation\nf=50 #Hz\nN1=350 #turns\nN2=800 #turns\nE1=400 #volts\nA=75e-4 #m**2\n\n#calculation\nE2=(N2*E1)/N1 #volts\nBm=E1/(4.44*f*A*N1) #Wb/m**2\n\n#result\nprint \" flux density = \" , round(Bm,3) , \"wb/m**2\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " flux density = 0.686 wb/m**2\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.14 , Page number 215", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "import math\n\n#find the magnetic nd iron loss component of current\n\n#variable declaration\nE1=440 #volts\nE2=200 #volts\nI=0.2 #amperea\ncoso=0.18 #p.f.\n\n#calculation\nsino= math.sqrt(1-coso**2) \nIw=I*coso #ampere\nIu=I*sino #ampere\n\n#result\nprint \" Magnetising compenet of current = \" , round(Iw,3), \"amperes\"\nprint \" iron loss compenet of current = \" , round(Iu,4), \"amperes\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " Magnetising compenet of current = 0.036 amperes\n iron loss compenet of current = 0.1967 amperes\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.15 , Page number 216", "cell_type": "markdown", "metadata": {}}, {"execution_count": 15, "cell_type": "code", "source": "#calculate the efficiency at loads\n\n#variable declaration\nKVA=20\nIl=350 #iron loss\nCl=400 #copper loss\nx=1 # fraction of load\npf=0.8 # at full load\npf1=0.4 #at half load\nx1=0.5 #fraction of load\n\n#calculation\nop=KVA*1000*x*pf\nop1=KVA*1000*x1*pf1\nTl=Il+(Cl*x*x)\nTl1=Il+(Cl*x1*x1)\nip=op+Tl\nip1=op1+Tl1\nn=op/ip*100\nn1=op1/ip1*100\n\n#result\nprint \"efficiency at half load = \" , round(n,2) \nprint \"efficiency at full load = \" , round(n1,2) \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "efficiency at half load = 95.52\nefficiency at full load = 89.89\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.16 , Page number 221", "cell_type": "markdown", "metadata": {}}, {"execution_count": 16, "cell_type": "code", "source": "#calculate the synchronous speed ,slip,frequncy induced emf\n\n#variable declaration\nf=50.0 #Hz\np=4 #poles \nN=1460.0 #rpm\n\n#calculation\nNs=120*f/p #rpm\ns=(Ns-N)/Ns #slip\nf1=(s*f) #Hz\n\n#result\nprint \"synchronous speed Ns = \" , Ns , \"rpm\"\nprint \"slip s = \" , round(s,3)\nprint \" Frequency of rotor induced emf f = \" , round(f1,2) , \"Hz\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "synchronous speed Ns = 1500.0 rpm\nslip s = 0.027\n Frequency of rotor induced emf f = 1.33 Hz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.17 , Page number 222", "cell_type": "markdown", "metadata": {}}, {"execution_count": 17, "cell_type": "code", "source": "#determine the value of slip nd speed of motor\n\n#variable declaration\nP=6 #pole\nf=50 #Hz\nf1=1.5\n\n#calculation\nNs=120*f/P\ns=f1/f\nN=Ns*(1-s)\n\n#result\nprint \" speed of motor = \", N, \" RPM\"\nprint \" slip = \" , round(s,3)\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " speed of motor = 970.0 RPM\n slip = 0.03\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.18 , Page number 222", "cell_type": "markdown", "metadata": {}}, {"execution_count": 18, "cell_type": "code", "source": "#calculate the numbers of poles ,slip at full load,frequncy rotor,speed of motor\n\n#variable declaration\nNs=1000.0 #rpm\nN=960\nf=50 #Hz\n\n#calculation\nP=120*f/Ns #synchronous speed\ns=(Ns-N)/Ns #slip \nf1=s*f #Hz\nN=Ns*(1-0.08) #speed of motor at 8% slip\n\n#result\nprint \" number of poles p = \" , P\nprint \" slip s = \" , round(s,2)\nprint \" Frequency of rotor emf f = \" , f , \"Hz\"\nprint \" Speed of motor at 8% slip N = \" , N , \"RPM\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": " number of poles p = 6.0\n slip s = 0.04\n Frequency of rotor emf f = 50 Hz\n Speed of motor at 8% slip N = 920.0 RPM\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5.19 , Page number 231", "cell_type": "markdown", "metadata": {}}, {"execution_count": 19, "cell_type": "code", "source": "#calculate the induced emf per phase\n\n#variable declaration\nf=50 #Hz\nP=16 #poles\nN=160 #rpm\nS=6 #slip\nF=0.025 #flux\n\n#calculation\nn=N*S #conductors\nZ=n/3 \ne=2.22*F*f*Z #rms value\n\n#result\nprint \"Induced emf per phase e = \" , e , \"volts\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Induced emf per phase e = 888.0 volts\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.8", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/sample_notebooks/MohdAsif/Chapter2,_Measurement_Errors.ipynb b/sample_notebooks/MohdAsif/Chapter2,_Measurement_Errors.ipynb
new file mode 100755
index 00000000..f8ad79f0
--- /dev/null
+++ b/sample_notebooks/MohdAsif/Chapter2,_Measurement_Errors.ipynb
@@ -0,0 +1,257 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7b602763fd5a9c056abb62703a3bc42ae0cb4a39b3c349f78c056ebe58b1c643"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example 2_3_1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Precision of the 5th measurement\n",
+ "#Given data : Measurements taken(Unit less)\n",
+ "X1=98;\n",
+ "X2=101;\n",
+ "X3=102;\n",
+ "X4=97;\n",
+ "X5=101;\n",
+ "X6=100;\n",
+ "X7=103;\n",
+ "X8=98;\n",
+ "X9=106;\n",
+ "X10=99.0;\n",
+ "#Calculation\n",
+ "Xn_bar=(X1+X2+X3+X4+X5+X6+X7+X8+X9+X10)/10;\n",
+ "Xn=101 # value of 5th measurement\n",
+ "P=(1-abs((Xn-Xn_bar)/Xn_bar))*100 #Precision\n",
+ "print \"Precision of the 5th measurement,P(%) = \",round(P,3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Precision of the 5th measurement,P(%) = 99.502\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example 2_3_2_a"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Absolute error\n",
+ "#given data :\n",
+ "Ae=80.0 # in V\n",
+ "Am=79 # in V\n",
+ "e=Ae-Am #absolute error\n",
+ "print \"Absolute error,e(V) = \",e"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Absolute error,e(V) = 1.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example 2_3_2_b"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Finding error\n",
+ "#given data :\n",
+ "Ae=80.0 # in V\n",
+ "Am=79 # in V\n",
+ "e=Ae-Am #error\n",
+ "ep=(e/Ae)*100 #relative percent error\n",
+ "print \"Relative Percent Error(%) = \",ep"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Relative Percent Error(%) = 1.25\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example 2_3_3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# maximum error\n",
+ "#given data :\n",
+ "V1=100 # in volts\n",
+ "V2=200 # in volts\n",
+ "V=V2-V1 # Voltage difference\n",
+ "A=.25 # Accuracy may be \u00b1 in %\n",
+ "max_error=(A/100)*V # in Volts\n",
+ "print \"maximum error(V) = \u00b1\",max_error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum error(V) = \u00b1 0.25\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example 2_3_4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#sensitivity and deflection error\n",
+ "# given data :\n",
+ "C=4.0 # change in output in mm\n",
+ "M=8.0 # magnitude of input in ohm\n",
+ "S=C/M # sensitivity\n",
+ "print \"sensitivity,S(mm/ohm) = \",S\n",
+ "D=M/C # Deflection\n",
+ "print \"Deflection factor,D(ohm/m) = \",D"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "sensitivity,S(mm/ohm) = 0.5\n",
+ "Deflection factor,D(ohm/m) = 2.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example 2_3_5 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Resolution\n",
+ "# given data :\n",
+ "V=200.0 # full scale reading in volts\n",
+ "N=100.0 # number of divisions \n",
+ "Scale_div=V/N # Volts\n",
+ "R=(1/10.0)*Scale_div # Resolution in Volts\n",
+ "print \"Resolution, R(V) = \",round(R,4)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resolution, R(V) = 0.2\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example 2_3_6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Resolution\n",
+ "#given data :\n",
+ "V=9.999 # full scale read out in volt\n",
+ "c=range(0,9999) # range from 0 to 9999\n",
+ "R=(1/max(c))*V*10.0**3\n",
+ "print \"Resolution, R(mV)\", R"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resolution, R(mV) 0.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/MohdAsif/Chapter4.ipynb b/sample_notebooks/MohdAsif/Chapter4.ipynb
new file mode 100755
index 00000000..ac4db12d
--- /dev/null
+++ b/sample_notebooks/MohdAsif/Chapter4.ipynb
@@ -0,0 +1,216 @@
+{
+ "metadata": {
+ "Asif": "",
+ "signature": "sha256:721a6a2445404e28ea958d05a879e1927a64948a8c3a5aa0f2d75d58bb60d3b3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example 4.2.1\n",
+ "#given data :\n",
+ "E_rms=230; #Voltage rms value in V\n",
+ "Ep=2**(1/2)*E_rms; #peak amplitude\n",
+ "#Result\n",
+ "print\"peak amplitude,Ep(V) = \",Ep"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "peak amplitude,Ep(V) = 230\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example 4.12.1\n",
+ "#given data :\n",
+ "Rm=500; #in ohm\n",
+ "E_rms=50; # in V\n",
+ "E_dc=(2**(1/2)*E_rms)/(math.pi/2) # in V\n",
+ "Im=1*10^-3; #in A\n",
+ "R=E_dc/Im; #in ohm\n",
+ "Rs=(Rm-R)*10**(-3);#in ohm\n",
+ "#result\n",
+ "print\"the resistance,Rs(kohm) = \",round(Rs,4)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the resistance,Rs(kohm) = 0.5035\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example 4.14.1\n",
+ "ff1=1 #form factor\n",
+ "r=1.11 #sine wave form factor\n",
+ "error=((r-ff1)/ff1)*100 #percentage error\n",
+ "#result\n",
+ "print\"percentage error is\",error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "percentage error is 11.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example 4.19.1\n",
+ "#given data :\n",
+ "gm=0.005 #iConductance in mho\n",
+ "V1=1.5 #Voltage in V\n",
+ "rd=200*10**3 #resistance in Ohm\n",
+ "Rd=15*10**3 #resistance in Ohm\n",
+ "Rm=75 #resistance in Ohm\n",
+ "I=(gm*V1*((Rd*rd)/(rd+Rd)))/((2*((Rd*rd)/(rd+Rd)))+Rm)*10**3 #Current in mA\n",
+ "#result\n",
+ "print\"current,I(mA) = \",I"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "current,I(mA) = 3.73994853651\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example 4.19.3\n",
+ "v1=100 # in volts\n",
+ "v2=30 #in volts\n",
+ "v3=103 # in volts\n",
+ "v4=1 #in volts\n",
+ "x=9 #assume input resistance in Mohm\n",
+ "r4=(v4/v3)*x*10**3 #in kohms\n",
+ "r3=(((v4/v1)*x*10**6)-(r4*10**3))*10**(-3) #in kohms\n",
+ "r2=(((v4/v2)*x*10**6)-((r4+r3)*10**3))*10**(-3) # in kohms\n",
+ "r1=9*10**6-((r2+r3+r4)*10**3) #in ohms\n",
+ "r1=r1*10**(-6) # Mohm\n",
+ "print\"resistance (R4) in kohm is\",r4\n",
+ "print\"resistance (R3) in kohm is\",r3\n",
+ "print\"resistance (R2) in kohm is\",r2\n",
+ "print\"resistance (R1) in Mohm is\",r1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resistance (R4) in kohm is 0\n",
+ "resistance (R3) in kohm is 0.0\n",
+ "resistance (R2) in kohm is 0.0\n",
+ "resistance (R1) in Mohm is 9.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example 4.19.4\n",
+ "#given data :\n",
+ "rd=150*10**3 #in ohm\n",
+ "Rm=50 # in ohm\n",
+ "Rs=1000*10**3 #in ohm\n",
+ "gm=0.0052 #in mho\n",
+ "rd1=rd/((gm*rd)+1)\n",
+ "V0=gm*((rd1*Rs)/(rd1+Rs))\n",
+ "R0=(2*Rs*rd1)/(Rs+rd1)\n",
+ "I=V0/(R0+Rm)*10**3 #Current in mA\n",
+ "print\"curent,I(mA) = \",round(I,4)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "curent,I(mA) = 2.3005\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Example 4.19.5\n",
+ "#given data :\n",
+ "V1=1 #in V\n",
+ "I=1.5*10**-3 #in A\n",
+ "rd=200*10^3 # in ohm\n",
+ "Rm=50 # in ohm\n",
+ "Rs=600*10**3 # in ohm\n",
+ "gm=0.005 #in mho\n",
+ "rd1=rd/((gm*rd)+1)\n",
+ "V0=gm*((rd1*Rs)/(rd1+Rs))*V1\n",
+ "R0=(2*Rs*rd1)/(Rs+rd1)\n",
+ "R_cal=(V0/I)-Rm-R0;\n",
+ "print\"resistance ,R_cal(ohm) = \",round(R_cal,4)\n",
+ "# answer is wrong in the textbook"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resistance ,R_cal(ohm) = 192.3838\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI.ipynb b/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI.ipynb
new file mode 100755
index 00000000..e025dd86
--- /dev/null
+++ b/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI.ipynb
@@ -0,0 +1,462 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:02197244985b7dfa2823dacf9fac72c0a7536b50c383ffa1801ccf3066222ec3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Radiation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7.1, PAGE NO.-30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable declaration\n",
+ "\n",
+ "I_m = 15 #Current in Ampere\n",
+ "P_rad = 6 #Power radiated in kW\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "# By formula\n",
+ "I_rms = I_m/math.sqrt(2) #I_rms is r.m.s. current\n",
+ "\n",
+ "R_rad = P_rad/(I_rms**2) #R_rad is radiation resistance\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The radiation resistance of Antenna is\",round(R_rad*1000,2),\"kW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The radiation resistance of Antenna is 53.33 kW\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.1,PAGE NO.-42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sin,cos,pi,sqrt \n",
+ "from sympy import Symbol\n",
+ "\n",
+ "# Variable Declaration\n",
+ "\n",
+ "Lm = Symbol('Lm') # Taking lamda as Lm\n",
+ "dL = Lm/25 # Length of dipole for Hertian dipole\n",
+ "H_phi = 5 # Magnetic field strength in uA/m\n",
+ "theta = pi/2\n",
+ "r = 2 # Distance in Km\n",
+ "dL_1 = Lm/2 # Length of dipole for Half wave dipole \n",
+ "R_rad = 73 # Radiation resistance for half wave dipole in ohm\n",
+ "R_rad1 = 36.5 # Radiation resistance for quarter wave monopole in ohm\n",
+ "dL_2 = Lm/4 # Length of dipole for quarter wave monopole \n",
+ "\n",
+ "# Calculation\n",
+ "\n",
+ "# By formula : H_phi = I_m*dL*sin(theta)/2*Lm*r\n",
+ "I_m = (H_phi*2*Lm*r)/(dL*sin(theta))\n",
+ "I_rms = I_m/sqrt(2)\n",
+ "P_rad = 80*(pi**2)*((dL/Lm)**2)*(I_rms**2)\n",
+ "I_m1 = (H_phi*2*pi*r*sin(theta))/(cos(pi/2*cos(theta)))\n",
+ "I_rms1 = I_m1/sqrt(2)\n",
+ "P_rad1 = (I_rms1**2)*R_rad\n",
+ "P_rad2 = (I_rms1**2)*R_rad1\n",
+ "\n",
+ "# Result\n",
+ "\n",
+ "print \" The power radiated by hertzian dipole is \",round(P_rad*10**-3,2),\"mW\"\n",
+ "print \" The power radiated by half wave dipole is \",round(P_rad1*10**-3,2),\"mW\"\n",
+ "print \" The power radiated by Quarter wave monopole is \",round(P_rad2*10**-3,2),\"mW\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.2,PAGE NO.-43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sin,cos,pi,sqrt\n",
+ "\n",
+ "\n",
+ "\n",
+ "#variable declaration \n",
+ "\n",
+ "\n",
+ "E_theta = 10*(10**(-6)) #Electric field strength in V/m\n",
+ "theta = pi/2 #observation angle\n",
+ "r = 500*(10**3) #distance in metrs\n",
+ "f = 50*(10**6) #frequency in Hertz\n",
+ "c = 3*(10**8) #speed of light in m/sec\n",
+ "R_rad = 73 #for half wave dipole Radiation resistance in ohms\n",
+ "\n",
+ "\n",
+ "# calculation\n",
+ "lamda = c/f\n",
+ "L = lamda/2 #L is the length of half wave dipole\n",
+ "# formula : E=((60*I_m)/r)*((cos(pi/2*cos(theta)))*sin(theta))\n",
+ "I_m = (E_theta*r*sin(theta))/(60*cos(pi/2*cos(theta)))\n",
+ "I_rms = I_m/sqrt(2)\n",
+ "P_avg = (R_rad*(I_m**2))/2\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"Length of Dipole is\" ,round(L,2),\"metres\"\n",
+ "print \"Current fed to Antenna\",round(I_rms*1000,2),\"mA\"\n",
+ "print \"Average Power\",round(P_avg*1000,2),\"mW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.3,PAGE NO.-44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sqrt\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "l_eff = 100 #effective hieght in m\n",
+ "f = 60*(10**3) #frequency in Hertz\n",
+ "r = 100*(10**3) #Distance in m\n",
+ "c = 3*(10**8) #Speed of light in m/sec\n",
+ "P_rad = 100*(10**3) #radiated power\n",
+ "\n",
+ "# calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "R_rad = 160*(pi**2)*((l_eff/lamda)**2)\n",
+ "I_rms = sqrt(P_rad/R_rad)\n",
+ "E_rms = (120*pi*l_eff*(I_rms**2))/(lamda*r)\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print \"Strength of Electric field\",round(E_rms,2),\"V/m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.4,PAGE NO.-45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "l_eff = 113.3 #Effective length in metres\n",
+ "lamda = 18.8 #Wavelength in metres\n",
+ "I_rms = 725 #Base current in Ampere\n",
+ "r = 175 #Distance in metre\n",
+ "Eta_o = 120*pi\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "E = (120*pi*l_eff*I_rms)/(lamda*r)\n",
+ "H = E/Eta_o\n",
+ "R_rad = 160*(pi**2)*((l_eff/lamda)**2)\n",
+ "P_rad = (I_rms**2)*(R_rad)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The electric field at a distance r is \",round(E*0.001,2),\"mV/m\"\n",
+ "print \"The H field is\",round(H,2),\"uA/m\"\n",
+ "print \"The power radiated by Antenna is \",round(P_rad*(10**(-9)),2),\"kW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.5,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sin\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "lamda = 10*(10**(-2)) # In cm\n",
+ "r = 200*(10**(-2)) # In cm\n",
+ "theta = 90 # In Degrees\n",
+ "phi = 0 # In Degrees\n",
+ "IdL = 3*(10**(-4)) # current distribution in Am\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "E_theta = (60*pi*IdL*sin(theta))/(lamda*r)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The magnitude of component E_theta is \",round(E_theta,2),\"V/m\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.6,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "dL = lamda/12\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "R_rad = 80*(pi**2)*((dL/lamda)**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Radiation resistance of dipole antenna is \",round(R_rad,2),\"ohm\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.7,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sqrt\n",
+ "from sympy import Symbol\n",
+ "# variable declaration\n",
+ "\n",
+ "I_m = 100 # uniform current in ampere\n",
+ "Lm = Symbol('Lm') #Taking Lm as lamda\n",
+ "dL = Lm/16\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "P_rad = 80*(pi**2)*((dL/Lm)**2)*((I_m/sqrt(2))**2)\n",
+ "R_rad = 80*(pi**2)*((dL/Lm)**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Radiation resistance of dipole is \",round(R_rad,2),\"ohm\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.8,PAGE NO.-47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# variable declaration\n",
+ "\n",
+ "f = 30*(10**6) #Frequency in Hz\n",
+ "c = 3*(10**8) #speed of light in m/s\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Length of Half wave dipole is \",round((lamda/2),2),\"m\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.10,PAGE NO.-48"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sin,sqrt \n",
+ "from sympy import Symbol\n",
+ "# variable declaration\n",
+ "\n",
+ "Lm = Symbol('Lm') # Taking lamda as Lm\n",
+ "dL = 0.01*Lm # Length of dipole \n",
+ "theta = 45\n",
+ "P_rad = 1 # Power radiated in kW\n",
+ "phi = 90\n",
+ "r = 1 # Distance in Km\n",
+ "Eta_o=120*pi\n",
+ "\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "R_rad = 20*(pi**2)*((dL/Lm)**2)\n",
+ "I_m = sqrt(2*P_rad*R_rad)\n",
+ "\n",
+ "# formula : P = (Eta_o/2)*(((Omega*I_m*dL*sin(theta))/(4*pi*r*v))**2)\n",
+ "P = (Eta_o/2)*(((I_m*dL*sin(theta))/(4*pi*(r**2)))**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Power density is \",P,\"Watt/m^2\"\n",
+ "\n",
+ "# Note : The Solving in the book is wrong they put 0.1 instead of 0.1*lamda \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.11,PAGE NO.-49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi \n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "dL = 75 #Length of dipole in m\n",
+ "f = 800 # Frequency in kHz\n",
+ "I_rms = 10 #rms Current in Amp\n",
+ "c = 3*(10**8) #Speed of light in m/s \n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "P_rad = 80*(pi**2)*((dL/lamda)**2)*(I_rms**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Total Power radiated by Antenna is \",round(P_rad*1000,2),\"kW\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_1.ipynb b/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_1.ipynb
new file mode 100755
index 00000000..e025dd86
--- /dev/null
+++ b/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_1.ipynb
@@ -0,0 +1,462 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:02197244985b7dfa2823dacf9fac72c0a7536b50c383ffa1801ccf3066222ec3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Radiation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7.1, PAGE NO.-30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable declaration\n",
+ "\n",
+ "I_m = 15 #Current in Ampere\n",
+ "P_rad = 6 #Power radiated in kW\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "# By formula\n",
+ "I_rms = I_m/math.sqrt(2) #I_rms is r.m.s. current\n",
+ "\n",
+ "R_rad = P_rad/(I_rms**2) #R_rad is radiation resistance\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The radiation resistance of Antenna is\",round(R_rad*1000,2),\"kW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The radiation resistance of Antenna is 53.33 kW\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.1,PAGE NO.-42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sin,cos,pi,sqrt \n",
+ "from sympy import Symbol\n",
+ "\n",
+ "# Variable Declaration\n",
+ "\n",
+ "Lm = Symbol('Lm') # Taking lamda as Lm\n",
+ "dL = Lm/25 # Length of dipole for Hertian dipole\n",
+ "H_phi = 5 # Magnetic field strength in uA/m\n",
+ "theta = pi/2\n",
+ "r = 2 # Distance in Km\n",
+ "dL_1 = Lm/2 # Length of dipole for Half wave dipole \n",
+ "R_rad = 73 # Radiation resistance for half wave dipole in ohm\n",
+ "R_rad1 = 36.5 # Radiation resistance for quarter wave monopole in ohm\n",
+ "dL_2 = Lm/4 # Length of dipole for quarter wave monopole \n",
+ "\n",
+ "# Calculation\n",
+ "\n",
+ "# By formula : H_phi = I_m*dL*sin(theta)/2*Lm*r\n",
+ "I_m = (H_phi*2*Lm*r)/(dL*sin(theta))\n",
+ "I_rms = I_m/sqrt(2)\n",
+ "P_rad = 80*(pi**2)*((dL/Lm)**2)*(I_rms**2)\n",
+ "I_m1 = (H_phi*2*pi*r*sin(theta))/(cos(pi/2*cos(theta)))\n",
+ "I_rms1 = I_m1/sqrt(2)\n",
+ "P_rad1 = (I_rms1**2)*R_rad\n",
+ "P_rad2 = (I_rms1**2)*R_rad1\n",
+ "\n",
+ "# Result\n",
+ "\n",
+ "print \" The power radiated by hertzian dipole is \",round(P_rad*10**-3,2),\"mW\"\n",
+ "print \" The power radiated by half wave dipole is \",round(P_rad1*10**-3,2),\"mW\"\n",
+ "print \" The power radiated by Quarter wave monopole is \",round(P_rad2*10**-3,2),\"mW\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.2,PAGE NO.-43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sin,cos,pi,sqrt\n",
+ "\n",
+ "\n",
+ "\n",
+ "#variable declaration \n",
+ "\n",
+ "\n",
+ "E_theta = 10*(10**(-6)) #Electric field strength in V/m\n",
+ "theta = pi/2 #observation angle\n",
+ "r = 500*(10**3) #distance in metrs\n",
+ "f = 50*(10**6) #frequency in Hertz\n",
+ "c = 3*(10**8) #speed of light in m/sec\n",
+ "R_rad = 73 #for half wave dipole Radiation resistance in ohms\n",
+ "\n",
+ "\n",
+ "# calculation\n",
+ "lamda = c/f\n",
+ "L = lamda/2 #L is the length of half wave dipole\n",
+ "# formula : E=((60*I_m)/r)*((cos(pi/2*cos(theta)))*sin(theta))\n",
+ "I_m = (E_theta*r*sin(theta))/(60*cos(pi/2*cos(theta)))\n",
+ "I_rms = I_m/sqrt(2)\n",
+ "P_avg = (R_rad*(I_m**2))/2\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"Length of Dipole is\" ,round(L,2),\"metres\"\n",
+ "print \"Current fed to Antenna\",round(I_rms*1000,2),\"mA\"\n",
+ "print \"Average Power\",round(P_avg*1000,2),\"mW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.3,PAGE NO.-44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sqrt\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "l_eff = 100 #effective hieght in m\n",
+ "f = 60*(10**3) #frequency in Hertz\n",
+ "r = 100*(10**3) #Distance in m\n",
+ "c = 3*(10**8) #Speed of light in m/sec\n",
+ "P_rad = 100*(10**3) #radiated power\n",
+ "\n",
+ "# calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "R_rad = 160*(pi**2)*((l_eff/lamda)**2)\n",
+ "I_rms = sqrt(P_rad/R_rad)\n",
+ "E_rms = (120*pi*l_eff*(I_rms**2))/(lamda*r)\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print \"Strength of Electric field\",round(E_rms,2),\"V/m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.4,PAGE NO.-45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "l_eff = 113.3 #Effective length in metres\n",
+ "lamda = 18.8 #Wavelength in metres\n",
+ "I_rms = 725 #Base current in Ampere\n",
+ "r = 175 #Distance in metre\n",
+ "Eta_o = 120*pi\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "E = (120*pi*l_eff*I_rms)/(lamda*r)\n",
+ "H = E/Eta_o\n",
+ "R_rad = 160*(pi**2)*((l_eff/lamda)**2)\n",
+ "P_rad = (I_rms**2)*(R_rad)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The electric field at a distance r is \",round(E*0.001,2),\"mV/m\"\n",
+ "print \"The H field is\",round(H,2),\"uA/m\"\n",
+ "print \"The power radiated by Antenna is \",round(P_rad*(10**(-9)),2),\"kW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.5,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sin\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "lamda = 10*(10**(-2)) # In cm\n",
+ "r = 200*(10**(-2)) # In cm\n",
+ "theta = 90 # In Degrees\n",
+ "phi = 0 # In Degrees\n",
+ "IdL = 3*(10**(-4)) # current distribution in Am\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "E_theta = (60*pi*IdL*sin(theta))/(lamda*r)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The magnitude of component E_theta is \",round(E_theta,2),\"V/m\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.6,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "dL = lamda/12\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "R_rad = 80*(pi**2)*((dL/lamda)**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Radiation resistance of dipole antenna is \",round(R_rad,2),\"ohm\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.7,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sqrt\n",
+ "from sympy import Symbol\n",
+ "# variable declaration\n",
+ "\n",
+ "I_m = 100 # uniform current in ampere\n",
+ "Lm = Symbol('Lm') #Taking Lm as lamda\n",
+ "dL = Lm/16\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "P_rad = 80*(pi**2)*((dL/Lm)**2)*((I_m/sqrt(2))**2)\n",
+ "R_rad = 80*(pi**2)*((dL/Lm)**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Radiation resistance of dipole is \",round(R_rad,2),\"ohm\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.8,PAGE NO.-47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# variable declaration\n",
+ "\n",
+ "f = 30*(10**6) #Frequency in Hz\n",
+ "c = 3*(10**8) #speed of light in m/s\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Length of Half wave dipole is \",round((lamda/2),2),\"m\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.10,PAGE NO.-48"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sin,sqrt \n",
+ "from sympy import Symbol\n",
+ "# variable declaration\n",
+ "\n",
+ "Lm = Symbol('Lm') # Taking lamda as Lm\n",
+ "dL = 0.01*Lm # Length of dipole \n",
+ "theta = 45\n",
+ "P_rad = 1 # Power radiated in kW\n",
+ "phi = 90\n",
+ "r = 1 # Distance in Km\n",
+ "Eta_o=120*pi\n",
+ "\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "R_rad = 20*(pi**2)*((dL/Lm)**2)\n",
+ "I_m = sqrt(2*P_rad*R_rad)\n",
+ "\n",
+ "# formula : P = (Eta_o/2)*(((Omega*I_m*dL*sin(theta))/(4*pi*r*v))**2)\n",
+ "P = (Eta_o/2)*(((I_m*dL*sin(theta))/(4*pi*(r**2)))**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Power density is \",P,\"Watt/m^2\"\n",
+ "\n",
+ "# Note : The Solving in the book is wrong they put 0.1 instead of 0.1*lamda \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.11,PAGE NO.-49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi \n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "dL = 75 #Length of dipole in m\n",
+ "f = 800 # Frequency in kHz\n",
+ "I_rms = 10 #rms Current in Amp\n",
+ "c = 3*(10**8) #Speed of light in m/s \n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "P_rad = 80*(pi**2)*((dL/lamda)**2)*(I_rms**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Total Power radiated by Antenna is \",round(P_rad*1000,2),\"kW\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_2.ipynb b/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_2.ipynb
new file mode 100755
index 00000000..e025dd86
--- /dev/null
+++ b/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_2.ipynb
@@ -0,0 +1,462 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:02197244985b7dfa2823dacf9fac72c0a7536b50c383ffa1801ccf3066222ec3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Radiation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7.1, PAGE NO.-30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable declaration\n",
+ "\n",
+ "I_m = 15 #Current in Ampere\n",
+ "P_rad = 6 #Power radiated in kW\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "# By formula\n",
+ "I_rms = I_m/math.sqrt(2) #I_rms is r.m.s. current\n",
+ "\n",
+ "R_rad = P_rad/(I_rms**2) #R_rad is radiation resistance\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The radiation resistance of Antenna is\",round(R_rad*1000,2),\"kW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The radiation resistance of Antenna is 53.33 kW\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.1,PAGE NO.-42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sin,cos,pi,sqrt \n",
+ "from sympy import Symbol\n",
+ "\n",
+ "# Variable Declaration\n",
+ "\n",
+ "Lm = Symbol('Lm') # Taking lamda as Lm\n",
+ "dL = Lm/25 # Length of dipole for Hertian dipole\n",
+ "H_phi = 5 # Magnetic field strength in uA/m\n",
+ "theta = pi/2\n",
+ "r = 2 # Distance in Km\n",
+ "dL_1 = Lm/2 # Length of dipole for Half wave dipole \n",
+ "R_rad = 73 # Radiation resistance for half wave dipole in ohm\n",
+ "R_rad1 = 36.5 # Radiation resistance for quarter wave monopole in ohm\n",
+ "dL_2 = Lm/4 # Length of dipole for quarter wave monopole \n",
+ "\n",
+ "# Calculation\n",
+ "\n",
+ "# By formula : H_phi = I_m*dL*sin(theta)/2*Lm*r\n",
+ "I_m = (H_phi*2*Lm*r)/(dL*sin(theta))\n",
+ "I_rms = I_m/sqrt(2)\n",
+ "P_rad = 80*(pi**2)*((dL/Lm)**2)*(I_rms**2)\n",
+ "I_m1 = (H_phi*2*pi*r*sin(theta))/(cos(pi/2*cos(theta)))\n",
+ "I_rms1 = I_m1/sqrt(2)\n",
+ "P_rad1 = (I_rms1**2)*R_rad\n",
+ "P_rad2 = (I_rms1**2)*R_rad1\n",
+ "\n",
+ "# Result\n",
+ "\n",
+ "print \" The power radiated by hertzian dipole is \",round(P_rad*10**-3,2),\"mW\"\n",
+ "print \" The power radiated by half wave dipole is \",round(P_rad1*10**-3,2),\"mW\"\n",
+ "print \" The power radiated by Quarter wave monopole is \",round(P_rad2*10**-3,2),\"mW\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.2,PAGE NO.-43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sin,cos,pi,sqrt\n",
+ "\n",
+ "\n",
+ "\n",
+ "#variable declaration \n",
+ "\n",
+ "\n",
+ "E_theta = 10*(10**(-6)) #Electric field strength in V/m\n",
+ "theta = pi/2 #observation angle\n",
+ "r = 500*(10**3) #distance in metrs\n",
+ "f = 50*(10**6) #frequency in Hertz\n",
+ "c = 3*(10**8) #speed of light in m/sec\n",
+ "R_rad = 73 #for half wave dipole Radiation resistance in ohms\n",
+ "\n",
+ "\n",
+ "# calculation\n",
+ "lamda = c/f\n",
+ "L = lamda/2 #L is the length of half wave dipole\n",
+ "# formula : E=((60*I_m)/r)*((cos(pi/2*cos(theta)))*sin(theta))\n",
+ "I_m = (E_theta*r*sin(theta))/(60*cos(pi/2*cos(theta)))\n",
+ "I_rms = I_m/sqrt(2)\n",
+ "P_avg = (R_rad*(I_m**2))/2\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"Length of Dipole is\" ,round(L,2),\"metres\"\n",
+ "print \"Current fed to Antenna\",round(I_rms*1000,2),\"mA\"\n",
+ "print \"Average Power\",round(P_avg*1000,2),\"mW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.3,PAGE NO.-44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sqrt\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "l_eff = 100 #effective hieght in m\n",
+ "f = 60*(10**3) #frequency in Hertz\n",
+ "r = 100*(10**3) #Distance in m\n",
+ "c = 3*(10**8) #Speed of light in m/sec\n",
+ "P_rad = 100*(10**3) #radiated power\n",
+ "\n",
+ "# calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "R_rad = 160*(pi**2)*((l_eff/lamda)**2)\n",
+ "I_rms = sqrt(P_rad/R_rad)\n",
+ "E_rms = (120*pi*l_eff*(I_rms**2))/(lamda*r)\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print \"Strength of Electric field\",round(E_rms,2),\"V/m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.4,PAGE NO.-45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "l_eff = 113.3 #Effective length in metres\n",
+ "lamda = 18.8 #Wavelength in metres\n",
+ "I_rms = 725 #Base current in Ampere\n",
+ "r = 175 #Distance in metre\n",
+ "Eta_o = 120*pi\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "E = (120*pi*l_eff*I_rms)/(lamda*r)\n",
+ "H = E/Eta_o\n",
+ "R_rad = 160*(pi**2)*((l_eff/lamda)**2)\n",
+ "P_rad = (I_rms**2)*(R_rad)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The electric field at a distance r is \",round(E*0.001,2),\"mV/m\"\n",
+ "print \"The H field is\",round(H,2),\"uA/m\"\n",
+ "print \"The power radiated by Antenna is \",round(P_rad*(10**(-9)),2),\"kW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.5,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sin\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "lamda = 10*(10**(-2)) # In cm\n",
+ "r = 200*(10**(-2)) # In cm\n",
+ "theta = 90 # In Degrees\n",
+ "phi = 0 # In Degrees\n",
+ "IdL = 3*(10**(-4)) # current distribution in Am\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "E_theta = (60*pi*IdL*sin(theta))/(lamda*r)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The magnitude of component E_theta is \",round(E_theta,2),\"V/m\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.6,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "dL = lamda/12\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "R_rad = 80*(pi**2)*((dL/lamda)**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Radiation resistance of dipole antenna is \",round(R_rad,2),\"ohm\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.7,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sqrt\n",
+ "from sympy import Symbol\n",
+ "# variable declaration\n",
+ "\n",
+ "I_m = 100 # uniform current in ampere\n",
+ "Lm = Symbol('Lm') #Taking Lm as lamda\n",
+ "dL = Lm/16\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "P_rad = 80*(pi**2)*((dL/Lm)**2)*((I_m/sqrt(2))**2)\n",
+ "R_rad = 80*(pi**2)*((dL/Lm)**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Radiation resistance of dipole is \",round(R_rad,2),\"ohm\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.8,PAGE NO.-47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# variable declaration\n",
+ "\n",
+ "f = 30*(10**6) #Frequency in Hz\n",
+ "c = 3*(10**8) #speed of light in m/s\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Length of Half wave dipole is \",round((lamda/2),2),\"m\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.10,PAGE NO.-48"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sin,sqrt \n",
+ "from sympy import Symbol\n",
+ "# variable declaration\n",
+ "\n",
+ "Lm = Symbol('Lm') # Taking lamda as Lm\n",
+ "dL = 0.01*Lm # Length of dipole \n",
+ "theta = 45\n",
+ "P_rad = 1 # Power radiated in kW\n",
+ "phi = 90\n",
+ "r = 1 # Distance in Km\n",
+ "Eta_o=120*pi\n",
+ "\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "R_rad = 20*(pi**2)*((dL/Lm)**2)\n",
+ "I_m = sqrt(2*P_rad*R_rad)\n",
+ "\n",
+ "# formula : P = (Eta_o/2)*(((Omega*I_m*dL*sin(theta))/(4*pi*r*v))**2)\n",
+ "P = (Eta_o/2)*(((I_m*dL*sin(theta))/(4*pi*(r**2)))**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Power density is \",P,\"Watt/m^2\"\n",
+ "\n",
+ "# Note : The Solving in the book is wrong they put 0.1 instead of 0.1*lamda \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.11,PAGE NO.-49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi \n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "dL = 75 #Length of dipole in m\n",
+ "f = 800 # Frequency in kHz\n",
+ "I_rms = 10 #rms Current in Amp\n",
+ "c = 3*(10**8) #Speed of light in m/s \n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "P_rad = 80*(pi**2)*((dL/lamda)**2)*(I_rms**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Total Power radiated by Antenna is \",round(P_rad*1000,2),\"kW\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_3.ipynb b/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_3.ipynb
new file mode 100755
index 00000000..e025dd86
--- /dev/null
+++ b/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_3.ipynb
@@ -0,0 +1,462 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:02197244985b7dfa2823dacf9fac72c0a7536b50c383ffa1801ccf3066222ec3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Radiation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7.1, PAGE NO.-30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable declaration\n",
+ "\n",
+ "I_m = 15 #Current in Ampere\n",
+ "P_rad = 6 #Power radiated in kW\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "# By formula\n",
+ "I_rms = I_m/math.sqrt(2) #I_rms is r.m.s. current\n",
+ "\n",
+ "R_rad = P_rad/(I_rms**2) #R_rad is radiation resistance\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The radiation resistance of Antenna is\",round(R_rad*1000,2),\"kW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The radiation resistance of Antenna is 53.33 kW\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.1,PAGE NO.-42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sin,cos,pi,sqrt \n",
+ "from sympy import Symbol\n",
+ "\n",
+ "# Variable Declaration\n",
+ "\n",
+ "Lm = Symbol('Lm') # Taking lamda as Lm\n",
+ "dL = Lm/25 # Length of dipole for Hertian dipole\n",
+ "H_phi = 5 # Magnetic field strength in uA/m\n",
+ "theta = pi/2\n",
+ "r = 2 # Distance in Km\n",
+ "dL_1 = Lm/2 # Length of dipole for Half wave dipole \n",
+ "R_rad = 73 # Radiation resistance for half wave dipole in ohm\n",
+ "R_rad1 = 36.5 # Radiation resistance for quarter wave monopole in ohm\n",
+ "dL_2 = Lm/4 # Length of dipole for quarter wave monopole \n",
+ "\n",
+ "# Calculation\n",
+ "\n",
+ "# By formula : H_phi = I_m*dL*sin(theta)/2*Lm*r\n",
+ "I_m = (H_phi*2*Lm*r)/(dL*sin(theta))\n",
+ "I_rms = I_m/sqrt(2)\n",
+ "P_rad = 80*(pi**2)*((dL/Lm)**2)*(I_rms**2)\n",
+ "I_m1 = (H_phi*2*pi*r*sin(theta))/(cos(pi/2*cos(theta)))\n",
+ "I_rms1 = I_m1/sqrt(2)\n",
+ "P_rad1 = (I_rms1**2)*R_rad\n",
+ "P_rad2 = (I_rms1**2)*R_rad1\n",
+ "\n",
+ "# Result\n",
+ "\n",
+ "print \" The power radiated by hertzian dipole is \",round(P_rad*10**-3,2),\"mW\"\n",
+ "print \" The power radiated by half wave dipole is \",round(P_rad1*10**-3,2),\"mW\"\n",
+ "print \" The power radiated by Quarter wave monopole is \",round(P_rad2*10**-3,2),\"mW\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.2,PAGE NO.-43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sin,cos,pi,sqrt\n",
+ "\n",
+ "\n",
+ "\n",
+ "#variable declaration \n",
+ "\n",
+ "\n",
+ "E_theta = 10*(10**(-6)) #Electric field strength in V/m\n",
+ "theta = pi/2 #observation angle\n",
+ "r = 500*(10**3) #distance in metrs\n",
+ "f = 50*(10**6) #frequency in Hertz\n",
+ "c = 3*(10**8) #speed of light in m/sec\n",
+ "R_rad = 73 #for half wave dipole Radiation resistance in ohms\n",
+ "\n",
+ "\n",
+ "# calculation\n",
+ "lamda = c/f\n",
+ "L = lamda/2 #L is the length of half wave dipole\n",
+ "# formula : E=((60*I_m)/r)*((cos(pi/2*cos(theta)))*sin(theta))\n",
+ "I_m = (E_theta*r*sin(theta))/(60*cos(pi/2*cos(theta)))\n",
+ "I_rms = I_m/sqrt(2)\n",
+ "P_avg = (R_rad*(I_m**2))/2\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"Length of Dipole is\" ,round(L,2),\"metres\"\n",
+ "print \"Current fed to Antenna\",round(I_rms*1000,2),\"mA\"\n",
+ "print \"Average Power\",round(P_avg*1000,2),\"mW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.3,PAGE NO.-44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sqrt\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "l_eff = 100 #effective hieght in m\n",
+ "f = 60*(10**3) #frequency in Hertz\n",
+ "r = 100*(10**3) #Distance in m\n",
+ "c = 3*(10**8) #Speed of light in m/sec\n",
+ "P_rad = 100*(10**3) #radiated power\n",
+ "\n",
+ "# calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "R_rad = 160*(pi**2)*((l_eff/lamda)**2)\n",
+ "I_rms = sqrt(P_rad/R_rad)\n",
+ "E_rms = (120*pi*l_eff*(I_rms**2))/(lamda*r)\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print \"Strength of Electric field\",round(E_rms,2),\"V/m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.4,PAGE NO.-45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "l_eff = 113.3 #Effective length in metres\n",
+ "lamda = 18.8 #Wavelength in metres\n",
+ "I_rms = 725 #Base current in Ampere\n",
+ "r = 175 #Distance in metre\n",
+ "Eta_o = 120*pi\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "E = (120*pi*l_eff*I_rms)/(lamda*r)\n",
+ "H = E/Eta_o\n",
+ "R_rad = 160*(pi**2)*((l_eff/lamda)**2)\n",
+ "P_rad = (I_rms**2)*(R_rad)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The electric field at a distance r is \",round(E*0.001,2),\"mV/m\"\n",
+ "print \"The H field is\",round(H,2),\"uA/m\"\n",
+ "print \"The power radiated by Antenna is \",round(P_rad*(10**(-9)),2),\"kW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.5,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sin\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "lamda = 10*(10**(-2)) # In cm\n",
+ "r = 200*(10**(-2)) # In cm\n",
+ "theta = 90 # In Degrees\n",
+ "phi = 0 # In Degrees\n",
+ "IdL = 3*(10**(-4)) # current distribution in Am\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "E_theta = (60*pi*IdL*sin(theta))/(lamda*r)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The magnitude of component E_theta is \",round(E_theta,2),\"V/m\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.6,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "dL = lamda/12\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "R_rad = 80*(pi**2)*((dL/lamda)**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Radiation resistance of dipole antenna is \",round(R_rad,2),\"ohm\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.7,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sqrt\n",
+ "from sympy import Symbol\n",
+ "# variable declaration\n",
+ "\n",
+ "I_m = 100 # uniform current in ampere\n",
+ "Lm = Symbol('Lm') #Taking Lm as lamda\n",
+ "dL = Lm/16\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "P_rad = 80*(pi**2)*((dL/Lm)**2)*((I_m/sqrt(2))**2)\n",
+ "R_rad = 80*(pi**2)*((dL/Lm)**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Radiation resistance of dipole is \",round(R_rad,2),\"ohm\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.8,PAGE NO.-47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# variable declaration\n",
+ "\n",
+ "f = 30*(10**6) #Frequency in Hz\n",
+ "c = 3*(10**8) #speed of light in m/s\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Length of Half wave dipole is \",round((lamda/2),2),\"m\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.10,PAGE NO.-48"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sin,sqrt \n",
+ "from sympy import Symbol\n",
+ "# variable declaration\n",
+ "\n",
+ "Lm = Symbol('Lm') # Taking lamda as Lm\n",
+ "dL = 0.01*Lm # Length of dipole \n",
+ "theta = 45\n",
+ "P_rad = 1 # Power radiated in kW\n",
+ "phi = 90\n",
+ "r = 1 # Distance in Km\n",
+ "Eta_o=120*pi\n",
+ "\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "R_rad = 20*(pi**2)*((dL/Lm)**2)\n",
+ "I_m = sqrt(2*P_rad*R_rad)\n",
+ "\n",
+ "# formula : P = (Eta_o/2)*(((Omega*I_m*dL*sin(theta))/(4*pi*r*v))**2)\n",
+ "P = (Eta_o/2)*(((I_m*dL*sin(theta))/(4*pi*(r**2)))**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Power density is \",P,\"Watt/m^2\"\n",
+ "\n",
+ "# Note : The Solving in the book is wrong they put 0.1 instead of 0.1*lamda \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.11,PAGE NO.-49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi \n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "dL = 75 #Length of dipole in m\n",
+ "f = 800 # Frequency in kHz\n",
+ "I_rms = 10 #rms Current in Amp\n",
+ "c = 3*(10**8) #Speed of light in m/s \n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "P_rad = 80*(pi**2)*((dL/lamda)**2)*(I_rms**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Total Power radiated by Antenna is \",round(P_rad*1000,2),\"kW\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_4.ipynb b/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_4.ipynb
new file mode 100755
index 00000000..e025dd86
--- /dev/null
+++ b/sample_notebooks/NIKHILESH DAMLE/ANTENNAS_AND_WAVE_PROPAGATION_BY_U.A_BAKSHI,_A.V_BAKSHI,_K.A_BAKSHI_4.ipynb
@@ -0,0 +1,462 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:02197244985b7dfa2823dacf9fac72c0a7536b50c383ffa1801ccf3066222ec3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Radiation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7.1, PAGE NO.-30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Variable declaration\n",
+ "\n",
+ "I_m = 15 #Current in Ampere\n",
+ "P_rad = 6 #Power radiated in kW\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "# By formula\n",
+ "I_rms = I_m/math.sqrt(2) #I_rms is r.m.s. current\n",
+ "\n",
+ "R_rad = P_rad/(I_rms**2) #R_rad is radiation resistance\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The radiation resistance of Antenna is\",round(R_rad*1000,2),\"kW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The radiation resistance of Antenna is 53.33 kW\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.1,PAGE NO.-42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sin,cos,pi,sqrt \n",
+ "from sympy import Symbol\n",
+ "\n",
+ "# Variable Declaration\n",
+ "\n",
+ "Lm = Symbol('Lm') # Taking lamda as Lm\n",
+ "dL = Lm/25 # Length of dipole for Hertian dipole\n",
+ "H_phi = 5 # Magnetic field strength in uA/m\n",
+ "theta = pi/2\n",
+ "r = 2 # Distance in Km\n",
+ "dL_1 = Lm/2 # Length of dipole for Half wave dipole \n",
+ "R_rad = 73 # Radiation resistance for half wave dipole in ohm\n",
+ "R_rad1 = 36.5 # Radiation resistance for quarter wave monopole in ohm\n",
+ "dL_2 = Lm/4 # Length of dipole for quarter wave monopole \n",
+ "\n",
+ "# Calculation\n",
+ "\n",
+ "# By formula : H_phi = I_m*dL*sin(theta)/2*Lm*r\n",
+ "I_m = (H_phi*2*Lm*r)/(dL*sin(theta))\n",
+ "I_rms = I_m/sqrt(2)\n",
+ "P_rad = 80*(pi**2)*((dL/Lm)**2)*(I_rms**2)\n",
+ "I_m1 = (H_phi*2*pi*r*sin(theta))/(cos(pi/2*cos(theta)))\n",
+ "I_rms1 = I_m1/sqrt(2)\n",
+ "P_rad1 = (I_rms1**2)*R_rad\n",
+ "P_rad2 = (I_rms1**2)*R_rad1\n",
+ "\n",
+ "# Result\n",
+ "\n",
+ "print \" The power radiated by hertzian dipole is \",round(P_rad*10**-3,2),\"mW\"\n",
+ "print \" The power radiated by half wave dipole is \",round(P_rad1*10**-3,2),\"mW\"\n",
+ "print \" The power radiated by Quarter wave monopole is \",round(P_rad2*10**-3,2),\"mW\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.2,PAGE NO.-43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sin,cos,pi,sqrt\n",
+ "\n",
+ "\n",
+ "\n",
+ "#variable declaration \n",
+ "\n",
+ "\n",
+ "E_theta = 10*(10**(-6)) #Electric field strength in V/m\n",
+ "theta = pi/2 #observation angle\n",
+ "r = 500*(10**3) #distance in metrs\n",
+ "f = 50*(10**6) #frequency in Hertz\n",
+ "c = 3*(10**8) #speed of light in m/sec\n",
+ "R_rad = 73 #for half wave dipole Radiation resistance in ohms\n",
+ "\n",
+ "\n",
+ "# calculation\n",
+ "lamda = c/f\n",
+ "L = lamda/2 #L is the length of half wave dipole\n",
+ "# formula : E=((60*I_m)/r)*((cos(pi/2*cos(theta)))*sin(theta))\n",
+ "I_m = (E_theta*r*sin(theta))/(60*cos(pi/2*cos(theta)))\n",
+ "I_rms = I_m/sqrt(2)\n",
+ "P_avg = (R_rad*(I_m**2))/2\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"Length of Dipole is\" ,round(L,2),\"metres\"\n",
+ "print \"Current fed to Antenna\",round(I_rms*1000,2),\"mA\"\n",
+ "print \"Average Power\",round(P_avg*1000,2),\"mW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.3,PAGE NO.-44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sqrt\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "l_eff = 100 #effective hieght in m\n",
+ "f = 60*(10**3) #frequency in Hertz\n",
+ "r = 100*(10**3) #Distance in m\n",
+ "c = 3*(10**8) #Speed of light in m/sec\n",
+ "P_rad = 100*(10**3) #radiated power\n",
+ "\n",
+ "# calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "R_rad = 160*(pi**2)*((l_eff/lamda)**2)\n",
+ "I_rms = sqrt(P_rad/R_rad)\n",
+ "E_rms = (120*pi*l_eff*(I_rms**2))/(lamda*r)\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print \"Strength of Electric field\",round(E_rms,2),\"V/m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.4,PAGE NO.-45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "l_eff = 113.3 #Effective length in metres\n",
+ "lamda = 18.8 #Wavelength in metres\n",
+ "I_rms = 725 #Base current in Ampere\n",
+ "r = 175 #Distance in metre\n",
+ "Eta_o = 120*pi\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "E = (120*pi*l_eff*I_rms)/(lamda*r)\n",
+ "H = E/Eta_o\n",
+ "R_rad = 160*(pi**2)*((l_eff/lamda)**2)\n",
+ "P_rad = (I_rms**2)*(R_rad)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The electric field at a distance r is \",round(E*0.001,2),\"mV/m\"\n",
+ "print \"The H field is\",round(H,2),\"uA/m\"\n",
+ "print \"The power radiated by Antenna is \",round(P_rad*(10**(-9)),2),\"kW\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.5,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sin\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "lamda = 10*(10**(-2)) # In cm\n",
+ "r = 200*(10**(-2)) # In cm\n",
+ "theta = 90 # In Degrees\n",
+ "phi = 0 # In Degrees\n",
+ "IdL = 3*(10**(-4)) # current distribution in Am\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "E_theta = (60*pi*IdL*sin(theta))/(lamda*r)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The magnitude of component E_theta is \",round(E_theta,2),\"V/m\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.6,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "dL = lamda/12\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "R_rad = 80*(pi**2)*((dL/lamda)**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Radiation resistance of dipole antenna is \",round(R_rad,2),\"ohm\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.7,PAGE NO.-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sqrt\n",
+ "from sympy import Symbol\n",
+ "# variable declaration\n",
+ "\n",
+ "I_m = 100 # uniform current in ampere\n",
+ "Lm = Symbol('Lm') #Taking Lm as lamda\n",
+ "dL = Lm/16\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "P_rad = 80*(pi**2)*((dL/Lm)**2)*((I_m/sqrt(2))**2)\n",
+ "R_rad = 80*(pi**2)*((dL/Lm)**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Radiation resistance of dipole is \",round(R_rad,2),\"ohm\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.8,PAGE NO.-47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# variable declaration\n",
+ "\n",
+ "f = 30*(10**6) #Frequency in Hz\n",
+ "c = 3*(10**8) #speed of light in m/s\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Length of Half wave dipole is \",round((lamda/2),2),\"m\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.10,PAGE NO.-48"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi,sin,sqrt \n",
+ "from sympy import Symbol\n",
+ "# variable declaration\n",
+ "\n",
+ "Lm = Symbol('Lm') # Taking lamda as Lm\n",
+ "dL = 0.01*Lm # Length of dipole \n",
+ "theta = 45\n",
+ "P_rad = 1 # Power radiated in kW\n",
+ "phi = 90\n",
+ "r = 1 # Distance in Km\n",
+ "Eta_o=120*pi\n",
+ "\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "R_rad = 20*(pi**2)*((dL/Lm)**2)\n",
+ "I_m = sqrt(2*P_rad*R_rad)\n",
+ "\n",
+ "# formula : P = (Eta_o/2)*(((Omega*I_m*dL*sin(theta))/(4*pi*r*v))**2)\n",
+ "P = (Eta_o/2)*(((I_m*dL*sin(theta))/(4*pi*(r**2)))**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Power density is \",P,\"Watt/m^2\"\n",
+ "\n",
+ "# Note : The Solving in the book is wrong they put 0.1 instead of 0.1*lamda \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9.11,PAGE NO.-49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi \n",
+ "\n",
+ "# variable declaration\n",
+ "\n",
+ "dL = 75 #Length of dipole in m\n",
+ "f = 800 # Frequency in kHz\n",
+ "I_rms = 10 #rms Current in Amp\n",
+ "c = 3*(10**8) #Speed of light in m/s \n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "lamda = c/f\n",
+ "P_rad = 80*(pi**2)*((dL/lamda)**2)*(I_rms**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print \"The Total Power radiated by Antenna is \",round(P_rad*1000,2),\"kW\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/NirenNegandhi/ch2.ipynb b/sample_notebooks/NirenNegandhi/ch2.ipynb
new file mode 100755
index 00000000..78fcb8ea
--- /dev/null
+++ b/sample_notebooks/NirenNegandhi/ch2.ipynb
@@ -0,0 +1,507 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:8949f832de7d3f263ae07355a00ea5a20f907aff9cf98c80b9a9488be44e93f7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2: Special Theory of Relativity"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2, Page 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import *\n",
+ "\n",
+ "#Variable declaration\n",
+ "ly = 9.46e+015; # Distance travelled by light in an year, m\n",
+ "c = 3e+008; # Speed of light, m/s\n",
+ "L = 4.30*ly; # Distance of Alpha Centauri from earth, m\n",
+ "T0 = 16*365.25*24*60*60; # Proper time in system K_prime, s\n",
+ "\n",
+ "#Calculations\n",
+ "# As time measured on earth, T = 2*L/v = T0_prime/sqrt(1-(v/c)^2), solving for v\n",
+ "v = sqrt(4*L**2/(T0**2+4*L**2/c**2)); # Speed of the aircraft, m/s\n",
+ "gama = 1/sqrt(1-(v/c)**2); # Relativistic factor\n",
+ "T = gama*T0/(365.25*24*60*60); # Time interval as measured on Earth, y\n",
+ "\n",
+ "#Results\n",
+ "print \"The speed of the aircraft = %4.2e m/s\" %v\n",
+ "print \"The time interval as measured on earth = %4.1f y\"%T\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The speed of the aircraft = 1.42e+08 m/s\n",
+ "The time interval as measured on earth = 18.2 y\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3, Page 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import *\n",
+ "\n",
+ "#Variable declaration\n",
+ "L0 = 4.30; # Distance of Alpha Centauri from earth, ly\n",
+ "c = 3e+008; # Speed of light, m/s\n",
+ "T = 8; # Proper time in system K_prime, y\n",
+ "\n",
+ "#Calculations\n",
+ "# As v/c = L0*sqrt(1-(v/c)^2)/(c*T) or bita = L0*sqrt(1-bita^2)/(c*T), solving for bita\n",
+ "bita = sqrt(L0**2/(T**2 + L0**2)); # Boost parameter\n",
+ "v = L0*sqrt(1-bita**2)/T; # Speed of the aircraft, c units\n",
+ "\n",
+ "#Results\n",
+ "print \"The boost parameter = %5.3f\"%bita\n",
+ "print \"The speed of the aircraft = %5.3fc units\"%v"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The boost parameter = 0.473\n",
+ "The speed of the aircraft = 0.473c units\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4, Page 40"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import *\n",
+ "\n",
+ "#Variable declaration\n",
+ "c = 1; # For simplicity assume speed of light to be unity, m/s\n",
+ "bita = 0.600; # Boost parameter\n",
+ "gama = 1/sqrt(1-bita**2); # Relativistic factor\n",
+ "u_x_prime = 0; # Speed of the protons in spaceship frame along x-axis, m/s\n",
+ "u_y_prime = 0.99*c; # Speed of the protons in spaceship frame along y-axis, m/s\n",
+ "u_z_prime = 0; # Speed of the protons in spaceship frame along z-axis, m/s\n",
+ "v = 0.60*c; # Speed of the spaceship w.r.t. space station, m/s\n",
+ "\n",
+ "#Calculations\n",
+ "u_x = (u_x_prime + v)/(1 + v/c**2*u_x_prime); # Speed of protons in space station frame along x-axis, m/s\n",
+ "u_y = u_y_prime/(gama*(1 + v/c**2*u_x_prime)); # Speed of protons in space station frame along y-axis, m/s\n",
+ "u_z = u_z_prime/(gama*(1 + v/c**2*u_x_prime)); # Speed of protons in space station frame along y-axis, m/s\n",
+ "u = sqrt(u_x**2 + u_y**2 + u_z**2); # The speed of the protons measured by an observer in the space station, m/s\n",
+ "\n",
+ "#Result\n",
+ "print \"The speed of the protons measured by an observer in the space station = %5.3fc units\"%u"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The speed of the protons measured by an observer in the space station = 0.994c units\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5, Page 45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import *\n",
+ "\n",
+ "#Variable declaration\n",
+ "c = 2.998e+008; # Speed of light in free space, m/s\n",
+ "v = 7712; # Speed of the space shuttle, m/s\n",
+ "bita = v/c; # Boost parameter\n",
+ "T_loss = 295.02; # Total measured loss in time, ps/sec\n",
+ "Add_T_loss = 35.0; # Additional time loss for moving clock from general relativity prediction, ps/s\n",
+ "\n",
+ "#Calculations\n",
+ "# From time dilation relation, T0_prime = T*sqrt(1 - bita^2), solving for (T - T0_prime)/T\n",
+ "Calc_T_loss = bita**2/2*1e+012; # Expected time lost per sec by the moving clock, ps/sec\n",
+ "Measured_T_loss = T_loss + Add_T_loss; # Total measured loss in time per sec as per special relativity, ps/s\n",
+ "percent_T_loss = (Calc_T_loss - Measured_T_loss)/Calc_T_loss*100; # Percentage deviation of measured and the calculated time loss per sec\n",
+ "T = 6.05e+05; # Total time of the seven-day mission, s\n",
+ "delta_T = Calc_T_loss*1e-012*T; # The total time difference between the moving and stationary clocks during the entire shuttle flight, s\n",
+ "\n",
+ "#Results\n",
+ "print \"The expected time lost per second for the moving clock = %6.2f ps\"%Calc_T_loss\n",
+ "print \"The percentage deviation of measured and the calculated time loss per sec for moving clock = %3.1f percent\"%percent_T_loss #answer differs due to rounding errors\n",
+ "print \"The total time difference between the moving and stationary clocks during the entire shuttle flight = %3.1f ms\"%(delta_T/1e-003)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The expected time lost per second for the moving clock = 330.86 ps\n",
+ "The percentage deviation of measured and the calculated time loss per sec for moving clock = 0.3 percent\n",
+ "The total time difference between the moving and stationary clocks during the entire shuttle flight = 0.2 ms\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8, Page 57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import *\n",
+ "\n",
+ "#Variable declaration\n",
+ "f0 = 1; # For simplicity assume frequency of the signals sent by Frank, Hz\n",
+ "# Outbound trip\n",
+ "bita = -0.8; # Boost parameter for receding frames\n",
+ "\n",
+ "#Calculations&Results\n",
+ "f = sqrt(1+bita)/sqrt(1-bita)*f0; # The frequency of the signals received by Mary in outbound trip, Hz\n",
+ "print \"The frequency of the signals received by Mary in outbound trip = f0/%d\", ceil(f*9)\n",
+ "# Return trip\n",
+ "bita = +0.8; # Boost parameter for approaching frames\n",
+ "f = sqrt(1+bita)/sqrt(1-bita)*f0; # The frequency of the signals received by Mary in return trip, Hz\n",
+ "print \"The frequency of the signals received by Mary in return trip = %df0\"%f"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The frequency of the signals received by Mary in outbound trip = f0/%d 3.0\n",
+ "The frequency of the signals received by Mary in return trip = 3f0\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.11, Page 64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import *\n",
+ "\n",
+ "#Variable declaration\n",
+ "q = 1.6e-019; # Charge on an electron, C\n",
+ "V = 25e+003; # Accelerating potential, volt\n",
+ "K = q*V; # Kinetic energy of electrons, J\n",
+ "m = 9.11e-031; # Rest mass of an electron, kg\n",
+ "c = 3.00e+08; # Speed of light, m/s\n",
+ "\n",
+ "#Calculations\n",
+ "# From relativistic kinetic energy formula, K = (gama - 1)*m*C^2, solving for gama\n",
+ "gama = 1 + K/(m*c**2); # Relativistic factor\n",
+ "bita = sqrt((gama**2-1)/gama**2); # Boost parameter\n",
+ "u = bita*c; # Speed of the electrons, m/s\n",
+ "# From non-relativistic expression, K = 1/2*m*u^2, solving for u\n",
+ "u_classical = sqrt(2*K/m); # Non-relativistic speed of the electrons, m/s\n",
+ "u_error = (u_classical - u)/u_classical*100; # Percentage error in speed of electrons, m/s\n",
+ "\n",
+ "#Results\n",
+ "print \"The relativistic speed of the accelerated electrons = %4.2e m/s\"%u\n",
+ "print \"The classical speed is about %d percent greater than the relativistic speed\"%ceil(u_error)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The relativistic speed of the accelerated electrons = 9.04e+07 m/s\n",
+ "The classical speed is about 4 percent greater than the relativistic speed\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.13, Page 69"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import *\n",
+ "\n",
+ "#Variable declaration\n",
+ "c = 1; # For simplicity assume peed of light to be unity, m/s\n",
+ "K = 2.00; # Kinetic energy of protons, GeV\n",
+ "E0 = 0.938; # Rest mass of a proton, GeV\n",
+ "E = K + E0; # Total energy of the proton, GeV\n",
+ "\n",
+ "#Calculations\n",
+ "# From relativistic mass energy relation, E^2 = (p*c)^2+E0^2, solving for p\n",
+ "p = sqrt(E**2 - E0**2)/c; # Momentum of the protons, GeV/c\n",
+ "# As E = gama*E0, solving for gama\n",
+ "gama = E/E0; # Relativistic factor\n",
+ "bita = sqrt((gama**2-1)/gama**2); # Boost parameter\n",
+ "v = bita*3.00e+08; # Speed of 2 GeV proton, m/s\n",
+ "\n",
+ "#Results\n",
+ "print \"The energy of each initial proton = %5.3f GeV\"%E\n",
+ "print \"The momentum of each initial proton = %4.2f GeV/c\"%p\n",
+ "print \"The speed of each initial proton = %3.1e m/s\"%v\n",
+ "print \"The relativistic factor, gama = %4.2f\"%gama\n",
+ "print \"The boost parameter, beta = %5.3f\"%bita"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The energy of each initial proton = 2.938 GeV\n",
+ "The momentum of each initial proton = 2.78 GeV/c\n",
+ "The speed of each initial proton = 2.8e+08 m/s\n",
+ "The relativistic factor, gama = 3.13\n",
+ "The boost parameter, beta = 0.948\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.15, Page 71"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "E_d = 1875.6; # Rest mass energy of the deuterium, MeV\n",
+ "E_pi = 139.6; # Rest mass energy of the pion, MeV\n",
+ "E_p = 938.3; # Rest mass energy of the proton, MeV\n",
+ "\n",
+ "#Calculation\n",
+ "K = 1./2*(E_d + E_pi - 2*E_p); # Minimum kinetic energy of the protons, MeV \n",
+ "\n",
+ "#Result\n",
+ "print \"The minimum kinetic energy of the protons = %2d MeV\"%K"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum kinetic energy of the protons = 69 MeV\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.16, Page 72"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "u = 931.5; # Energy equivalent of 1 amu, MeV\n",
+ "c = 1; # Speed of light in vacuum, m/s\n",
+ "\n",
+ "#Calculations\n",
+ "m_e = 0.000549*u; # Rest mass of an electron, MeV/c^2\n",
+ "m_p = 1.007276*u; # Rest mass of a proton, MeV/c^2\n",
+ "m_n = 1.008665*u; # Rest mass of a neutron, MeV/c^2\n",
+ "m_He = 4.002603*u; # Rest mass of a helium, MeV/c^2\n",
+ "M_He = m_He - 2*m_e; # Mass of He nucleus, MeV/c^2\n",
+ "E_B_He = (2*m_p + 2*m_n - M_He)*c**2; # Binding energy of the He nucleus, MeV\n",
+ "\n",
+ "#Result\n",
+ "print \"The binding energy of the He nucleus = %4.1f MeV\"%E_B_He"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The binding energy of the He nucleus = 28.3 MeV\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.17, Page 72"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "u = 931.5; # Energy equivalent of 1 amu, MeV/u\n",
+ "c = 1; # For simplicity assume speed of light in vacuum to be unity, m/s\n",
+ "E_B = 4.24; # The dissociationenergy of the NaCl molecule, MeV\n",
+ "\n",
+ "#Calculations\n",
+ "M = 58.44*u; # Energy corresponding to molecular mass of NaCl, MeV\n",
+ "f_r = E_B/M; # The fractional mass increase of the Na and Cl atoms\n",
+ "\n",
+ "#Result\n",
+ "print \"The fractional mass increase of the Na and Cl atoms when they are not bound together in NaCl = %4.1e\"%(f_r/1e+006)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The fractional mass increase of the Na and Cl atoms when they are not bound together in NaCl = 7.8e-11\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.18, Page 72"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import *\n",
+ "\n",
+ "#Variable declaration\n",
+ "c = 1; # For simplicity assume speed of light in vacuum to be unity, m/s\n",
+ "E0_n = 940; # Rest energy of a neutron, MeV\n",
+ "E0_pi = 140; # Rest energy of a pion, MeV\n",
+ "p_n = 4702; # Momentum of the neutron, MeV/c\n",
+ "p_pi = 169; # Momentum of the pion, MeV/c\n",
+ "\n",
+ "#Calculations\n",
+ "E_n = sqrt((p_n*c)**2+E0_n**2); # Total energy of the neutron, MeV\n",
+ "E_pi = sqrt((p_pi*c)**2+E0_pi**2); # Total energy of the pion, MeV\n",
+ "E = E_n + E_pi; # Total energy of the reaction, MeV\n",
+ "p_sigma = p_n + p_pi; # Momentum of the sigma particle, MeV/c\n",
+ "E0_sigma = sqrt(E**2 - (p_sigma*c)**2); # Rest mass energy of the sigma particle, MeV\n",
+ "m_sigma = E0_sigma/c**2; # Rest mass of sigma particle, MeV/c^2;\n",
+ "K = E - E0_sigma; # Kinetic energy of sigma particle, MeV\n",
+ "\n",
+ "#Results\n",
+ "print \"The rest mass of sigma particle = %4d MeV/c^2\"%ceil(m_sigma)\n",
+ "print \"The kinetic energy of sigma particle = %4d MeV\"%ceil(K)\n",
+ "\n",
+ "#Answers differ due to rounding errors"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The rest mass of sigma particle = 1192 MeV/c^2\n",
+ "The kinetic energy of sigma particle = 3824 MeV\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/NitamoniDas/chapter_8_Data_Abstraction_through_Classes_and_User-Defined_Data_Types.ipynb b/sample_notebooks/NitamoniDas/chapter_8_Data_Abstraction_through_Classes_and_User-Defined_Data_Types.ipynb
new file mode 100755
index 00000000..1083b19a
--- /dev/null
+++ b/sample_notebooks/NitamoniDas/chapter_8_Data_Abstraction_through_Classes_and_User-Defined_Data_Types.ipynb
@@ -0,0 +1,809 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:dbbd8ed92141bcc804ff2fbeacf8bb85f122dc6e196e1d830291a4a449a3a439"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: Data Abstraction through Classes and User-Defined Data Types "
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.1, page no: 208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Super:\n",
+ " def __init__(self):\n",
+ " self.__IntegerData=None #private member\n",
+ " #public functions\n",
+ " def SetData(self,i):\n",
+ " self.__IntegerData=i #refer to IntegerData\n",
+ " def ShowData(self):\n",
+ " print \"Data is \",self.__IntegerData,' '\n",
+ "\n",
+ "ob1=Super()\n",
+ "ob2=Super()\n",
+ "ob1.SetData(1000)\n",
+ "ob2.SetData(2000)\n",
+ "ob1.ShowData()\n",
+ "ob2.ShowData()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Data is 1000 \n",
+ "Data is 2000 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.2, page no:211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class X:\n",
+ " def __init__(self):\n",
+ " self.a=None #private members\n",
+ " self.b=None #private members\n",
+ " \n",
+ "#no structure type present in python \n",
+ "x = X()\n",
+ "\n",
+ "x.a=0\n",
+ "x.b=1\n",
+ "print \"x.a=\",x.a,\",x.b=\",x.b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x.a= 0 ,x.b= 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.3, page no:214"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction:\n",
+ " \n",
+ " def SetValue(self,a,b): #public functions\n",
+ " self.__num=a \n",
+ " self.__denom=b \n",
+ " def GetValue(self,a,b):\n",
+ " a=self.__num\n",
+ " b=self.__denom\n",
+ " \n",
+ "f=Fraction()\n",
+ "n=input(\"Enter n: \") #user input\n",
+ "d=input(\"Enter d: \") #user input\n",
+ "print \"enter the numerator and denominator: \", ' ',n,d\n",
+ "\n",
+ "f.SetValue(n,d) #call function SetValue\n",
+ "print \"Numerator value set: \", ' ',n\n",
+ "print \"Denominator value set: \", ' ',d\n",
+ "f.GetValue(n,d) #call function GetData\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter n: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter d: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter the numerator and denominator: 3 4\n",
+ "Numerator value set: 3\n",
+ "Denominator value set: 4\n",
+ "Numerator value retrieved: 3\n",
+ "Denominator value retrieved: 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.4, page no:216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class SimpleClass:\n",
+ " def __init__(self):\n",
+ " self.__i=None #private member\n",
+ " \n",
+ " def __init__(self):\n",
+ " self.__i=500 #constructor\n",
+ " \n",
+ " def SetData(self,d):\n",
+ " self.__i=d\n",
+ " \n",
+ " def GetData(self):\n",
+ " return self.__i\n",
+ " \n",
+ "#Initializing\n",
+ "s1=SimpleClass()\n",
+ "s2=SimpleClass()\n",
+ "print \"s1 has data: \",s1.GetData()\n",
+ "print \"s2 has data: \",s2.GetData()\n",
+ "s1.SetData(1000) #function call\n",
+ "s2.SetData(2000)\n",
+ "print \"s1 has data: \",s1.GetData(),' '\n",
+ "print \"s2 has data: \", s2.GetData(),' '\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s1 has data: 500\n",
+ "s2 has data: 500\n",
+ "s1 has data: 1000 \n",
+ "s2 has data: 2000 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.5, page no:217"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class SimpleClass:\n",
+ " __IntegerData=None\n",
+ " def __init__(self,data=None):\n",
+ " if data==None:\n",
+ " self.__IntegerData=500 #default constructor\n",
+ " else:\n",
+ " self.__IntegerData=data #parameterised constructor\n",
+ " \n",
+ " def SetData(self,d):\n",
+ " self.__IntegerData=d\n",
+ " \n",
+ " def GetData(self):\n",
+ " return self.__IntegerData\n",
+ " \n",
+ "#Initializing\n",
+ "s1=SimpleClass()\n",
+ "s2=SimpleClass()\n",
+ "s3=SimpleClass(400)\n",
+ "s4=SimpleClass(600)\n",
+ "print \"s1 has data: \",s1.GetData(),' '\n",
+ "print \"s2 has data: \",s2.GetData(),' '\n",
+ "print \"s3 has data: \",s3.GetData(),' '\n",
+ "print \"s4 has data: \",s4.GetData(),' '\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s1 has data: 500 \n",
+ "s2 has data: 500 \n",
+ "s3 has data: 400 \n",
+ "s4 has data: 600 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.6, page no:218"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction: \n",
+ " def_init_num=None #private members\n",
+ " def_init_denom=None #private members\n",
+ " def __init__(self,a=0,b=1):\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " print \"Numerator set inside constructor\",' ',n\n",
+ " print \"Denominator set inside constructor\",' ',d\n",
+ " \n",
+ " def SetValue(self,a,b):\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " def GetValue(self,a,b):\n",
+ " a= self.__num\n",
+ " b= self.__denom\n",
+ " return a,b\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " pass\n",
+ " \n",
+ "n=input(\"Enter n: \") #user input\n",
+ "d=input(\"Enter d: \") #user input\n",
+ "print \"Please enter value of numerator and denominator: \",' ',n,d\n",
+ "f=Fraction(n,d)\n",
+ "f.GetValue(n,d)\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter n: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter d: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter value of numerator and denominator: 3 4\n",
+ "Numerator set inside constructor 3\n",
+ "Denominator set inside constructor 4\n",
+ "Numerator value retrieved: 3\n",
+ "Denominator value retrieved: 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.7, page no:221"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction:\n",
+ " \n",
+ " def __init__(self,a=0,b=1): #constructor\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " print \"Numerator set inside constructor: \",self.__num\n",
+ " print \"Denominator set inside constructor: \",self.__denom \n",
+ " \n",
+ " def GetValue(self,a,b):\n",
+ " return self.__num,self.__denom\n",
+ "n=input(\"Enter n: \") #user input\n",
+ "d=input(\"Enter d: \") #user input\n",
+ "print \"Please enter the value of the numerator and denominator: \",n,d\n",
+ "f=Fraction(n,d)\n",
+ "n,d=f.GetValue(n,d)\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d\n",
+ "n=input(\"Please enter the value of numerator only: \")\n",
+ "f1=Fraction(n)\n",
+ "n,d=f1.GetValue(n,d)\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d\n",
+ "print 'ok..now I will create a fraction-no input please'\n",
+ "f2=Fraction()\n",
+ "n,d=f2.GetValue(n,d)\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter n: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter d: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter the value of the numerator and denominator: 3 4\n",
+ "Numerator set inside constructor: 3\n",
+ "Denominator set inside constructor: 4\n",
+ "Numerator value retrieved: 3\n",
+ "Denominator value retrieved: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter the value of numerator only: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Numerator set inside constructor: 3\n",
+ "Denominator set inside constructor: 1\n",
+ "Numerator value retrieved: 3\n",
+ "Denominator value retrieved: 1\n",
+ "ok..now I will create a fraction-no input please\n",
+ "Numerator set inside constructor: 0\n",
+ "Denominator set inside constructor: 1\n",
+ "Numerator value retrieved: 0\n",
+ "Denominator value retrieved: 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.8, page no:223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction:\n",
+ " def_init_num=None #private members\n",
+ " def_init_denom=None #private members\n",
+ " \n",
+ " def __init__(self,anotherFraction=None): \n",
+ " if anotherFraction==None: #normal constructor\n",
+ " self.__num=anotherFraction\n",
+ " self.__denom=anotherFraction\n",
+ " else: #copy constructor\n",
+ " self.__num=anotherFraction.self.__num\n",
+ " self.__denom=anotherFraction.self.__denom\n",
+ " \n",
+ " \n",
+ " #public functions\n",
+ " def SetValue(self,a,b):\n",
+ " self.__num=a\n",
+ " self.__denom=b#refer to IntegerData\n",
+ " def GetValue(self,a,b):\n",
+ " a=self.__num\n",
+ " b=self.__denom\n",
+ " return a,b\n",
+ " \n",
+ "f=Fraction()\n",
+ "n=input(\"Enter n: \") #user input\n",
+ "d=input(\"Enter d: \") #user input\n",
+ "print \"enter the numerator and denominator: \", ' ',n,d\n",
+ "\n",
+ "f.SetValue(n,d) #call function SetValue\n",
+ "print \"Numerator value set: \", ' ',n\n",
+ "print \"Denominator value set: \", ' ',d\n",
+ "f.GetValue(n,d) #call function GetData\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d\n",
+ "print \"Now a second clone copy is being created: \",''\n",
+ "f1=f\n",
+ "f1.GetValue(n,d)\n",
+ "print \"Clone's numerator value retrieved: \", ' ',n\n",
+ "print \"Clone's denominator value retrieved: \", ' ',d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter n: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter d: 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter the numerator and denominator: 5 6\n",
+ "Numerator value set: 5\n",
+ "Denominator value set: 6\n",
+ "Numerator value retrieved: 5\n",
+ "Denominator value retrieved: 6\n",
+ "Now a second clone copy is being created: \n",
+ "Clone's numerator value retrieved: 5\n",
+ "Clone's denominator value retrieved: 6\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.9, page no:229"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def MyNewHandler():\n",
+ " print \"Sorry operator new failed to allocate memory\"\n",
+ " exit(0)\n",
+ " \n",
+ "def _set_new_handler(s):\n",
+ " s()\n",
+ "#In python there is no in-built _set_new_handler function, so i made this function and passed MyNewHandler function as a parameters\n",
+ "_set_new_handler(MyNewHandler)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sorry operator new failed to allocate memory\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.10, page no:230"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import * \n",
+ "class Fraction: \n",
+ " def __init__(self,a=0,b=1): \n",
+ " if isinstance(a,int): \n",
+ " c = c_int(a) \n",
+ " d = c_int(b) \n",
+ " self.__num = pointer(c) \n",
+ " self.__denom = pointer(d) \n",
+ " print 'constructor sets numerator = ', self.__num[0] , ', denominator = ', self.__denom[0] \n",
+ " else:\n",
+ " c=c_int(a.__num[0])\n",
+ " d = c_int(a.__denom[0])\n",
+ " self.__num = pointer(c) \n",
+ " self.__denom = pointer(d)\n",
+ " print 'copy constructor sets numerator = ', self.__num[0] , ', denominator = ', self.__denom[0] \n",
+ " \n",
+ " def __del__(self): \n",
+ " print 'destructor deallocates numerator = ', self.__num[0] , ', denominator = ', self.__denom[0] \n",
+ " \n",
+ "n = input(\"Please enter values of numerator: \") \n",
+ "d = input(\"Please enter values of denominator: \") \n",
+ "f = Fraction(n,d) \n",
+ "print 'Please enter another set of ' \n",
+ "n = input(\"numerator: \") \n",
+ "d = input(\"denominator: \") \n",
+ "print 'Creating fraction *pf : ' \n",
+ "pf = Fraction(n,d) \n",
+ "print 'Now a clone copy (f2) created from *pf: ' \n",
+ "f2 = Fraction(pf)\n",
+ "print 'Now another clone copy (*pf2) created from f:' \n",
+ "pf2 = Fraction(f) \n",
+ "print '*pf2 is being destroyed:' \n",
+ "del pf2\n",
+ "print '*pf is being destroyed:' \n",
+ "del pf \n",
+ "print 'now objects f2 and f automatically destroyed : '"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter values of numerator: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter values of denominator: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "constructor sets numerator = 3 , denominator = 4\n",
+ "Please enter another set of \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "numerator: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "denominator: 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Creating fraction *pf : \n",
+ "constructor sets numerator = 5 , denominator = 6\n",
+ "Now a clone copy (f2) created from *pf: \n",
+ "copy constructor sets numerator = 5 , denominator = 6\n",
+ "Now another clone copy (*pf2) created from f:\n",
+ "copy constructor sets numerator = 3 , denominator = 4\n",
+ "*pf2 is being destroyed:\n",
+ "*pf is being destroyed:\n",
+ "now objects f2 and f automatically destroyed : \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.11, page no:234"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Memfail(self,s):\n",
+ " print \"Sorry Unable to allocate memory\"\n",
+ " sys.exit(0)\n",
+ "\n",
+ "MAX_SIZE = 60 + 1\n",
+ "\n",
+ "MAX_SIZE=[[0 for col in range(MAX_SIZE)]for row in range(MAX_SIZE)]\n",
+ "nChar=0\n",
+ "chArr=\"Hello\"\n",
+ "\n",
+ "print \"Please input a string( 60 characters max.): \",chArr\n",
+ "\n",
+ "nChar=len(chArr)+1\n",
+ "szStr=chArr\n",
+ "print \"required memory space for\",nChar,\n",
+ "print \"characters\"\n",
+ "chArr=szStr #string copy\n",
+ "szStr=chArr\n",
+ "print \"String copied in allocated space: \",szStr\n",
+ "print \"Memory space dellocated\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input a string( 60 characters max.): Hello\n",
+ "required memory space for 6 characters\n",
+ "String copied in allocated space: Hello\n",
+ "Memory space dellocated\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.12, page no:236"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction:\n",
+ " \n",
+ " def __init__(self,a=0,b=1): #constructor\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " pass\n",
+ " \n",
+ " def GetValue(self,a,b):\n",
+ " a=self.__num\n",
+ " b=self.__denom\n",
+ " return self.__num,self.__denom\n",
+ "n=4\n",
+ "d=5\n",
+ "f=Fraction(4,5)\n",
+ "n,d=f.GetValue(n,d)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.13, page no:239"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class X:\n",
+ " __sa=20 #initialising static member\n",
+ " a = None\n",
+ " def __init__(self):\n",
+ " self.a=None #public member\n",
+ " def f(self,b):\n",
+ " a=30\n",
+ " print \"Global a= \",b\n",
+ " print \"Local a= \",a\n",
+ " print \"Nonstatic member a= \",self.a\n",
+ " print \"static member sa= \",self.__sa\n",
+ "\n",
+ "a=10\n",
+ "\n",
+ "aXobj=X()\n",
+ "aXobj.a=40\n",
+ "aXobj.f(a)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Global a= 10\n",
+ "Local a= 30\n",
+ "Nonstatic member a= 40\n",
+ "static member sa= 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/NitamoniDas/chapter_8_Data_Abstraction_through_Classes_and_User-Defined_Data_Types_1.ipynb b/sample_notebooks/NitamoniDas/chapter_8_Data_Abstraction_through_Classes_and_User-Defined_Data_Types_1.ipynb
new file mode 100755
index 00000000..1083b19a
--- /dev/null
+++ b/sample_notebooks/NitamoniDas/chapter_8_Data_Abstraction_through_Classes_and_User-Defined_Data_Types_1.ipynb
@@ -0,0 +1,809 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:dbbd8ed92141bcc804ff2fbeacf8bb85f122dc6e196e1d830291a4a449a3a439"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: Data Abstraction through Classes and User-Defined Data Types "
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.1, page no: 208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Super:\n",
+ " def __init__(self):\n",
+ " self.__IntegerData=None #private member\n",
+ " #public functions\n",
+ " def SetData(self,i):\n",
+ " self.__IntegerData=i #refer to IntegerData\n",
+ " def ShowData(self):\n",
+ " print \"Data is \",self.__IntegerData,' '\n",
+ "\n",
+ "ob1=Super()\n",
+ "ob2=Super()\n",
+ "ob1.SetData(1000)\n",
+ "ob2.SetData(2000)\n",
+ "ob1.ShowData()\n",
+ "ob2.ShowData()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Data is 1000 \n",
+ "Data is 2000 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.2, page no:211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class X:\n",
+ " def __init__(self):\n",
+ " self.a=None #private members\n",
+ " self.b=None #private members\n",
+ " \n",
+ "#no structure type present in python \n",
+ "x = X()\n",
+ "\n",
+ "x.a=0\n",
+ "x.b=1\n",
+ "print \"x.a=\",x.a,\",x.b=\",x.b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x.a= 0 ,x.b= 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.3, page no:214"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction:\n",
+ " \n",
+ " def SetValue(self,a,b): #public functions\n",
+ " self.__num=a \n",
+ " self.__denom=b \n",
+ " def GetValue(self,a,b):\n",
+ " a=self.__num\n",
+ " b=self.__denom\n",
+ " \n",
+ "f=Fraction()\n",
+ "n=input(\"Enter n: \") #user input\n",
+ "d=input(\"Enter d: \") #user input\n",
+ "print \"enter the numerator and denominator: \", ' ',n,d\n",
+ "\n",
+ "f.SetValue(n,d) #call function SetValue\n",
+ "print \"Numerator value set: \", ' ',n\n",
+ "print \"Denominator value set: \", ' ',d\n",
+ "f.GetValue(n,d) #call function GetData\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter n: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter d: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter the numerator and denominator: 3 4\n",
+ "Numerator value set: 3\n",
+ "Denominator value set: 4\n",
+ "Numerator value retrieved: 3\n",
+ "Denominator value retrieved: 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.4, page no:216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class SimpleClass:\n",
+ " def __init__(self):\n",
+ " self.__i=None #private member\n",
+ " \n",
+ " def __init__(self):\n",
+ " self.__i=500 #constructor\n",
+ " \n",
+ " def SetData(self,d):\n",
+ " self.__i=d\n",
+ " \n",
+ " def GetData(self):\n",
+ " return self.__i\n",
+ " \n",
+ "#Initializing\n",
+ "s1=SimpleClass()\n",
+ "s2=SimpleClass()\n",
+ "print \"s1 has data: \",s1.GetData()\n",
+ "print \"s2 has data: \",s2.GetData()\n",
+ "s1.SetData(1000) #function call\n",
+ "s2.SetData(2000)\n",
+ "print \"s1 has data: \",s1.GetData(),' '\n",
+ "print \"s2 has data: \", s2.GetData(),' '\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s1 has data: 500\n",
+ "s2 has data: 500\n",
+ "s1 has data: 1000 \n",
+ "s2 has data: 2000 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.5, page no:217"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class SimpleClass:\n",
+ " __IntegerData=None\n",
+ " def __init__(self,data=None):\n",
+ " if data==None:\n",
+ " self.__IntegerData=500 #default constructor\n",
+ " else:\n",
+ " self.__IntegerData=data #parameterised constructor\n",
+ " \n",
+ " def SetData(self,d):\n",
+ " self.__IntegerData=d\n",
+ " \n",
+ " def GetData(self):\n",
+ " return self.__IntegerData\n",
+ " \n",
+ "#Initializing\n",
+ "s1=SimpleClass()\n",
+ "s2=SimpleClass()\n",
+ "s3=SimpleClass(400)\n",
+ "s4=SimpleClass(600)\n",
+ "print \"s1 has data: \",s1.GetData(),' '\n",
+ "print \"s2 has data: \",s2.GetData(),' '\n",
+ "print \"s3 has data: \",s3.GetData(),' '\n",
+ "print \"s4 has data: \",s4.GetData(),' '\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s1 has data: 500 \n",
+ "s2 has data: 500 \n",
+ "s3 has data: 400 \n",
+ "s4 has data: 600 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.6, page no:218"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction: \n",
+ " def_init_num=None #private members\n",
+ " def_init_denom=None #private members\n",
+ " def __init__(self,a=0,b=1):\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " print \"Numerator set inside constructor\",' ',n\n",
+ " print \"Denominator set inside constructor\",' ',d\n",
+ " \n",
+ " def SetValue(self,a,b):\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " def GetValue(self,a,b):\n",
+ " a= self.__num\n",
+ " b= self.__denom\n",
+ " return a,b\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " pass\n",
+ " \n",
+ "n=input(\"Enter n: \") #user input\n",
+ "d=input(\"Enter d: \") #user input\n",
+ "print \"Please enter value of numerator and denominator: \",' ',n,d\n",
+ "f=Fraction(n,d)\n",
+ "f.GetValue(n,d)\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter n: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter d: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter value of numerator and denominator: 3 4\n",
+ "Numerator set inside constructor 3\n",
+ "Denominator set inside constructor 4\n",
+ "Numerator value retrieved: 3\n",
+ "Denominator value retrieved: 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.7, page no:221"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction:\n",
+ " \n",
+ " def __init__(self,a=0,b=1): #constructor\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " print \"Numerator set inside constructor: \",self.__num\n",
+ " print \"Denominator set inside constructor: \",self.__denom \n",
+ " \n",
+ " def GetValue(self,a,b):\n",
+ " return self.__num,self.__denom\n",
+ "n=input(\"Enter n: \") #user input\n",
+ "d=input(\"Enter d: \") #user input\n",
+ "print \"Please enter the value of the numerator and denominator: \",n,d\n",
+ "f=Fraction(n,d)\n",
+ "n,d=f.GetValue(n,d)\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d\n",
+ "n=input(\"Please enter the value of numerator only: \")\n",
+ "f1=Fraction(n)\n",
+ "n,d=f1.GetValue(n,d)\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d\n",
+ "print 'ok..now I will create a fraction-no input please'\n",
+ "f2=Fraction()\n",
+ "n,d=f2.GetValue(n,d)\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter n: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter d: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter the value of the numerator and denominator: 3 4\n",
+ "Numerator set inside constructor: 3\n",
+ "Denominator set inside constructor: 4\n",
+ "Numerator value retrieved: 3\n",
+ "Denominator value retrieved: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter the value of numerator only: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Numerator set inside constructor: 3\n",
+ "Denominator set inside constructor: 1\n",
+ "Numerator value retrieved: 3\n",
+ "Denominator value retrieved: 1\n",
+ "ok..now I will create a fraction-no input please\n",
+ "Numerator set inside constructor: 0\n",
+ "Denominator set inside constructor: 1\n",
+ "Numerator value retrieved: 0\n",
+ "Denominator value retrieved: 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.8, page no:223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction:\n",
+ " def_init_num=None #private members\n",
+ " def_init_denom=None #private members\n",
+ " \n",
+ " def __init__(self,anotherFraction=None): \n",
+ " if anotherFraction==None: #normal constructor\n",
+ " self.__num=anotherFraction\n",
+ " self.__denom=anotherFraction\n",
+ " else: #copy constructor\n",
+ " self.__num=anotherFraction.self.__num\n",
+ " self.__denom=anotherFraction.self.__denom\n",
+ " \n",
+ " \n",
+ " #public functions\n",
+ " def SetValue(self,a,b):\n",
+ " self.__num=a\n",
+ " self.__denom=b#refer to IntegerData\n",
+ " def GetValue(self,a,b):\n",
+ " a=self.__num\n",
+ " b=self.__denom\n",
+ " return a,b\n",
+ " \n",
+ "f=Fraction()\n",
+ "n=input(\"Enter n: \") #user input\n",
+ "d=input(\"Enter d: \") #user input\n",
+ "print \"enter the numerator and denominator: \", ' ',n,d\n",
+ "\n",
+ "f.SetValue(n,d) #call function SetValue\n",
+ "print \"Numerator value set: \", ' ',n\n",
+ "print \"Denominator value set: \", ' ',d\n",
+ "f.GetValue(n,d) #call function GetData\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d\n",
+ "print \"Now a second clone copy is being created: \",''\n",
+ "f1=f\n",
+ "f1.GetValue(n,d)\n",
+ "print \"Clone's numerator value retrieved: \", ' ',n\n",
+ "print \"Clone's denominator value retrieved: \", ' ',d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter n: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter d: 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter the numerator and denominator: 5 6\n",
+ "Numerator value set: 5\n",
+ "Denominator value set: 6\n",
+ "Numerator value retrieved: 5\n",
+ "Denominator value retrieved: 6\n",
+ "Now a second clone copy is being created: \n",
+ "Clone's numerator value retrieved: 5\n",
+ "Clone's denominator value retrieved: 6\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.9, page no:229"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def MyNewHandler():\n",
+ " print \"Sorry operator new failed to allocate memory\"\n",
+ " exit(0)\n",
+ " \n",
+ "def _set_new_handler(s):\n",
+ " s()\n",
+ "#In python there is no in-built _set_new_handler function, so i made this function and passed MyNewHandler function as a parameters\n",
+ "_set_new_handler(MyNewHandler)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sorry operator new failed to allocate memory\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.10, page no:230"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import * \n",
+ "class Fraction: \n",
+ " def __init__(self,a=0,b=1): \n",
+ " if isinstance(a,int): \n",
+ " c = c_int(a) \n",
+ " d = c_int(b) \n",
+ " self.__num = pointer(c) \n",
+ " self.__denom = pointer(d) \n",
+ " print 'constructor sets numerator = ', self.__num[0] , ', denominator = ', self.__denom[0] \n",
+ " else:\n",
+ " c=c_int(a.__num[0])\n",
+ " d = c_int(a.__denom[0])\n",
+ " self.__num = pointer(c) \n",
+ " self.__denom = pointer(d)\n",
+ " print 'copy constructor sets numerator = ', self.__num[0] , ', denominator = ', self.__denom[0] \n",
+ " \n",
+ " def __del__(self): \n",
+ " print 'destructor deallocates numerator = ', self.__num[0] , ', denominator = ', self.__denom[0] \n",
+ " \n",
+ "n = input(\"Please enter values of numerator: \") \n",
+ "d = input(\"Please enter values of denominator: \") \n",
+ "f = Fraction(n,d) \n",
+ "print 'Please enter another set of ' \n",
+ "n = input(\"numerator: \") \n",
+ "d = input(\"denominator: \") \n",
+ "print 'Creating fraction *pf : ' \n",
+ "pf = Fraction(n,d) \n",
+ "print 'Now a clone copy (f2) created from *pf: ' \n",
+ "f2 = Fraction(pf)\n",
+ "print 'Now another clone copy (*pf2) created from f:' \n",
+ "pf2 = Fraction(f) \n",
+ "print '*pf2 is being destroyed:' \n",
+ "del pf2\n",
+ "print '*pf is being destroyed:' \n",
+ "del pf \n",
+ "print 'now objects f2 and f automatically destroyed : '"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter values of numerator: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter values of denominator: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "constructor sets numerator = 3 , denominator = 4\n",
+ "Please enter another set of \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "numerator: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "denominator: 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Creating fraction *pf : \n",
+ "constructor sets numerator = 5 , denominator = 6\n",
+ "Now a clone copy (f2) created from *pf: \n",
+ "copy constructor sets numerator = 5 , denominator = 6\n",
+ "Now another clone copy (*pf2) created from f:\n",
+ "copy constructor sets numerator = 3 , denominator = 4\n",
+ "*pf2 is being destroyed:\n",
+ "*pf is being destroyed:\n",
+ "now objects f2 and f automatically destroyed : \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.11, page no:234"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Memfail(self,s):\n",
+ " print \"Sorry Unable to allocate memory\"\n",
+ " sys.exit(0)\n",
+ "\n",
+ "MAX_SIZE = 60 + 1\n",
+ "\n",
+ "MAX_SIZE=[[0 for col in range(MAX_SIZE)]for row in range(MAX_SIZE)]\n",
+ "nChar=0\n",
+ "chArr=\"Hello\"\n",
+ "\n",
+ "print \"Please input a string( 60 characters max.): \",chArr\n",
+ "\n",
+ "nChar=len(chArr)+1\n",
+ "szStr=chArr\n",
+ "print \"required memory space for\",nChar,\n",
+ "print \"characters\"\n",
+ "chArr=szStr #string copy\n",
+ "szStr=chArr\n",
+ "print \"String copied in allocated space: \",szStr\n",
+ "print \"Memory space dellocated\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input a string( 60 characters max.): Hello\n",
+ "required memory space for 6 characters\n",
+ "String copied in allocated space: Hello\n",
+ "Memory space dellocated\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.12, page no:236"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction:\n",
+ " \n",
+ " def __init__(self,a=0,b=1): #constructor\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " pass\n",
+ " \n",
+ " def GetValue(self,a,b):\n",
+ " a=self.__num\n",
+ " b=self.__denom\n",
+ " return self.__num,self.__denom\n",
+ "n=4\n",
+ "d=5\n",
+ "f=Fraction(4,5)\n",
+ "n,d=f.GetValue(n,d)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.13, page no:239"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class X:\n",
+ " __sa=20 #initialising static member\n",
+ " a = None\n",
+ " def __init__(self):\n",
+ " self.a=None #public member\n",
+ " def f(self,b):\n",
+ " a=30\n",
+ " print \"Global a= \",b\n",
+ " print \"Local a= \",a\n",
+ " print \"Nonstatic member a= \",self.a\n",
+ " print \"static member sa= \",self.__sa\n",
+ "\n",
+ "a=10\n",
+ "\n",
+ "aXobj=X()\n",
+ "aXobj.a=40\n",
+ "aXobj.f(a)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Global a= 10\n",
+ "Local a= 30\n",
+ "Nonstatic member a= 40\n",
+ "static member sa= 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/SINDHUARROJU/Chapter1.ipynb b/sample_notebooks/SINDHUARROJU/Chapter1.ipynb
new file mode 100755
index 00000000..aec285c1
--- /dev/null
+++ b/sample_notebooks/SINDHUARROJU/Chapter1.ipynb
@@ -0,0 +1,463 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:305dcc155810a92329b40a851ec0d721020f53211b825d9c1f3b0e3bb9312285"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "1: Acoustics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.1, Page number 12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "p=50; #sound waves with output power(W)\n",
+ "r=4; #Distance(m)\n",
+ "\n",
+ "#Calculation\n",
+ "I=p/(4*math.pi*r**2) #Intensity(W/m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"Intensity of sound at a distance of 4m from the source is\",round(I,2),\"W/m**2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Intensity of sound at a distance of 4m from the source is 0.25 W/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.2, Page number 12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Io=10**-12; #Initial intensity of sound(W/m**2)\n",
+ "d=50; #number of decibels given by 10log(Io/I1)\n",
+ "P=70; #Output power(W)\n",
+ "\n",
+ "#Calculation\n",
+ "I1=(10**5)*Io; #Intensity(W/m**2)\n",
+ "r=math.sqrt(P/(4*math.pi*I1)); #distance(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"The distance at which sound reduces to a level of 50dB is\",round(r/10**3,2),\"*10**3 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The distance at which sound reduces to a level of 50dB is 7.46 *10**3 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.3, Page number 12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "v=8000; #volume of the hall(m**3)\n",
+ "T=1.5; #Reverberation time(sec)\n",
+ "\n",
+ "#Calculation\n",
+ "A=(0.161*v)/T; #Total absorption time(m**2 sabine)\n",
+ "\n",
+ "#Result\n",
+ "print \"The total reverberation in the hall is\",round(A,2),\"m**2 sabine\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The total reverberation in the hall is 858.67 m**2 sabine\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.4, Page number 12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "l=25; #length of the hall(m)\n",
+ "b=20; #breadth of the hall(m)\n",
+ "h=10; #height of the hall(m)\n",
+ "T=4; #Reverberation time(s)\n",
+ "\n",
+ "#Calculation\n",
+ "V=l*b*h; #Volume of the hall(m**3)\n",
+ "A=(0.161*V)/T; #Total absorption time(m**2 sabine)\n",
+ "a=A/(2*((l*b)+(b*h)+(l*h))); #a is absorption co-efficient\n",
+ "\n",
+ "#Result\n",
+ "print \"The average absorption co-efficients of surfaces is\",round(a,3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The average absorption co-efficients of surfaces is 0.106\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.5, Page number 12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Y=77*(10**10); #Youngs modulus for quartz(dyne/cm**2)\n",
+ "rho=2.6; #density of quartz(g/cm**3)\n",
+ "t=0.4; #thickness(cm)\n",
+ "\n",
+ "#Calculation\n",
+ "f=((1/(2*t))*math.sqrt(Y/rho))*10**-3; #frequency(kHz)\n",
+ "\n",
+ "#Result\n",
+ "print \"The frequency of ultrasonic waves produced is\",int(f),\"kHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The frequency of ultrasonic waves produced is 680 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.6, Page number 12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Y=81*10**10; #Young's modulus for barium titanate(dynes/cm**2)\n",
+ "rho=5.51; #density of barium titanate(g/cm**3)\n",
+ "f=900; #frequency of ultrasonic waves(kHZ)\n",
+ "\n",
+ "#Calculation\n",
+ "t=((1/(2*f))*math.sqrt(Y/rho))*10**-2; #thickness of crystal(mm)\n",
+ "\n",
+ "#Result\n",
+ "print \"The thickness of the crystal to produce ultrasonic waves is\",round(t,2),\"mm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The thickness of the crystal to produce ultrasonic waves is 2.13 mm\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.7, Page number 13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "r=3; #distance(m)\n",
+ "I=0.86; #Intensity of sound source(W/m**2)\n",
+ "\n",
+ "#Calculation\n",
+ "P=4*math.pi*r**2*I; #Power of the sound source(W)\n",
+ "\n",
+ "#Result\n",
+ "print \"The output power of the sound source is\",round(P,2),\"W\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The output power of the sound source is 97.26 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.8, Page number 13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "d=60; #Number of decibels given by 10*log(I/I0)\n",
+ "I0=10**-12; #Initial intensity of sound(W/m**2)\n",
+ "I=10**-6; #since 10log(I/I0)=60\n",
+ "r=200; #distance(m)\n",
+ "\n",
+ "#Calculation\n",
+ "P=4*math.pi*r**2*I; #output power of the sound source(W)\n",
+ "\n",
+ "#Result\n",
+ "print \"The output power of the sound source is\",round(P,1),\"W\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The output power of the sound source is 0.5 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.9, Page number 13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "V=9250; #volume of the hall(m**3)\n",
+ "A=900; #Total absorption(m**2 sabine)\n",
+ "\n",
+ "#Calculation\n",
+ "T=(0.161*V)/A; #Reverberation time(s)\n",
+ "\n",
+ "#Result\n",
+ "print \"The reverberation time in a hall is\",round(T,2),\"s\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reverberation time in a hall is 1.65 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.10, Page number 13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "f1=400; #Initial frequency(kHZ)\n",
+ "f2=500; #New frequency(kHZ)\n",
+ "t1=3; #initial thickness of the crystal(mm)\n",
+ "\n",
+ "#Calculation\n",
+ "t2=(f1*t1)/f2; #required thickness(mm)\n",
+ "\n",
+ "#Result\n",
+ "print \"The required thickness of the crystal is\",t2,\"mm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The required thickness of the crystal is 2.4 mm\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.11, Page number 13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "t1=2; #Initial thickness(mm)\n",
+ "t2=2.8; #New thickness(mm)\n",
+ "\n",
+ "#Calculation\n",
+ "F=t1/t2; #ratio of new to old frequencies\n",
+ "\n",
+ "#Result\n",
+ "print \"The ratio of new to old frequencies is\",round(F,3),"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The ratio of new to old frequencies is 0.714\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/SantoshPawar/Chapter9.ipynb b/sample_notebooks/SantoshPawar/Chapter9.ipynb
new file mode 100755
index 00000000..1ffaf482
--- /dev/null
+++ b/sample_notebooks/SantoshPawar/Chapter9.ipynb
@@ -0,0 +1,569 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 09 : Transistor Biasing and Thermal Stabilization"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.1, Page No 55"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Vcc=22.5 #in V\n",
+ "Rc=5.6 #in K\n",
+ "Re=1.0 #in K\n",
+ "R2=10.0 #in K\n",
+ "R1=90.0 #in K\n",
+ "B=55.0 #beta\n",
+ "\n",
+ "#Calculations\n",
+ "V=(R2*Vcc)/(R2+R1) #Thevenin Equivallent Voltage\n",
+ "Rb=(R2*R1)/(R2+R1) #Thevenin Equivallent Resistance\n",
+ "\n",
+ "#For base current large compared to reverse saturation current ie Ib>>Ico it follows that Ic=B*Ib\n",
+ "#Applying KVL to the base circuit\n",
+ "#0.65-2.25+Ic+10*Ib=0\n",
+ "#We have -1.60+Ic+(10/55)*Ic=0\n",
+ "\n",
+ "Ic=1.60/(65.0/55);\n",
+ "Ib=Ic/55.0\n",
+ "\n",
+ "#Applying KVL to the collector circuit yields\n",
+ "#-22.5+6.6*Ic+Ib+Vce\n",
+ "\n",
+ "Vce = 22.5-(6.6*1.36)-0.025\n",
+ "\n",
+ "#Results\n",
+ "print(\"The equivallent Vbb = %.2f Volts \" %V)\n",
+ "print(\"The equivallent Rb is = %.2f ohm \" %Rb)\n",
+ "print(\"As B=55 we have Ic=55*Ib \")\n",
+ "print(\" Ic= %.2f milli amp \" %Ic)\n",
+ "print(\"Ib= %.2f micro amp \" %Ib)\n",
+ "print(\"Vce= %.2f Volts \" %Vce)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The equivallent Vbb = 2.25 Volts \n",
+ "The equivallent Rb is = 9.00 ohm \n",
+ "As B=55 we have Ic=55*Ib \n",
+ " Ic= 1.35 milli amp \n",
+ "Ib= 0.02 micro amp \n",
+ "Vce= 13.50 Volts \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.2, Page No 61"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialisation of variables\n",
+ "Rc=4.0 #in K\n",
+ "Vcc=20.0 #in V\n",
+ "Vce=10.0 #in V\n",
+ "Ic=2.0 #in mA\n",
+ "#Ic varies from 1.75 to 2.25 and B(beta) varies from 36 to 90\n",
+ "Re = (Vcc-Vce)/Ic - Rc\n",
+ "#S=delta Ic/delta B\n",
+ "Ic2=2.25 #in mA\n",
+ "Ic1=1.75 #in mA\n",
+ "B2=90.0\n",
+ "B1=36.0\n",
+ "\n",
+ "#Calculations\n",
+ "S=(Ic2-Ic1)/(B2-B1)\n",
+ "S2=(S*36*(1+90))/1.75\n",
+ "#S2=(1+B)*(1+(Rb/Re))/(1+B+(Rb/Re))\n",
+ "Rb=(S2-1)*(1+B2)*Re/(1+B2-S2);\n",
+ "Vbe=0.65 #in V\n",
+ "V = Vbe + ((Rb+Re*(1+B1))*Ic1/B1);\n",
+ "R1=Rb*Vcc/V\n",
+ "R2=R1*V/(Vcc-V)\n",
+ "\n",
+ "#Results\n",
+ "print(\"S2 = %.2f K \" %S2)\n",
+ "print(\"Re = is %.2f B2=90 \" %Re)\n",
+ "print(\"Rb= %.2f K \" %Rb)\n",
+ "print(\"V = %.2f Volts \" %V)\n",
+ "print(\"R1= %.2f K \" %R1)\n",
+ "print(\"R2= %.2f K \" %R2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "S2 = 17.33 K \n",
+ "Re = is 1.00 B2=90 \n",
+ "Rb= 20.18 K \n",
+ "V = 3.43 Volts \n",
+ "R1= 117.67 K \n",
+ "R2= 24.35 K \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.3a Page No 69"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialisation of variables\n",
+ "Re=4.7 #in K\n",
+ "Rb=7.75 #in K\n",
+ "B1=55.0 #/beta at 25degree C\n",
+ "Ic1=1.5 #in mA\n",
+ "Ico1=1.0\n",
+ "Vbe1=0.6 #in V\n",
+ "\n",
+ "#Part a\n",
+ "\n",
+ "Ico2=33000.0 #in nA\n",
+ "Vbe2=0.225 #in V\n",
+ "\n",
+ "#Calculations\n",
+ "M1=1/(1+(Rb/(Re*B1))) #Stability Factor\n",
+ "B2=100.0 #at 175degree C\n",
+ "M2=1/(1+(Rb/(Re*B2))) #Stability Factor\n",
+ "\n",
+ "print(\"Stabitity Factor at 25deree C= %.2f \" %M1)\n",
+ "print(\"Stabitity Factor at 175deree C= %.2f \" %M2)\n",
+ "\n",
+ "if M2>M1 :\n",
+ " M1=1.0\n",
+ " M2=1.0\n",
+ "\n",
+ "\n",
+ "#Let k = (delta Ic)/(Ic1)\n",
+ "k=(1+(Rb/Re))*(M1*(Ico2-Ico1)*(10**-9)/Ic1*(10**-3))-(M1*(Vbe2-Vbe1)/(Ic1*Re))+(1+(Rb/Re))*(M2*(B2-B1)/(B2*B1));\n",
+ "deltaIc=k*Ic1\n",
+ "print(\"Change in Collector Current at 175degree C is = %.2f mA\" %deltaIc)\n",
+ "\n",
+ "\n",
+ "#Given Data at -65degree C\n",
+ "Ico2=1.95*(10**-3)\n",
+ "B2=25.0\n",
+ "Vbe2=0.78\n",
+ "\n",
+ "M2=1/(1+(Rb/(Re*B2))) #Stability Factor\n",
+ "print(\"Stabitity Factor at -65deree C= %.2f \" %M2)\n",
+ " \n",
+ "#Let k = (delta Ic)/(Ic1)\n",
+ "k=(1+(Rb/Re))*(M1*(Ico2-Ico1)*(10**-9)/Ic1*(10**-3))-(M1*(Vbe2-Vbe1)/(Ic1*Re))+(1+(Rb/Re))*(M2*(B2-B1)/(B2*B1))\n",
+ "deltaIc=k*Ic1\n",
+ "\n",
+ "#Results\n",
+ "print(\"Change in Collector Current at -65degree C is = %.2f mA\" %deltaIc)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Stabitity Factor at 25deree C= 0.97 \n",
+ "Stabitity Factor at 175deree C= 0.98 \n",
+ "Change in Collector Current at 175degree C is = 0.11 mA\n",
+ "Stabitity Factor at -65deree C= 0.94 \n",
+ "Change in Collector Current at -65degree C is = -0.12 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.3b, Page No 70"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Re=4.7 #in K\n",
+ "Rb=7.75 #in K\n",
+ "B1=55.0 #/beta at 25degree C\n",
+ "Ic1=1.5 #in mA\n",
+ "Ico1=1.0\n",
+ "Vbe1=0.6 #in V\n",
+ "\n",
+ "\n",
+ "#Part a\n",
+ "\n",
+ "Ico2=33000.0 #in nA\n",
+ "Vbe2=0.225 #in V\n",
+ "\n",
+ "#Calculations\n",
+ "M1=1/(1+(Rb/(Re*B1))) #Stability Factor\n",
+ "#Given Data at -65degree C\n",
+ "Ico2=1.95*(10**-3)\n",
+ "B2=25.0 #at -65degree C\n",
+ "Vbe2=0.78\n",
+ "M2=1/(1+(Rb/(Re*B2))) #Stability Factor\n",
+ "\n",
+ "#Let k = (delta Ic)/(Ic1)\n",
+ "k=(1+(Rb/Re))*(M1*(Ico2-Ico1)*(10**-9)/Ic1*(10**-3))-(M1*(Vbe2-Vbe1)/(Ic1*Re))+(1+(Rb/Re))*(M2*(B2-B1)/(B2*B1));\n",
+ "deltaIc=k*Ic1\n",
+ "\n",
+ "\n",
+ "\n",
+ "#Given Data\n",
+ "Ico2=32.0 #in nA\n",
+ "Vbe2=0.10 #in V\n",
+ "M1=1/(1+(Rb/(Re*B1))) #Stability Factor\n",
+ "print(\"Stabitity Factor at 25deree C= %.2f \" %M1)\n",
+ "B2=90.0 #at 175degree C\n",
+ "M2=1/(1+(Rb/(Re*B2))) #Stability Factor\n",
+ "print(\"Stabitity Factor at 75deree C= %.2f \" %M2)\n",
+ "\n",
+ "if M2>M1 :\n",
+ " M1=1.0\n",
+ " M2=1.0\n",
+ "\n",
+ "#Let k = (delta Ic)/(Ic1)\n",
+ "k=(1+(Rb/Re))*(M1*(Ico2-Ico1)*(10**-9)/Ic1*(10**-3))-(M1*(Vbe2-Vbe1)/(Ic1*Re))+(1+(Rb/Re))*(M2*(B2-B1)/(B2*B1));\n",
+ "deltaIc=k*Ic1\n",
+ "print(\"Change in Collector Current at 75degree C is = %.2f mA\" %deltaIc)\n",
+ "\n",
+ "#Given Data at -65degree C\n",
+ "Ico2=1.95*(10**-3)\n",
+ "B2=20.0\n",
+ "Vbe2=0.38\n",
+ "\n",
+ "M2=1/(1+(Rb/(Re*B2))) #Stability Factor\n",
+ "print(\"Stabitity Factor at -65deree C= %.2f \" %M2)\n",
+ " \n",
+ " \n",
+ "#Let k = (delta Ic)/(Ic1)\n",
+ "k=(1+(Rb/Re))*(M1*(Ico2-Ico1)*(10**-9)/Ic1*(10**-3))-(M1*(Vbe2-Vbe1)/(Ic1*Re))+(1+(Rb/Re))*(M2*(B2-B1)/(B2*B1));\n",
+ "deltaIc=k*Ic1\n",
+ "print(\"Change in Collector Current at -65degree C is = %.2f mA\" %deltaIc)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Stabitity Factor at 25deree C= 0.97 \n",
+ "Stabitity Factor at 75deree C= 0.98 \n",
+ "Change in Collector Current at 75degree C is = 0.13 mA\n",
+ "Stabitity Factor at -65deree C= 0.92 \n",
+ "Change in Collector Current at -65degree C is = -0.07 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4 Page No 71"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "\n",
+ "B1=150.0 #beta\n",
+ "Ico1=50.0 #in nA\n",
+ "\n",
+ "#Given Data at 65degree C\n",
+ "B2=1200.0 #beta\n",
+ "Ico2=3.0 #in micro A\n",
+ "\n",
+ "Vbe=0.65 #in mV\n",
+ "Vcc=20.0 #in V\n",
+ "M=1.0 \n",
+ "#Assumption: Each factor Ico,B, and Vbe cuses the same percentge change(5%)\n",
+ "\n",
+ "#Let Rb/Re=k\n",
+ "#(1+k)*((1200-150)/(1200*150))=0.05\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "k=((0.05)*((1200*150)/(1200-150)))-1\n",
+ "print(\"Rb/Re = %.2f \" %k)\n",
+ "#Let us check our assumption\n",
+ "\n",
+ "if M>(1.0/(1+(k/B1))) :\n",
+ " M=1.0\n",
+ "\n",
+ "#(1+(Rb/Re))*((Ico2-Ico1)/Ic1)=0.05 Since Ico2>>Ico1, we consider only Ico2\n",
+ "\n",
+ "Ic1=((1+k)*Ico2)/(0.05*1000)\n",
+ "print(\"Ic1= %.2f mA \" %Ic1)\n",
+ "\n",
+ "#Vbe changes 2.5mV/degree\n",
+ "DVbe=2.5*40\n",
+ "#Total increment\n",
+ "dVbe=2*DVbe*(10**-3)\n",
+ "\n",
+ "#Let l=(Ic1*Re)\n",
+ "l=dVbe/0.05\n",
+ "\n",
+ "Re=l/Ic1\n",
+ "print(\"Re= %.2f \" %Re)\n",
+ "Rb=k*Re\n",
+ "print(\"Rb= %.2f \" %Rb)\n",
+ "\n",
+ "B=(B1+B2)/2 #beta\n",
+ "V=((Ic1/B)*Rb)+(Vbe)+(((Ic1/B)+Ic1)*Re)\n",
+ "print(\"V= %.2f Volts\" %V)\n",
+ "R1=(Rb*Vcc)/V\n",
+ "R2=(R1*V)/(Vcc-V)\n",
+ "\n",
+ "#Results\n",
+ "print(\"R1= %.2f ohm\" %R1)\n",
+ "print(\"R2= %.2f ohm\" %R2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rb/Re = 7.55 \n",
+ "Ic1= 0.51 mA \n",
+ "Re= 7.80 \n",
+ "Rb= 58.87 \n",
+ "V= 4.70 Volts\n",
+ "R1= 250.47 ohm\n",
+ "R2= 76.96 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.5 Page No 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialisation of variables\n",
+ "\n",
+ "Vcc=30.0 #in V\n",
+ "Rc=2.0 #in K\n",
+ "Re=4.7 #in K\n",
+ "Ic=1.5 #in mA\n",
+ "\n",
+ "#We know that dPc/dIc = Vcc - (2*Ic*(Rc+Re))\n",
+ "#Let D=dPc/dIc\n",
+ "\n",
+ "D = Vcc - (2*Ic*(Re+Rc))\n",
+ "\n",
+ "print('Ic increases by 0.131mA over a temprature range of 35 to 75 degree C')\n",
+ "print('theta<(A=(dPc/dIc)*(dIc/dTc))')\n",
+ "A=D*((0.131*(10^-3))/(75-25))\n",
+ "\n",
+ "#Results\n",
+ "print(\"theta< %.2f degreeC/W \" %(1.0/A))\n",
+ "print('The upper bound on theta is so high that transistor would not violate it and therefore circuit will be safe from thermal runaway')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ic increases by 0.131mA over a temprature range of 35 to 75 degree C\n",
+ "theta<(A=(dPc/dIc)*(dIc/dTc))\n",
+ "theta< -4.28 degreeC/W \n",
+ "The upper bound on theta is so high that transistor would not violate it and therefore circuit will be safe from thermal runaway\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6a, Page No 79 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "B=100.0 #beta\n",
+ "Ico=-5.0 #in mA\n",
+ "Ic=-1.0 #in mA\n",
+ "Vcc=40.0 \n",
+ "Re=5.0 #in ohm\n",
+ "Rc=10.0 #in ohm\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "#Ic= BIb + (1+B)*Ico\n",
+ "#Ic=B(Ib+Ico)\n",
+ "Ib=-(Ic/B)+Ico\n",
+ "\n",
+ "print(\"Ib= %.2f mA \" %Ib)\n",
+ "#Neglecting Vbe\n",
+ "Rb=(5-Vcc)/(Ib*0.001)\n",
+ "print(\"Rb= %.2f ohm \" %Rb)\n",
+ "\n",
+ "Vce=Vcc-15\n",
+ "if Vce>(Vcc/2) :\n",
+ " S=(1+B)*(1+(Rb/Re))/(1+B+(Rb/Re))\n",
+ " print(\"Stability Factor is= %.2f \" %S)\n",
+ "\n",
+ "A=-(Vcc+(2*Ic*(Re+Rc)))*(S)*(0.007*Ico*0.01)\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print(\"theta< %.2f degreeC/W \" %(1.0/A))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ib= -4.99 mA \n",
+ "Rb= 7014.03 ohm \n",
+ "Stability Factor is= 94.28 \n",
+ "theta< 3.03 degreeC/W \n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6b Page No 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\n",
+ "#initialisation of variables\n",
+ "B=100.0 #beta\n",
+ "Ico=-5.0 #in mA\n",
+ "Ic=-1.0 #in mA\n",
+ "Vcc=40.0 \n",
+ "Re=5.0 #in ohm\n",
+ "Rc=10.0 #in ohm\n",
+ "\n",
+ "#Calculations\n",
+ "#Ic= BIb + (1+B)*Ico\n",
+ "#Ic=B(Ib+Ico)\n",
+ "Ib=-(Ic/B)+Ico\n",
+ "\n",
+ "#Neglecting Vbe\n",
+ "Rb=(5-Vcc)/(Ib*0.001)\n",
+ "\n",
+ "Vce=Vcc-15\n",
+ "if Vce>(Vcc/2) :\n",
+ " S=(1+B)*(1+(Rb/Re))/(1+B+(Rb/Re))\n",
+ " print(\"Stability Factor is= %.2f \" %S)\n",
+ "\n",
+ "A=-(Vcc+(2*Ic*(Re+Rc)))*(S)*(0.007*Ico*0.01)\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print(\"theta< %.2f degreeC/W \" %(1.0/A))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ib= -4.99 mA \n",
+ "Rb= 7014.03 ohm \n",
+ "Stability Factor is= 94.28 \n",
+ "theta< 3.03 degreeC/W \n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/Sashankkonete/Chapter1.ipynb b/sample_notebooks/Sashankkonete/Chapter1.ipynb
new file mode 100755
index 00000000..75a00457
--- /dev/null
+++ b/sample_notebooks/Sashankkonete/Chapter1.ipynb
@@ -0,0 +1,458 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:edfd4792836df6190ed0a8d87ba87b2a1115c66d7d1cb21a33ed50c25e8f72b5"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1 - Electric drives"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1 - pg 6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the Total annual cost in both cases\n",
+ "#Initialization of variables\n",
+ "C_g=60000.;#in Rs\n",
+ "C_id=18750*10;#in Rs\n",
+ "E_c=75000;#in kWh\n",
+ "E_a=60000;#in kWh\n",
+ "#Calculations\n",
+ "D=0.12*C_g;#in Rs\n",
+ "C_e=4*E_c;#in Rs\n",
+ "C_t=D+C_e;#in Rs\n",
+ "AD=0.15*C_id;#in Rs\n",
+ "C_ea=4*E_a;#in Rs\n",
+ "C_total=AD+C_ea;#in Rs\n",
+ "#Results\n",
+ "print 'Total annual cost in case of group drive (in Rs)=',C_t\n",
+ "print 'Total annual cost in case of individual drive (in Rs)=',C_total"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total annual cost in case of group drive (in Rs)= 307200.0\n",
+ "Total annual cost in case of individual drive (in Rs)= 268125.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2 - pg 17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the stable operating point\n",
+ "import math\n",
+ "#Initialization of variables\n",
+ "a=1;\n",
+ "b=1;\n",
+ "c=-30;\n",
+ "#Calculations\n",
+ "w_m=(-b+math.sqrt((b**2)-4*a*c))/(2*a);#speed of the drive\n",
+ "t_l=0.5*(w_m**2);#motoring torqe \n",
+ "#Results\n",
+ "print 'stable operating point=',w_m,t_l"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "stable operating point= 5.0 12.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3 - pg 18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the power developed by the motor\n",
+ "#Initialization of variables\n",
+ "import math\n",
+ "J_m=0.4;#motor inertia(in Kg-m2)\n",
+ "J_l=10.;#load inertia(in Kg-m2)\n",
+ "a=0.1;#Teeth ratio of gear\n",
+ "i=1./a;\n",
+ "N=1400.;\n",
+ "pi=22./7.;\n",
+ "n=0.90;#efficency of motor\n",
+ "T_l=50.;#Torque(N-m)\n",
+ "#Calculations\n",
+ "J=J_m+J_l/(i**2);#Total moment of inertia referred to the motor shaft\n",
+ "T_L=T_l/(i*n);#total equivalent torque referref to motor shaft\n",
+ "P=T_L*2*pi*N/60.;#power developed by motor\n",
+ "#Results\n",
+ "print 'power developed by motor(in Watt)=',math.ceil(P)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "power developed by motor(in Watt)= 815.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4 - pg 19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the total torque and power developed\n",
+ "#Initialization of variables\n",
+ "import math\n",
+ "J_m=0.4;#motor inertia(in Kg-m2)\n",
+ "J_l=10;#load inertia(in Kg-m2)\n",
+ "a=0.1;#Teeth ratio of gear\n",
+ "N=1500.;\n",
+ "n_t=0.88;\n",
+ "m=600.;#weight\n",
+ "g=9.81;\n",
+ "#Calculations\n",
+ "f_r=m*g;#force\n",
+ "w_m=2*math.pi*N/60.;#motor speed\n",
+ "w=2.;#uniform speed of weight lifting\n",
+ "n=0.9;#efficency of motor\n",
+ "T_l=50;#Torque(N-m)\n",
+ "J=J_m+(a**2)*J_l+m*((w/w_m)**2);#Total moment of inertia referred to the motor shaft\n",
+ "T_L=(a*T_l/n)+f_r*w/(n_t*w_m) ;#total equivalent torque referred to motor shaft\n",
+ "p=T_L*w_m;#power developed by motor(in Watt)\n",
+ "P=p/1000.;#power developed by motor(in kWatt)\n",
+ "#Results\n",
+ "print 'Total torque referred to motor shaft(in kg-m2)=',round(J,2)\n",
+ "print 'Total equivalent Torque referred to motor shaft(in N-m)=',round(T_L,2)\n",
+ "print 'power developed by motor(in kWatt)=',round(P,2)\n",
+ "print 'The answers are a bit different from textbook due to rounding off error'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total torque referred to motor shaft(in kg-m2)= 0.6\n",
+ "Total equivalent Torque referred to motor shaft(in N-m)= 90.72\n",
+ "power developed by motor(in kWatt)= 14.25\n",
+ "The answers are a bit different from textbook due to rounding off error\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5 - pg 50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the Motor Speed\n",
+ "#Initialization of variables\n",
+ "import math\n",
+ "from math import ceil\n",
+ "V=220.;#in volts\n",
+ "V_1=200.;#in volts\n",
+ "N=1000.;#in rpm\n",
+ "I=100.;#in amperes\n",
+ "R_a=0.1;#in ohms\n",
+ "#Calculations\n",
+ "E_b=V-I*R_a;#in volts\n",
+ "I_1=I;#in amperes\n",
+ "E_b1=V_1-I_1*R_a;#in volts\n",
+ "N_1=N*E_b1/E_b;\n",
+ "#Results\n",
+ "print 'Motor Speed (in rpm)=',ceil(N_1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Motor Speed (in rpm)= 905.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6 - pg 50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the full load Speed and Torque\n",
+ "#Initialization of variables\n",
+ "import math\n",
+ "from math import ceil\n",
+ "V=230;#in volts\n",
+ "R_sh=230;#in ohms\n",
+ "R_a=0.5;#in ohms\n",
+ "I_sh=V/R_sh;#in amperes\n",
+ "#Calculations\n",
+ "I_lo=3;#in amperes\n",
+ "I_ao=I_lo-I_sh;#in amperes\n",
+ "E_bo=V-I_ao*R_a;#in volts\n",
+ "N_o=1000;#in rpm\n",
+ "I_lf=23;#in amperes\n",
+ "I_af=I_lf-I_sh;#in amperes\n",
+ "E_bf=V-I_af*R_a;#in volts\n",
+ "Phy_ratio=0.98;\n",
+ "N_f=N_o*(E_bf/E_bo)/Phy_ratio;\n",
+ "T_f=9.55*E_bf*I_af/N_f;\n",
+ "#Results\n",
+ "print 'Full Load Speed (in rpm)=',ceil(N_f)\n",
+ "print 'Full load Torque (in Newton-meter)=',round(T_f,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Full Load Speed (in rpm)= 976.0\n",
+ "Full load Torque (in Newton-meter)= 47.15\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7 - pg 51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the Armature voltage drop at full load\n",
+ "#Initialization of variables\n",
+ "V=440.;#in volts\n",
+ "N_o=2000.;#in rpm\n",
+ "E_bo=440.;#in volts\n",
+ "N_f=1000.;#in rpm\n",
+ "N_h=1050.;#in rpm\n",
+ "#Calculations\n",
+ "E_bf=E_bo*N_f/N_o#in volts\n",
+ "E_b=E_bo*N_h/N_o;#in volts\n",
+ "v=(E_b-E_bf)*2;\n",
+ "#Results\n",
+ "print 'Armature voltage drop at full load (in volts)=',v"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Armature voltage drop at full load (in volts)= 22.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8 - pg 51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the Speed\n",
+ "#Initialization of variables\n",
+ "V=230.;#in volts\n",
+ "N1=750.;#in rpm\n",
+ "R=10.;#in ohms\n",
+ "I_a=30.;#in amperes\n",
+ "#Calculations\n",
+ "N2=N1*((V+I_a*R)/V)**-1;\n",
+ "#Results\n",
+ "print'Speed (in rpm)=',int(N2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Speed (in rpm)= 325\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9 - pg 52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the Speed in both cases\n",
+ "import math\n",
+ "from math import ceil\n",
+ "#Initialization of variables\n",
+ "V=200.;#in volts\n",
+ "I_1=20.#in amperes\n",
+ "R_a=0.5;#in ohms\n",
+ "#Calculations\n",
+ "E_b1=V-I_1*R_a;#in volts\n",
+ "N1=700;#in rpm\n",
+ "I_2=math.sqrt(1.44)*I_1;#in amperes\n",
+ "E_b2=V-I_2*R_a;#in volts\n",
+ "N2=N1*(E_b2/E_b1)*(I_1/I_2);\n",
+ "I_3=10;#in amperes\n",
+ "E_b3=V-I_3*R_a;#in volts\n",
+ "N3=N1*(E_b3/E_b1)*(I_1/I_3);\n",
+ "#Results\n",
+ "print '(a) Speed (in rpm)=',round(N2,1)\n",
+ "print '(b) Speed (in rpm)=',ceil(N3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) Speed (in rpm)= 577.2\n",
+ "(b) Speed (in rpm)= 1437.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10 - pg 52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#calculate the Torque and Speed\n",
+ "#Initialization of variables\n",
+ "import math\n",
+ "from math import ceil\n",
+ "V=230.;#in volts\n",
+ "I_1=90.;#in amperes\n",
+ "R_a=0.08;#in ohms\n",
+ "R_se=0.05;#in ohms\n",
+ "E_2=180.;#in volts\n",
+ "N2=700.;#in rpm\n",
+ "R=1.5;#in ohms\n",
+ "#Calculations\n",
+ "R_m=R_a+R_se;#in ohms\n",
+ "E_b1=V-I_1*(R_m+R);#in volts\n",
+ "N1=N2*(E_b1/E_2);\n",
+ "T=9.55*E_b1*I_1/N1;\n",
+ "#Results\n",
+ "print 'Speed (in rpm)=',ceil(N1)\n",
+ "print 'Torque (in Newton-meter)=',round(T,0)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Speed (in rpm)= 324.0\n",
+ "Torque (in Newton-meter)= 221.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
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
+}
diff --git a/sample_notebooks/ShriniwasSabban/Chapter2.ipynb b/sample_notebooks/ShriniwasSabban/Chapter2.ipynb
new file mode 100755
index 00000000..1872c9f4
--- /dev/null
+++ b/sample_notebooks/ShriniwasSabban/Chapter2.ipynb
@@ -0,0 +1,233 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 02 : Power Semiconductor Diodes and Transistors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1, Page No 21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "B=40.0\n",
+ "R_c=10 #ohm\n",
+ "V_cc=130.0 #V\n",
+ "V_B=10.0 #V\n",
+ "V_CES=1.0 #V\n",
+ "V_BES=1.5 #V\n",
+ "\n",
+ "#Calculations\n",
+ "I_CS=(V_cc-V_CES)/R_c #A\n",
+ "I_BS=I_CS/B #A\n",
+ "R_B1=(V_B-V_BES)/I_BS\n",
+ "P_T1=V_BES*I_BS+V_CES*I_CS\n",
+ "ODF=5\n",
+ "I_B=ODF*I_BS\n",
+ "R_B2=(V_B-V_BES)/I_B\n",
+ "P_T2=V_BES*I_B+V_CES*I_CS\n",
+ "B_f=I_CS/I_B\n",
+ "\n",
+ "#Results\n",
+ "print(\"value of R_B in saturated state= %.2f ohm\" %R_B1)\n",
+ "print(\"Power loss in transistor=%.2f W\" %P_T1)\n",
+ "print(\"Value of R_B for an overdrive factor 5 = %.2f ohm\" %R_B2)\n",
+ "print(\"Power loss in transistor = %.2f W\" %P_T2)\n",
+ "print(\"Forced current gain=%.0f\" %B_f)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of R_B in saturated state= 26.36 ohm\n",
+ "Power loss in transistor=13.38 W\n",
+ "Value of R_B for an overdrive factor 5 = 5.27 ohm\n",
+ "Power loss in transistor = 15.32 W\n",
+ "Forced current gain=8\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2, Page No 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialisation of variables\n",
+ "I_CEO=2*10**-3 #A\n",
+ "V_CC=220.0 #V\n",
+ "P_dt=I_CEO*V_CC #instant. power loss during delay time\n",
+ "t_d=.4*10**-6 #s\n",
+ "f=5000\n",
+ "P_d=f*I_CEO*V_CC*t_d #avg power loss during delay time\n",
+ "V_CES=2 #V\n",
+ "t_r=1*10**-6 #s\n",
+ "I_CS=80 #A\n",
+ "\n",
+ "#Calculations\n",
+ "P_r=f*I_CS*t_r*(V_CC/2-(V_CC-V_CES)/3) #avg power loss during rise time\n",
+ "t_m=V_CC*t_r/(2*(V_CC-V_CES))\n",
+ "P_rm=I_CS*V_CC**2/(4*(V_CC-V_CES)) #instant. power loss during rise time\n",
+ "\n",
+ "#Results\n",
+ "P_on=P_d+P_r \n",
+ "print(\"Avg power loss during turn on = %.2f W\" %P_on)\n",
+ "P_nt=I_CS*V_CES \n",
+ "print(\"Instantaneous power loss during turn on = %.0f W\" %P_nt)\n",
+ "t_n=50*10**-6\n",
+ "P_n=f*I_CS*V_CES*t_n\n",
+ "print(\"Avg power loss during conduction period = %.0f W\" %P_n)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Avg power loss during turn on = 14.93 W\n",
+ "Instantaneous power loss during turn on = 160 W\n",
+ "Avg power loss during conduction period = 40 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3 Page No 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialisation of variables\n",
+ "I_CEO=2*10**-3 #A\n",
+ "V_CC=220 #V\n",
+ "t_d=.4*10**-6 #s\n",
+ "f=5000\n",
+ "V_CES=2 #V\n",
+ "t_r=1*10**-6 #s\n",
+ "I_CS=80 #A\n",
+ "t_n=50*10**-6 #s\n",
+ "t_0=40*10**-6 #s\n",
+ "t_f=3*10**-6 #s\n",
+ "\n",
+ "#Calculations\n",
+ "P_st=I_CS*V_CES # instant. power loss during t_s\n",
+ "P_s=f*I_CS*V_CES*t_f #avg power loss during t_s\n",
+ "P_f=f*t_f*(I_CS/6)*(V_CC-V_CES) #avg power loss during fall time\n",
+ "P_fm=(I_CS/4)*(V_CC-V_CES) #peak instant power dissipation\n",
+ "P_off=P_s+P_f\n",
+ "\n",
+ "#Results\n",
+ "print(\"Total avg power loss during turn off = %.2f W\" %P_off)\n",
+ "P_0t=I_CEO*V_CC\n",
+ "print(\"Instantaneous power loss during t_0 = %.2f W\" %P_0t)\n",
+ "P_0=f*I_CEO*V_CC*t_0 #avg power loss during t_s\n",
+ "P_on=14.9339 #W from previous eg\n",
+ "P_n=40 #W from previous eg\n",
+ "P_T=P_on+P_n+P_off+P_0 \n",
+ "print(\"Total power loss = %.2f W\" %P_T)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total avg power loss during turn off = 44.91 W\n",
+ "Instantaneous power loss during t_0 = 0.44 W\n",
+ "Total power loss = 99.93 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4, Page No 28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "I_CS=100.0 \n",
+ "V_CC=200.0 \n",
+ "t_on=40*10**-6\n",
+ "\n",
+ "#Calculations\n",
+ "P_on=(I_CS/50)*10**6*t_on*(V_CC*t_on/2-(V_CC*10**6*t_on**2/(40*3))) #energy during turn on\n",
+ "t_off=60*10**-6\n",
+ "P_off=(I_CS*t_off/2-(I_CS/60)*10**6*(t_off**2)/3)*((V_CC/75)*10**6*t_off) #energy during turn off\n",
+ "P_t=P_on+P_off #total energy\n",
+ "P_avg=300.0\n",
+ "f=P_avg/P_t\n",
+ "\n",
+ "#Results\n",
+ "print(\"Allowable switching frequency = %.2f Hz\" %f)\n",
+ "#in book ans is: f=1123.6 Hz. The difference in results due to difference in rounding of of digits"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Allowable switching frequency = 1125.00 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/ShriniwasSabban/Chapter2_1.ipynb b/sample_notebooks/ShriniwasSabban/Chapter2_1.ipynb
new file mode 100755
index 00000000..1872c9f4
--- /dev/null
+++ b/sample_notebooks/ShriniwasSabban/Chapter2_1.ipynb
@@ -0,0 +1,233 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 02 : Power Semiconductor Diodes and Transistors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1, Page No 21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "B=40.0\n",
+ "R_c=10 #ohm\n",
+ "V_cc=130.0 #V\n",
+ "V_B=10.0 #V\n",
+ "V_CES=1.0 #V\n",
+ "V_BES=1.5 #V\n",
+ "\n",
+ "#Calculations\n",
+ "I_CS=(V_cc-V_CES)/R_c #A\n",
+ "I_BS=I_CS/B #A\n",
+ "R_B1=(V_B-V_BES)/I_BS\n",
+ "P_T1=V_BES*I_BS+V_CES*I_CS\n",
+ "ODF=5\n",
+ "I_B=ODF*I_BS\n",
+ "R_B2=(V_B-V_BES)/I_B\n",
+ "P_T2=V_BES*I_B+V_CES*I_CS\n",
+ "B_f=I_CS/I_B\n",
+ "\n",
+ "#Results\n",
+ "print(\"value of R_B in saturated state= %.2f ohm\" %R_B1)\n",
+ "print(\"Power loss in transistor=%.2f W\" %P_T1)\n",
+ "print(\"Value of R_B for an overdrive factor 5 = %.2f ohm\" %R_B2)\n",
+ "print(\"Power loss in transistor = %.2f W\" %P_T2)\n",
+ "print(\"Forced current gain=%.0f\" %B_f)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of R_B in saturated state= 26.36 ohm\n",
+ "Power loss in transistor=13.38 W\n",
+ "Value of R_B for an overdrive factor 5 = 5.27 ohm\n",
+ "Power loss in transistor = 15.32 W\n",
+ "Forced current gain=8\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2, Page No 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialisation of variables\n",
+ "I_CEO=2*10**-3 #A\n",
+ "V_CC=220.0 #V\n",
+ "P_dt=I_CEO*V_CC #instant. power loss during delay time\n",
+ "t_d=.4*10**-6 #s\n",
+ "f=5000\n",
+ "P_d=f*I_CEO*V_CC*t_d #avg power loss during delay time\n",
+ "V_CES=2 #V\n",
+ "t_r=1*10**-6 #s\n",
+ "I_CS=80 #A\n",
+ "\n",
+ "#Calculations\n",
+ "P_r=f*I_CS*t_r*(V_CC/2-(V_CC-V_CES)/3) #avg power loss during rise time\n",
+ "t_m=V_CC*t_r/(2*(V_CC-V_CES))\n",
+ "P_rm=I_CS*V_CC**2/(4*(V_CC-V_CES)) #instant. power loss during rise time\n",
+ "\n",
+ "#Results\n",
+ "P_on=P_d+P_r \n",
+ "print(\"Avg power loss during turn on = %.2f W\" %P_on)\n",
+ "P_nt=I_CS*V_CES \n",
+ "print(\"Instantaneous power loss during turn on = %.0f W\" %P_nt)\n",
+ "t_n=50*10**-6\n",
+ "P_n=f*I_CS*V_CES*t_n\n",
+ "print(\"Avg power loss during conduction period = %.0f W\" %P_n)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Avg power loss during turn on = 14.93 W\n",
+ "Instantaneous power loss during turn on = 160 W\n",
+ "Avg power loss during conduction period = 40 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3 Page No 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialisation of variables\n",
+ "I_CEO=2*10**-3 #A\n",
+ "V_CC=220 #V\n",
+ "t_d=.4*10**-6 #s\n",
+ "f=5000\n",
+ "V_CES=2 #V\n",
+ "t_r=1*10**-6 #s\n",
+ "I_CS=80 #A\n",
+ "t_n=50*10**-6 #s\n",
+ "t_0=40*10**-6 #s\n",
+ "t_f=3*10**-6 #s\n",
+ "\n",
+ "#Calculations\n",
+ "P_st=I_CS*V_CES # instant. power loss during t_s\n",
+ "P_s=f*I_CS*V_CES*t_f #avg power loss during t_s\n",
+ "P_f=f*t_f*(I_CS/6)*(V_CC-V_CES) #avg power loss during fall time\n",
+ "P_fm=(I_CS/4)*(V_CC-V_CES) #peak instant power dissipation\n",
+ "P_off=P_s+P_f\n",
+ "\n",
+ "#Results\n",
+ "print(\"Total avg power loss during turn off = %.2f W\" %P_off)\n",
+ "P_0t=I_CEO*V_CC\n",
+ "print(\"Instantaneous power loss during t_0 = %.2f W\" %P_0t)\n",
+ "P_0=f*I_CEO*V_CC*t_0 #avg power loss during t_s\n",
+ "P_on=14.9339 #W from previous eg\n",
+ "P_n=40 #W from previous eg\n",
+ "P_T=P_on+P_n+P_off+P_0 \n",
+ "print(\"Total power loss = %.2f W\" %P_T)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total avg power loss during turn off = 44.91 W\n",
+ "Instantaneous power loss during t_0 = 0.44 W\n",
+ "Total power loss = 99.93 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4, Page No 28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "I_CS=100.0 \n",
+ "V_CC=200.0 \n",
+ "t_on=40*10**-6\n",
+ "\n",
+ "#Calculations\n",
+ "P_on=(I_CS/50)*10**6*t_on*(V_CC*t_on/2-(V_CC*10**6*t_on**2/(40*3))) #energy during turn on\n",
+ "t_off=60*10**-6\n",
+ "P_off=(I_CS*t_off/2-(I_CS/60)*10**6*(t_off**2)/3)*((V_CC/75)*10**6*t_off) #energy during turn off\n",
+ "P_t=P_on+P_off #total energy\n",
+ "P_avg=300.0\n",
+ "f=P_avg/P_t\n",
+ "\n",
+ "#Results\n",
+ "print(\"Allowable switching frequency = %.2f Hz\" %f)\n",
+ "#in book ans is: f=1123.6 Hz. The difference in results due to difference in rounding of of digits"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Allowable switching frequency = 1125.00 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/ShubhamRungta/Chapter2.ipynb b/sample_notebooks/ShubhamRungta/Chapter2.ipynb
new file mode 100755
index 00000000..b9dc8563
--- /dev/null
+++ b/sample_notebooks/ShubhamRungta/Chapter2.ipynb
@@ -0,0 +1,228 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:cba451428c3d9c574800bbc1429b7e9efcd18af4b82f735faf4ac85b4ea52c65"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter02:The 741 IC OP-AMP"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.1:Pg-80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Ex 2.1\n",
+ "\n",
+ "# data from fig of Ex2.1\n",
+ "VCC=5.0;#V\n",
+ "IS=10**-14.0;#A\n",
+ "RS=39*1000.0;#ohm\n",
+ "VBE12=0.7;#V(Assumed)\n",
+ "VBE11=0.7;#V(Assumed)\n",
+ "VEE=-5;#V\n",
+ "IREF=(VCC-VBE12-VBE11-VEE)/RS*10**6;#micro A\n",
+ "print \"Estimated input reference current , IREF(micro A)\",round(IREF,2)\n",
+ "VT=25*10**-3;#V(Thermal Voltage)\n",
+ "VBE=VT*log(IREF*10**-6/IS);#V\n",
+ "IREF=(VCC-VBE-VBE-VEE)/RS*10**6;#micro A\n",
+ "print \"More precise value of reference current , IREF(micro A)\",round(IREF,2)\n",
+ "#Replacing Vcc by 15 V in the original design\n",
+ "VCC2=15.0;#V\n",
+ "VEE2=-15.0;#V\n",
+ "IREF=(VCC2-VBE-VBE-VEE2)/RS*10**6;#micro A\n",
+ "VBE=VT*log(IREF*10**-6/IS);#V\n",
+ "R5=(VCC-VBE-VBE-VEE)/(IREF*10**-6);#ohm\n",
+ "R5=round(R5/1000);#kohm\n",
+ "print \"Value of R5(kohm) : \",R5"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Estimated input reference current , IREF(micro A) 220.51\n",
+ "More precise value of reference current , IREF(micro A) 225.88\n",
+ "Value of R5(kohm) : 12.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.2:Pg-81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Ex 2.2\n",
+ "import math\n",
+ "# data from fig of Ex2.2\n",
+ "IC10=20*10**-6;#A\n",
+ "IREF=0.5*10**-3;#A\n",
+ "IS=10**-14;#A\n",
+ "VT=25*10**-3;#V(Thermal Voltage)\n",
+ "R4=VT/IC10*math.log(IREF/IC10);#ohm\n",
+ "print \"For Widlar current source design, the value of R4(kohm) : \",round(R4/1000,2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For Widlar current source design, the value of R4(kohm) : 4.02\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.3:Pg-82"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Ex 2.3\n",
+ "\n",
+ "import math\n",
+ "# given data\n",
+ "Gm1=10.0;#mA/V\n",
+ "Gm1=Gm1/1000;#A/V\n",
+ "Cc=50.0;#pF\n",
+ "Cc=Cc*10**-12;#F\n",
+ "Rt=10**8;#ohm(Shunting resistance with Cc)\n",
+ " # solution\n",
+ "Ao=Gm1*Rt;#unitless\n",
+ "fp=1/(2*math.pi*Rt*Cc);#Hz\n",
+ "ft=Gm1/(2*math.pi*Cc)/10**6;#MHz\n",
+ "print \"Frequency at which gain is maximum, fp in Hz\",round(fp,1)\n",
+ "print \"Unit gain frequency, ft(MHz)\",round(ft,1)\n",
+ "#Bode plot can not be plotted with the given data in the question by using python functions. \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frequency at which gain is maximum, fp in Hz 31.8\n",
+ "Unit gain frequency, ft(MHz) 31.8\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.4:Pg-83"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Ex 2.4\n",
+ "\n",
+ "import math\n",
+ "# given data\n",
+ "SR=10.0/10**-6;#V/s\n",
+ "Vout=10.0;#V(magnitude of output voltage)\n",
+ "fm=SR/(2*math.pi*Vout)/1000;#kHz\n",
+ "print \"Full power bandwidth(kHz)\",round(fm,1)\n",
+ "VT=25.0/1000;#V(Thermal voltage)\n",
+ "ft=SR/(2*math.pi*4*VT)/10.0**6;#MHz\n",
+ "print \"Unity gain bandwidth(MHz)\",round(ft,1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Full power bandwidth(kHz) 159.2\n",
+ "Unity gain bandwidth(MHz) 15.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.5:Pg-84"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Ex 2.5\n",
+ "\n",
+ "VCC=5;#V\n",
+ "VEE=-5;#V\n",
+ "VBE=0.6;#V\n",
+ "VCE23=0.6;#V\n",
+ "VCE_sat=0.2;#V\n",
+ "Vo_max=VCC-VCE_sat-VBE;#V\n",
+ "Vo_min=VEE+VCE_sat+VBE+VCE23;#V\n",
+ "print \"Maximum output voltage(V)\",round(Vo_max,2)\n",
+ "print \"Minimum output voltage(V)\",round(Vo_min,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum output voltage(V) 4.2\n",
+ "Minimum output voltage(V) -3.6\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/SrutiGoyal/Chapter_11-_Object_Initialization_and_Clean-Up.ipynb b/sample_notebooks/SrutiGoyal/Chapter_11-_Object_Initialization_and_Clean-Up.ipynb
new file mode 100755
index 00000000..d3bdda01
--- /dev/null
+++ b/sample_notebooks/SrutiGoyal/Chapter_11-_Object_Initialization_and_Clean-Up.ipynb
@@ -0,0 +1,1779 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:64b755d597a2016634dadbbc81a598a60446119cc89f4f94fd9140b5bc077b77"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Object Initialization and clean up"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- bag.cpp, Page-392"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_ITEMS=25\n",
+ "def show(self):\n",
+ " for i in range(self.ItemCount):\n",
+ " print self._Bag__contents[i],\n",
+ "class Bag:\n",
+ " __contents=[int]*MAX_ITEMS\n",
+ " __ItemCount=int\n",
+ " def SetEmpty(self):\n",
+ " self.ItemCount=0\n",
+ " def put(self,item):\n",
+ " self._Bag__contents[self.ItemCount]=item\n",
+ " self.ItemCount+=1\n",
+ " show=show\n",
+ "bag=Bag() #object of class Bag\n",
+ "bag.SetEmpty() #initialize the object\n",
+ "while 1:\n",
+ " item=int(raw_input(\"\\nEnter Item Number to be put into the bag <0-no item>: \"))\n",
+ " if item==0:\n",
+ " break\n",
+ " bag.put(item)\n",
+ " print \"Items in bag:\",\n",
+ " bag.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Items in bag: 1"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3 2"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3 2 4"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- newbag.cpp, Page-395"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_ITEMS=25 #size of array contents\n",
+ "def show(self):\n",
+ " for i in range(self.ItemCount):\n",
+ " print self._Bag__contents[i],\n",
+ "class Bag:\n",
+ " __contents=[int]*MAX_ITEMS #int 1D array\n",
+ " __ItemCount=int\n",
+ " def __init__(self): #Constructor\n",
+ " self.ItemCount=0\n",
+ " def put(self,item): #member function defined inside the class\n",
+ " self._Bag__contents[self.ItemCount]=item\n",
+ " self.ItemCount+=1\n",
+ " show=show #member function defined outside the class\n",
+ "bag=Bag() #object of class Bag\n",
+ "while 1:\n",
+ " item=int(raw_input(\"\\nEnter Item Number to be put into the bag <0-no item>: \"))\n",
+ " if item==0:\n",
+ " break\n",
+ " bag.put(item)\n",
+ " print \"Items in bag:\",\n",
+ " bag.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Items in bag: 1"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3 2"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3 2 4"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-test1.cpp, Page-396"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self):\n",
+ " print \"Constructor of class test called\"\n",
+ "class Test:\n",
+ " __init__=__init__ #Constructor\n",
+ "G=Test()\n",
+ "def func():\n",
+ " L=Test()\n",
+ " print \"Here's function func()\"\n",
+ "X=Test()\n",
+ "print \"main() function\"\n",
+ "func()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class test called\n",
+ "Constructor of class test called\n",
+ "main() function\n",
+ "Constructor of class test called\n",
+ "Here's function func()\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- giftbag.cpp, Page- 398"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_ITEMS=25\n",
+ "def show(self):\n",
+ " if self.ItemCount:\n",
+ " for i in range(self.ItemCount):\n",
+ " print self._Bag__contents[i],\n",
+ " else:\n",
+ " print \"Nil\"\n",
+ "class Bag:\n",
+ " __contents=[int]*MAX_ITEMS\n",
+ " __ItemCount=int\n",
+ " def __init__(self, item=None): #parameterized constructor: Python does not support overloading of functions\n",
+ " if isinstance(item, int):\n",
+ " self._Bag__contents[0]=item\n",
+ " self.ItemCount=1\n",
+ " else:\n",
+ " self.ItemCount=0\n",
+ " def put(self,item):\n",
+ " self._Bag__contents[self.ItemCount]=item\n",
+ " self.ItemCount+=1\n",
+ " show=show\n",
+ "bag1=Bag()\n",
+ "bag2=Bag(4) #object created using the parameterized constructor\n",
+ "print \"Gifted bag1 initially has:\",\n",
+ "bag1.show()\n",
+ "print \"Gifted bag2 initially has:\",\n",
+ "bag2.show()\n",
+ "while 1:\n",
+ " item=int(raw_input(\"\\nEnter Item Number to be put into the bag <0-no item>: \"))\n",
+ " if item==0:\n",
+ " break\n",
+ " bag2.put(item)\n",
+ " print \"Items in bag2:\",\n",
+ " bag2.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gifted bag1 initially has: Nil\n",
+ "Gifted bag2 initially has: 4"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag2: 4 1"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag2: 4 1 2"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag2: 4 1 2 3"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-test.cpp, Page-400 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self):\n",
+ " print \"Constructor of class Test called\"\n",
+ "def __del__(self):\n",
+ " print \"Destructor of class Test called\"\n",
+ "class Test:\n",
+ " __init__=__init__ #Constructor\n",
+ " __del__=__del__ #Destructor\n",
+ "x=Test()\n",
+ "print \"Terminating main\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class Test called\n",
+ "Destructor of class Test called\n",
+ "Terminating main\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-count.cpp, Page-401"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "nobjects=0\n",
+ "nobj_alive=0\n",
+ "class MyClass:\n",
+ " def __init__(self):\n",
+ " global nobjects #using the global nobjects\n",
+ " global nobj_alive #using the global nobj_alive\n",
+ " nobjects+=1\n",
+ " nobj_alive+=1\n",
+ " def __del__(self):\n",
+ " global nobj_alive #using the global nobjects\n",
+ " nobj_alive-=1\n",
+ " def show(self):\n",
+ " global nobjects\n",
+ " global nobj_alive\n",
+ " print \"Total number of objects created: \", nobjects\n",
+ " print \"Number of objects currently alive: \", nobj_alive\n",
+ "obj1=MyClass()\n",
+ "obj1.show()\n",
+ "def func():\n",
+ " obj1=MyClass()\n",
+ " obj2=MyClass()\n",
+ " obj2.show()\n",
+ " del obj1\n",
+ " del obj2\n",
+ "func()\n",
+ "obj1.show()\n",
+ "obj2=MyClass()\n",
+ "obj3=MyClass()\n",
+ "obj2.show()\n",
+ "del obj1\n",
+ "del obj2\n",
+ "del obj3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total number of objects created: 1\n",
+ "Number of objects currently alive: 1\n",
+ "Total number of objects created: 3\n",
+ "Number of objects currently alive: 3\n",
+ "Total number of objects created: 3\n",
+ "Number of objects currently alive: 1\n",
+ "Total number of objects created: 5\n",
+ "Number of objects currently alive: 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example-account.cpp, Page- 403"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def MoneyTransfer(self, acc , amount):\n",
+ " self._AccClass__balance=self._AccClass__balance-amount\n",
+ " acc._AccClass__balance=acc._AccClass__balance + amount\n",
+ "class AccClass:\n",
+ " __accno=int\n",
+ " __balance=float\n",
+ " def __init__(self, an=None, bal=0.0):\n",
+ " if isinstance(an, int):\n",
+ " self.accno=an\n",
+ " self.__balance=bal\n",
+ " else:\n",
+ " self.accno=raw_input(\"Enter account number for acc1 object: \")\n",
+ " self.__balance=float(raw_input(\"Enter the balance: \"))\n",
+ " def display(self):\n",
+ " print \"Acoount number is: \", self.accno\n",
+ " print \"Balance is: \", self.__balance\n",
+ " MoneyTransfer=MoneyTransfer\n",
+ "acc1=AccClass()\n",
+ "acc2=AccClass(10)\n",
+ "acc3=AccClass(20, 750.5)\n",
+ "print \"Acoount information...\"\n",
+ "acc1.display()\n",
+ "acc2.display()\n",
+ "acc3.display()\n",
+ "trans_money=float(raw_input(\"How much money is to be transferred from acc3 to acc1: \"))\n",
+ "acc3.MoneyTransfer(acc1, trans_money)\n",
+ "print \"Updated information about accounts...\"\n",
+ "acc1.display()\n",
+ "acc2.display()\n",
+ "acc3.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter account number for acc1 object: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the balance: 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Acoount information...\n",
+ "Acoount number is: 1\n",
+ "Balance is: 100.0\n",
+ "Acoount number is: 10\n",
+ "Balance is: 0.0\n",
+ "Acoount number is: 20\n",
+ "Balance is: 750.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How much money is to be transferred from acc3 to acc1: 200\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Updated information about accounts...\n",
+ "Acoount number is: 1\n",
+ "Balance is: 300.0\n",
+ "Acoount number is: 10\n",
+ "Balance is: 0.0\n",
+ "Acoount number is: 20\n",
+ "Balance is: 550.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-test2.cpp. Page- 405"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self, NameIn=None):\n",
+ " if isinstance(NameIn, str):\n",
+ " self.name=NameIn\n",
+ " print \"Test Object \", NameIn, \" created\"\n",
+ " else:\n",
+ " self.name=\"unnamed\"\n",
+ " print \"Test object 'unnamed' created\"\n",
+ "def __del__(self):\n",
+ " print \"Test Object \", self.name, \" destroyed\"\n",
+ " del self.name\n",
+ "class Test:\n",
+ " __name=[str]\n",
+ " __init__=__init__\n",
+ " __del__=__del__\n",
+ "g=Test(\"global\")\n",
+ "def func():\n",
+ " l=Test(\"func\")\n",
+ " print \"here's function func()\"\n",
+ "x=Test(\"main\")\n",
+ "func()\n",
+ "print \"main() function - termination\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Test Object global created\n",
+ "Test Object global destroyed\n",
+ "Test Object main created\n",
+ "Test Object main destroyed\n",
+ "Test Object func created\n",
+ "here's function func()\n",
+ "Test Object func destroyed\n",
+ "main() function - termination\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex1.cpp, Page- 407"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "def add (self, c2):\n",
+ " temp=Complex()\n",
+ " temp._Complex__real=self._Complex__real+c2._Complex__real\n",
+ " temp._Complex__imag=self._Complex__imag+c2._Complex__imag\n",
+ " return temp\n",
+ "class Complex:\n",
+ " __real=float\n",
+ " __imag=float\n",
+ " def __init__(self, real_in=None, imag_in=0.0):\n",
+ " if isinstance(real_in, float):\n",
+ " self.__real=real_in\n",
+ " self.__imag=imag_in\n",
+ " else:\n",
+ " self.__real=self.__imag=0.0\n",
+ " def show(self, msg):\n",
+ " print msg, \n",
+ " print self.__real,\n",
+ " if self.__imag<0:\n",
+ " print \"-i\",\n",
+ " else:\n",
+ " print \"+i\",\n",
+ " print math.fabs(self.__imag) #print absolute value\n",
+ " add=add\n",
+ "c1=Complex(1.5,2.0)\n",
+ "c2=Complex(2.2)\n",
+ "c3=Complex()\n",
+ "c1.show(\"c1=\")\n",
+ "c2.show(\"c2=\")\n",
+ "c3=c1.add(c2)\n",
+ "c3.show(\"c3=c1.add(c2):\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1= 1.5 +i 2.0\n",
+ "c2= 2.2 +i 0.0\n",
+ "c3=c1.add(c2): 3.7 +i 2.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- noname.cpp, Page- 410"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class nameless:\n",
+ " __a=int\n",
+ " def __init__(self):\n",
+ " print \"Constructor\"\n",
+ " def __del__(self):\n",
+ " print \"Destructor\"\n",
+ "nameless() #nameless object created\n",
+ "n1=nameless()\n",
+ "n2=nameless()\n",
+ "print \"Program terminates\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor\n",
+ "Destructor\n",
+ "Constructor\n",
+ "Destructor\n",
+ "Constructor\n",
+ "Destructor\n",
+ "Program terminates\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-name.cpp, Page-411"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def show(self, msg):\n",
+ " print msg\n",
+ " print \"First Name: \", self._name__first\n",
+ " if self._name__middle[0]:\n",
+ " print \"Middle Name: \", self._name__middle\n",
+ " if self._name__last[0]:\n",
+ " print \"Last Name: \", self._name__last\n",
+ "class name:\n",
+ " __first=[None]*15\n",
+ " __middle=[None]*15\n",
+ " __last=[None]*15\n",
+ " def __init__(self, FirstName=None, MiddleName=None, LastName=None):\n",
+ " if isinstance(LastName, str):\n",
+ " self.__last=LastName\n",
+ " self.__middle=MiddleName\n",
+ " self.__first=FirstName\n",
+ " elif isinstance(MiddleName, str):\n",
+ " self.__middle=MiddleName\n",
+ " self.__first=FirstName\n",
+ " elif isinstance(FirstName, str):\n",
+ " self.__first=FirstName\n",
+ " else:\n",
+ " self.__last='\\0' #initialized to NULL\n",
+ " self.__middle='\\0'\n",
+ " self.__first='\\0'\n",
+ " show=show\n",
+ "n1=name()\n",
+ "n2=name()\n",
+ "n3=name()\n",
+ "n1=name(\"Rajkumar\")\n",
+ "n2=name(\"Savithri\", \"S\")\n",
+ "n3=name(\"Veugopal\", \"K\", \"R\")\n",
+ "n1.show(\"First prson details...\")\n",
+ "n2.show(\"Second prson details...\")\n",
+ "n3.show(\"Third prson details...\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First prson details...\n",
+ "First Name: Rajkumar\n",
+ "Second prson details...\n",
+ "First Name: Savithri\n",
+ "Middle Name: S\n",
+ "Third prson details...\n",
+ "First Name: Veugopal\n",
+ "Middle Name: K\n",
+ "Last Name: R\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vector1.cpp, Page-413"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def read(self):\n",
+ " for i in range(self._vector__sz):\n",
+ " print \"Enter vector [\", i, \"]? \",\n",
+ " self._vector__v[i]=int(raw_input())\n",
+ "def show_sum(self):\n",
+ " Sum=0\n",
+ " for i in range(self._vector__sz):\n",
+ " Sum+=self._vector__v[i]\n",
+ " print \"Vector sum= \", Sum\n",
+ "class vector:\n",
+ " __v=[int] #array of type integer\n",
+ " __sz=int\n",
+ " def __init__(self, size):\n",
+ " self.__sz= size\n",
+ " self.__v=[int]*size #dynamically allocating size to integer array\n",
+ " def __del__(self):\n",
+ " del self.__v\n",
+ " read=read\n",
+ " show_sum=show_sum\n",
+ "count = int\n",
+ "count=int(raw_input(\"How many elements are there in the vector: \"))\n",
+ "v1= vector(count)\n",
+ "v1.read()\n",
+ "v1.show_sum()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many elements are there in the vector: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter vector [ 0 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 1 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 2 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 3 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 4 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Vector sum= 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vector2.cpp, Page-415"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def show(self):\n",
+ " for i in range(self._vector__size):\n",
+ " print self.elem(i), \", \",\n",
+ "class vector:\n",
+ " __v=[int]\n",
+ " __size=int\n",
+ " def __init__(self, vector_size):\n",
+ " if isinstance(vector_size, int):\n",
+ " self.__size= vector_size\n",
+ " self.__v=[int]*vector_size\n",
+ " else:\n",
+ " print \"Copy construcor invoked\"\n",
+ " self.__size=vector_size.__size\n",
+ " self.__v=[int]*vector_size.__size\n",
+ " for i in range(vector_size.__size):\n",
+ " self.__v[i]=vector_size.__v[i]\n",
+ " def elem(self,i):\n",
+ " if i>=self.__size:\n",
+ " print \"Error: Out of Range\"\n",
+ " return -1\n",
+ " return self.__v[i]\n",
+ " def __del__(self):\n",
+ " del self.__v\n",
+ " show=show\n",
+ "v1=vector(5)\n",
+ "v2=vector(5)\n",
+ "for i in range(5):\n",
+ " if v2.elem(i)!=-1:\n",
+ " v2._vector__v[i]=i+1\n",
+ "v1=v2\n",
+ "v3=vector(v2)\n",
+ "print \"Vector v1: \",\n",
+ "v1.show()\n",
+ "print \"\\nvector v2: \",\n",
+ "v2.show()\n",
+ "print \"\\nvector v3: \",\n",
+ "v3.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Copy construcor invoked\n",
+ "Vector v1: 1 , 2 , 3 , 4 , 5 , \n",
+ "vector v2: 1 , 2 , 3 , 4 , 5 , \n",
+ "vector v3: 1 , 2 , 3 , 4 , 5 , \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-matrix.cpp, Page-418"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "TRUE=1\n",
+ "FALSE=0\n",
+ "def __del__(self):\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " del self._matrix__p[i]\n",
+ " del self._matrix__p\n",
+ "def add(self, a, b):\n",
+ " self._matrix__MaxRow=a._matrix__MaxRow\n",
+ " self._matrix__MaxCol=a._matrix__MaxCol\n",
+ " if (a._matrix__MaxRow!=b._matrix__MaxRow)|(a._matrix__MaxCol!=b._matrix__MaxCol):\n",
+ " print \"Error: invalid matrix order for addition\"\n",
+ " return\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " self._matrix__p[i][j]=a._matrix__p[i][j]+b._matrix__p[i][j]\n",
+ "def sub(self, a, b):\n",
+ " self._matrix__MaxRow=a._matrix__MaxRow\n",
+ " self._matrix__MaxCol=a._matrix__MaxCol\n",
+ " if (a._matrix__MaxRow!=b._matrix__MaxRow)|(a._matrix__MaxCol!=b._matrix__MaxCol):\n",
+ " print \"Error: invalid matrix order for subtraction\"\n",
+ " return\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " self._matrix__p[i][j]=a._matrix__p[i][j]-b._matrix__p[i][j]\n",
+ "def mul(self, a, b):\n",
+ " self._matrix__MaxRow=a._matrix__MaxRow\n",
+ " self._matrix__MaxCol=a._matrix__MaxCol\n",
+ " if (a._matrix__MaxCol!=b._matrix__MaxRow):\n",
+ " print \"Error: invalid matrix order for multiplication\"\n",
+ " return\n",
+ " for i in range(a._matrix__MaxRow):\n",
+ " for j in range(b._matrix__MaxCol):\n",
+ " self._matrix__p[i][j]=0\n",
+ " for k in range(a._matrix__MaxCol):\n",
+ " self._matrix__p[i][j]+=a._matrix__p[i][j]*b._matrix__p[i][j]\n",
+ "def eql(self, b):\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " if self._matrix__p[i][i]!=b._matrix__p[i][j]:\n",
+ " return 0\n",
+ " return 1\n",
+ "def read(self):\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " print \"Matrix[\", i, \",\",j,\"] =? \",\n",
+ " self._matrix__p[i][j]=int(raw_input())\n",
+ "def show(self):\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " print self._matrix__p[i][j], \" \",\n",
+ " print \"\"\n",
+ "class matrix:\n",
+ " __MaxRow=int\n",
+ " __MaxCol=int\n",
+ " __p=[int]\n",
+ " def __init__(self, row=0, col=0):\n",
+ " self.__MaxRow=row\n",
+ " self.__MaxCol=col\n",
+ " if row>0:\n",
+ " self.__p=[[int]*self.__MaxCol]*self.__MaxRow\n",
+ " __del__=__del__\n",
+ " read=read\n",
+ " show=show\n",
+ " add=add\n",
+ " sub=sub\n",
+ " mul=mul\n",
+ " eql=eql\n",
+ "print \"Enter Matrix A details...\"\n",
+ "m=int(raw_input(\"How many rows? \"))\n",
+ "n=int(raw_input(\"How many columns? \"))\n",
+ "a=matrix(m,n)\n",
+ "a.read()\n",
+ "print \"Enter Matrix B details...\"\n",
+ "p=int(raw_input(\"How many rows? \"))\n",
+ "q=int(raw_input(\"How many columns? \"))\n",
+ "b=matrix(p,q)\n",
+ "b.read()\n",
+ "print \"Matrix A is...\"\n",
+ "a.show()\n",
+ "print \"Matrix B is...\"\n",
+ "b.show()\n",
+ "c=matrix(m,n)\n",
+ "c.add(a,b)\n",
+ "print \"C=A+B...\"\n",
+ "c.show()\n",
+ "d=matrix(m,n)\n",
+ "d.sub(a,b)\n",
+ "print \"D=A-B...\"\n",
+ "d.show()\n",
+ "e=matrix(m,q)\n",
+ "e.mul(a,b)\n",
+ "print \"E=A*B...\"\n",
+ "e.show()\n",
+ "print \"(Is matrix A equal to matrix B)? \",\n",
+ "if(a.eql(b)):\n",
+ " print \"Yes\"\n",
+ "else:\n",
+ " print \"No\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Matrix A details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many rows? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many columns? 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrix[ 0 , 0 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 0 , 1 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 0 , 2 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 0 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 1 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 2 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 0 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 1 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 2 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Matrix B details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many rows? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many columns? 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrix[ 0 , 0 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 0 , 1 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 0 , 2 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 0 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 1 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 2 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 0 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 1 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 2 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix A is...\n",
+ "2 2 2 \n",
+ "2 2 2 \n",
+ "2 2 2 \n",
+ "Matrix B is...\n",
+ "1 1 1 \n",
+ "1 1 1 \n",
+ "1 1 1 \n",
+ "C=A+B...\n",
+ "3 3 3 \n",
+ "3 3 3 \n",
+ "3 3 3 \n",
+ "D=A-B...\n",
+ "1 1 1 \n",
+ "1 1 1 \n",
+ "1 1 1 \n",
+ "E=A*B...\n",
+ "6 6 6 \n",
+ "6 6 6 \n",
+ "6 6 6 \n",
+ "(Is matrix A equal to matrix B)? No\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-person.cpp, Page-423"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self, NameIn, AddressIn, PhoneIn):\n",
+ " self._Person__name=NameIn\n",
+ " self._Person__address=AddressIn\n",
+ " self._Person__phone=PhoneIn\n",
+ "#inline\n",
+ "def __del__(self):\n",
+ " del self._Person__name\n",
+ " del self._Person__address\n",
+ " del self._Person__phone\n",
+ "def getname(self):\n",
+ " return self._Person__name\n",
+ "def getaddress(self):\n",
+ " return self._Person__address\n",
+ "def getphone(self):\n",
+ " return self._Person__phone\n",
+ "def changename(self, NameIn):\n",
+ " if(self._Person__name):\n",
+ " del self._Person__name\n",
+ " self._Person__name=NameIn\n",
+ "class Person:\n",
+ " __name=[str]\n",
+ " __address=[str]\n",
+ " __phone=[str]\n",
+ " __init__=__init__\n",
+ " __del__=__del__\n",
+ " getname=getname\n",
+ " getaddress=getaddress\n",
+ " getphone=getphone\n",
+ " changename=changename\n",
+ "def printperson(p):\n",
+ " if(p.getname()):\n",
+ " print \"Name: \", p.getname()\n",
+ " if(p.getaddress()):\n",
+ " print \"Address: \", p.getaddress()\n",
+ " if(p.getphone()):\n",
+ " print \"Phone: \", p.getphone()\n",
+ "me=Person(\"Rajkumar\", \"E-mail: raj@cdabc.erne.in\", \"91-080-5584271\")\n",
+ "printperson(me)\n",
+ "you=Person(\"XYZ\", \"-not sure-\", \"-not sure-\")\n",
+ "print \"You XYZ by default...\"\n",
+ "printperson(you)\n",
+ "you.changename(\"ABC\")\n",
+ "print \"You changed XYZ to ABC...\"\n",
+ "printperson(you)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Rajkumar\n",
+ "Address: E-mail: raj@cdabc.erne.in\n",
+ "Phone: 91-080-5584271\n",
+ "You XYZ by default...\n",
+ "Name: XYZ\n",
+ "Address: -not sure-\n",
+ "Phone: -not sure-\n",
+ "You changed XYZ to ABC...\n",
+ "Name: ABC\n",
+ "Address: -not sure-\n",
+ "Phone: -not sure-\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-graph.cpp, Page-425"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self):\n",
+ " if(self._Graphics__nobjects[0]==False):\n",
+ " self._Graphics__setgraphicsmode()\n",
+ " self._Graphics__nobjects[0]+=1\n",
+ "def __del__(self):\n",
+ " self._Graphics__nobjects[0]-=1\n",
+ " if(self._Graphics__nobjects[0]==False):\n",
+ " self._Graphics__settextmode()\n",
+ "class Graphics:\n",
+ " __nobjects=[0]\n",
+ " def __setgraphicsmode(self):\n",
+ " pass\n",
+ " def __settextmode(self):\n",
+ " pass\n",
+ " __init__=__init__\n",
+ " __del__=__del__\n",
+ " def getcount(self):\n",
+ " return self.__nobjects[0]\n",
+ "def my_func():\n",
+ " obj=Graphics()\n",
+ " print \"No. of Graphics' objects while in my_func=\", obj.getcount()\n",
+ "obj1=Graphics()\n",
+ "print \"No. of Graphics' objects before in my_func=\", obj1.getcount()\n",
+ "my_func()\n",
+ "print \"No. of Graphics' objects after in my_func=\", obj1.getcount()\n",
+ "obj2=Graphics()\n",
+ "obj3=Graphics()\n",
+ "obj4=Graphics()\n",
+ "print \"Value of static member nobjects after all 3 more objects...\"\n",
+ "print \"In obj1= \", obj1.getcount()\n",
+ "print \"In obj2= \", obj2.getcount()\n",
+ "print \"In obj3= \", obj3.getcount()\n",
+ "print \"In obj4= \", obj4.getcount()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No. of Graphics' objects before in my_func= 1\n",
+ "No. of Graphics' objects while in my_func= 2\n",
+ "No. of Graphics' objects after in my_func= 1\n",
+ "Value of static member nobjects after all 3 more objects...\n",
+ "In obj1= 4\n",
+ "In obj2= 4\n",
+ "In obj3= 4\n",
+ "In obj4= 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example Page-428"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def distance(self, a, b):\n",
+ " self.x=a.x-b.x\n",
+ " self.y=a.y-b.y\n",
+ "def display(self):\n",
+ " print \"x= \",self.x\n",
+ " print \"y= \", self.y\n",
+ "class point:\n",
+ " __x=int\n",
+ " __y=int\n",
+ " def __init__(self, a=None, b=None):\n",
+ " if isinstance(a, int):\n",
+ " self.x=a\n",
+ " self.y=b\n",
+ " else:\n",
+ " self.x=self.y=0\n",
+ " def __del__(self):\n",
+ " pass\n",
+ " distance=distance\n",
+ " display=display\n",
+ "p1=point(40,18)\n",
+ "p2=point(12,9)\n",
+ "p3=point()\n",
+ "p3.distance(p1,p2)\n",
+ "print \"Coordinates of P1: \"\n",
+ "p1.display()\n",
+ "print \"Coordinates of P2: \"\n",
+ "p2.display()\n",
+ "print \"distance between P1 and P2: \"\n",
+ "p3.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Coordinates of P1: \n",
+ "x= 40\n",
+ "y= 18\n",
+ "Coordinates of P2: \n",
+ "x= 12\n",
+ "y= 9\n",
+ "distance between P1 and P2: \n",
+ "x= 28\n",
+ "y= 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example Page-430"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def display(self):\n",
+ " print \"a =\", self.a,\n",
+ " print \"b =\", self.b\n",
+ "class data:\n",
+ " __a=int\n",
+ " __b=float\n",
+ " def __init__(self, x=None, y=None):\n",
+ " if isinstance(x, int):\n",
+ " self.a=x\n",
+ " self.b=y\n",
+ " elif isinstance(x, data):\n",
+ " self.a=x.a\n",
+ " self.b=x.b\n",
+ " else:\n",
+ " self.a=0\n",
+ " self.b=0\n",
+ " display=display\n",
+ "d1=data()\n",
+ "d2=data(12,9.9)\n",
+ "d3=data(d2)\n",
+ "print \"For default constructor: \"\n",
+ "d1.display()\n",
+ "print\"For parameterized constructor: \"\n",
+ "d2.display()\n",
+ "print \"For Copy Constructor: \"\n",
+ "d3.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For default constructor: \n",
+ "a = 0 b = 0\n",
+ "For parameterized constructor: \n",
+ "a = 12 b = 9.9\n",
+ "For Copy Constructor: \n",
+ "a = 12 b = 9.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/SrutiGoyal/Chapter_11-_Object_Initialization_and_Clean-Up_1.ipynb b/sample_notebooks/SrutiGoyal/Chapter_11-_Object_Initialization_and_Clean-Up_1.ipynb
new file mode 100755
index 00000000..d3bdda01
--- /dev/null
+++ b/sample_notebooks/SrutiGoyal/Chapter_11-_Object_Initialization_and_Clean-Up_1.ipynb
@@ -0,0 +1,1779 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:64b755d597a2016634dadbbc81a598a60446119cc89f4f94fd9140b5bc077b77"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Object Initialization and clean up"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- bag.cpp, Page-392"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_ITEMS=25\n",
+ "def show(self):\n",
+ " for i in range(self.ItemCount):\n",
+ " print self._Bag__contents[i],\n",
+ "class Bag:\n",
+ " __contents=[int]*MAX_ITEMS\n",
+ " __ItemCount=int\n",
+ " def SetEmpty(self):\n",
+ " self.ItemCount=0\n",
+ " def put(self,item):\n",
+ " self._Bag__contents[self.ItemCount]=item\n",
+ " self.ItemCount+=1\n",
+ " show=show\n",
+ "bag=Bag() #object of class Bag\n",
+ "bag.SetEmpty() #initialize the object\n",
+ "while 1:\n",
+ " item=int(raw_input(\"\\nEnter Item Number to be put into the bag <0-no item>: \"))\n",
+ " if item==0:\n",
+ " break\n",
+ " bag.put(item)\n",
+ " print \"Items in bag:\",\n",
+ " bag.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Items in bag: 1"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3 2"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3 2 4"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- newbag.cpp, Page-395"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_ITEMS=25 #size of array contents\n",
+ "def show(self):\n",
+ " for i in range(self.ItemCount):\n",
+ " print self._Bag__contents[i],\n",
+ "class Bag:\n",
+ " __contents=[int]*MAX_ITEMS #int 1D array\n",
+ " __ItemCount=int\n",
+ " def __init__(self): #Constructor\n",
+ " self.ItemCount=0\n",
+ " def put(self,item): #member function defined inside the class\n",
+ " self._Bag__contents[self.ItemCount]=item\n",
+ " self.ItemCount+=1\n",
+ " show=show #member function defined outside the class\n",
+ "bag=Bag() #object of class Bag\n",
+ "while 1:\n",
+ " item=int(raw_input(\"\\nEnter Item Number to be put into the bag <0-no item>: \"))\n",
+ " if item==0:\n",
+ " break\n",
+ " bag.put(item)\n",
+ " print \"Items in bag:\",\n",
+ " bag.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Items in bag: 1"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3 2"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3 2 4"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-test1.cpp, Page-396"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self):\n",
+ " print \"Constructor of class test called\"\n",
+ "class Test:\n",
+ " __init__=__init__ #Constructor\n",
+ "G=Test()\n",
+ "def func():\n",
+ " L=Test()\n",
+ " print \"Here's function func()\"\n",
+ "X=Test()\n",
+ "print \"main() function\"\n",
+ "func()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class test called\n",
+ "Constructor of class test called\n",
+ "main() function\n",
+ "Constructor of class test called\n",
+ "Here's function func()\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- giftbag.cpp, Page- 398"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_ITEMS=25\n",
+ "def show(self):\n",
+ " if self.ItemCount:\n",
+ " for i in range(self.ItemCount):\n",
+ " print self._Bag__contents[i],\n",
+ " else:\n",
+ " print \"Nil\"\n",
+ "class Bag:\n",
+ " __contents=[int]*MAX_ITEMS\n",
+ " __ItemCount=int\n",
+ " def __init__(self, item=None): #parameterized constructor: Python does not support overloading of functions\n",
+ " if isinstance(item, int):\n",
+ " self._Bag__contents[0]=item\n",
+ " self.ItemCount=1\n",
+ " else:\n",
+ " self.ItemCount=0\n",
+ " def put(self,item):\n",
+ " self._Bag__contents[self.ItemCount]=item\n",
+ " self.ItemCount+=1\n",
+ " show=show\n",
+ "bag1=Bag()\n",
+ "bag2=Bag(4) #object created using the parameterized constructor\n",
+ "print \"Gifted bag1 initially has:\",\n",
+ "bag1.show()\n",
+ "print \"Gifted bag2 initially has:\",\n",
+ "bag2.show()\n",
+ "while 1:\n",
+ " item=int(raw_input(\"\\nEnter Item Number to be put into the bag <0-no item>: \"))\n",
+ " if item==0:\n",
+ " break\n",
+ " bag2.put(item)\n",
+ " print \"Items in bag2:\",\n",
+ " bag2.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gifted bag1 initially has: Nil\n",
+ "Gifted bag2 initially has: 4"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag2: 4 1"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag2: 4 1 2"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag2: 4 1 2 3"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-test.cpp, Page-400 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self):\n",
+ " print \"Constructor of class Test called\"\n",
+ "def __del__(self):\n",
+ " print \"Destructor of class Test called\"\n",
+ "class Test:\n",
+ " __init__=__init__ #Constructor\n",
+ " __del__=__del__ #Destructor\n",
+ "x=Test()\n",
+ "print \"Terminating main\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class Test called\n",
+ "Destructor of class Test called\n",
+ "Terminating main\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-count.cpp, Page-401"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "nobjects=0\n",
+ "nobj_alive=0\n",
+ "class MyClass:\n",
+ " def __init__(self):\n",
+ " global nobjects #using the global nobjects\n",
+ " global nobj_alive #using the global nobj_alive\n",
+ " nobjects+=1\n",
+ " nobj_alive+=1\n",
+ " def __del__(self):\n",
+ " global nobj_alive #using the global nobjects\n",
+ " nobj_alive-=1\n",
+ " def show(self):\n",
+ " global nobjects\n",
+ " global nobj_alive\n",
+ " print \"Total number of objects created: \", nobjects\n",
+ " print \"Number of objects currently alive: \", nobj_alive\n",
+ "obj1=MyClass()\n",
+ "obj1.show()\n",
+ "def func():\n",
+ " obj1=MyClass()\n",
+ " obj2=MyClass()\n",
+ " obj2.show()\n",
+ " del obj1\n",
+ " del obj2\n",
+ "func()\n",
+ "obj1.show()\n",
+ "obj2=MyClass()\n",
+ "obj3=MyClass()\n",
+ "obj2.show()\n",
+ "del obj1\n",
+ "del obj2\n",
+ "del obj3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total number of objects created: 1\n",
+ "Number of objects currently alive: 1\n",
+ "Total number of objects created: 3\n",
+ "Number of objects currently alive: 3\n",
+ "Total number of objects created: 3\n",
+ "Number of objects currently alive: 1\n",
+ "Total number of objects created: 5\n",
+ "Number of objects currently alive: 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example-account.cpp, Page- 403"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def MoneyTransfer(self, acc , amount):\n",
+ " self._AccClass__balance=self._AccClass__balance-amount\n",
+ " acc._AccClass__balance=acc._AccClass__balance + amount\n",
+ "class AccClass:\n",
+ " __accno=int\n",
+ " __balance=float\n",
+ " def __init__(self, an=None, bal=0.0):\n",
+ " if isinstance(an, int):\n",
+ " self.accno=an\n",
+ " self.__balance=bal\n",
+ " else:\n",
+ " self.accno=raw_input(\"Enter account number for acc1 object: \")\n",
+ " self.__balance=float(raw_input(\"Enter the balance: \"))\n",
+ " def display(self):\n",
+ " print \"Acoount number is: \", self.accno\n",
+ " print \"Balance is: \", self.__balance\n",
+ " MoneyTransfer=MoneyTransfer\n",
+ "acc1=AccClass()\n",
+ "acc2=AccClass(10)\n",
+ "acc3=AccClass(20, 750.5)\n",
+ "print \"Acoount information...\"\n",
+ "acc1.display()\n",
+ "acc2.display()\n",
+ "acc3.display()\n",
+ "trans_money=float(raw_input(\"How much money is to be transferred from acc3 to acc1: \"))\n",
+ "acc3.MoneyTransfer(acc1, trans_money)\n",
+ "print \"Updated information about accounts...\"\n",
+ "acc1.display()\n",
+ "acc2.display()\n",
+ "acc3.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter account number for acc1 object: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the balance: 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Acoount information...\n",
+ "Acoount number is: 1\n",
+ "Balance is: 100.0\n",
+ "Acoount number is: 10\n",
+ "Balance is: 0.0\n",
+ "Acoount number is: 20\n",
+ "Balance is: 750.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How much money is to be transferred from acc3 to acc1: 200\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Updated information about accounts...\n",
+ "Acoount number is: 1\n",
+ "Balance is: 300.0\n",
+ "Acoount number is: 10\n",
+ "Balance is: 0.0\n",
+ "Acoount number is: 20\n",
+ "Balance is: 550.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-test2.cpp. Page- 405"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self, NameIn=None):\n",
+ " if isinstance(NameIn, str):\n",
+ " self.name=NameIn\n",
+ " print \"Test Object \", NameIn, \" created\"\n",
+ " else:\n",
+ " self.name=\"unnamed\"\n",
+ " print \"Test object 'unnamed' created\"\n",
+ "def __del__(self):\n",
+ " print \"Test Object \", self.name, \" destroyed\"\n",
+ " del self.name\n",
+ "class Test:\n",
+ " __name=[str]\n",
+ " __init__=__init__\n",
+ " __del__=__del__\n",
+ "g=Test(\"global\")\n",
+ "def func():\n",
+ " l=Test(\"func\")\n",
+ " print \"here's function func()\"\n",
+ "x=Test(\"main\")\n",
+ "func()\n",
+ "print \"main() function - termination\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Test Object global created\n",
+ "Test Object global destroyed\n",
+ "Test Object main created\n",
+ "Test Object main destroyed\n",
+ "Test Object func created\n",
+ "here's function func()\n",
+ "Test Object func destroyed\n",
+ "main() function - termination\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex1.cpp, Page- 407"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "def add (self, c2):\n",
+ " temp=Complex()\n",
+ " temp._Complex__real=self._Complex__real+c2._Complex__real\n",
+ " temp._Complex__imag=self._Complex__imag+c2._Complex__imag\n",
+ " return temp\n",
+ "class Complex:\n",
+ " __real=float\n",
+ " __imag=float\n",
+ " def __init__(self, real_in=None, imag_in=0.0):\n",
+ " if isinstance(real_in, float):\n",
+ " self.__real=real_in\n",
+ " self.__imag=imag_in\n",
+ " else:\n",
+ " self.__real=self.__imag=0.0\n",
+ " def show(self, msg):\n",
+ " print msg, \n",
+ " print self.__real,\n",
+ " if self.__imag<0:\n",
+ " print \"-i\",\n",
+ " else:\n",
+ " print \"+i\",\n",
+ " print math.fabs(self.__imag) #print absolute value\n",
+ " add=add\n",
+ "c1=Complex(1.5,2.0)\n",
+ "c2=Complex(2.2)\n",
+ "c3=Complex()\n",
+ "c1.show(\"c1=\")\n",
+ "c2.show(\"c2=\")\n",
+ "c3=c1.add(c2)\n",
+ "c3.show(\"c3=c1.add(c2):\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1= 1.5 +i 2.0\n",
+ "c2= 2.2 +i 0.0\n",
+ "c3=c1.add(c2): 3.7 +i 2.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- noname.cpp, Page- 410"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class nameless:\n",
+ " __a=int\n",
+ " def __init__(self):\n",
+ " print \"Constructor\"\n",
+ " def __del__(self):\n",
+ " print \"Destructor\"\n",
+ "nameless() #nameless object created\n",
+ "n1=nameless()\n",
+ "n2=nameless()\n",
+ "print \"Program terminates\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor\n",
+ "Destructor\n",
+ "Constructor\n",
+ "Destructor\n",
+ "Constructor\n",
+ "Destructor\n",
+ "Program terminates\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-name.cpp, Page-411"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def show(self, msg):\n",
+ " print msg\n",
+ " print \"First Name: \", self._name__first\n",
+ " if self._name__middle[0]:\n",
+ " print \"Middle Name: \", self._name__middle\n",
+ " if self._name__last[0]:\n",
+ " print \"Last Name: \", self._name__last\n",
+ "class name:\n",
+ " __first=[None]*15\n",
+ " __middle=[None]*15\n",
+ " __last=[None]*15\n",
+ " def __init__(self, FirstName=None, MiddleName=None, LastName=None):\n",
+ " if isinstance(LastName, str):\n",
+ " self.__last=LastName\n",
+ " self.__middle=MiddleName\n",
+ " self.__first=FirstName\n",
+ " elif isinstance(MiddleName, str):\n",
+ " self.__middle=MiddleName\n",
+ " self.__first=FirstName\n",
+ " elif isinstance(FirstName, str):\n",
+ " self.__first=FirstName\n",
+ " else:\n",
+ " self.__last='\\0' #initialized to NULL\n",
+ " self.__middle='\\0'\n",
+ " self.__first='\\0'\n",
+ " show=show\n",
+ "n1=name()\n",
+ "n2=name()\n",
+ "n3=name()\n",
+ "n1=name(\"Rajkumar\")\n",
+ "n2=name(\"Savithri\", \"S\")\n",
+ "n3=name(\"Veugopal\", \"K\", \"R\")\n",
+ "n1.show(\"First prson details...\")\n",
+ "n2.show(\"Second prson details...\")\n",
+ "n3.show(\"Third prson details...\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First prson details...\n",
+ "First Name: Rajkumar\n",
+ "Second prson details...\n",
+ "First Name: Savithri\n",
+ "Middle Name: S\n",
+ "Third prson details...\n",
+ "First Name: Veugopal\n",
+ "Middle Name: K\n",
+ "Last Name: R\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vector1.cpp, Page-413"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def read(self):\n",
+ " for i in range(self._vector__sz):\n",
+ " print \"Enter vector [\", i, \"]? \",\n",
+ " self._vector__v[i]=int(raw_input())\n",
+ "def show_sum(self):\n",
+ " Sum=0\n",
+ " for i in range(self._vector__sz):\n",
+ " Sum+=self._vector__v[i]\n",
+ " print \"Vector sum= \", Sum\n",
+ "class vector:\n",
+ " __v=[int] #array of type integer\n",
+ " __sz=int\n",
+ " def __init__(self, size):\n",
+ " self.__sz= size\n",
+ " self.__v=[int]*size #dynamically allocating size to integer array\n",
+ " def __del__(self):\n",
+ " del self.__v\n",
+ " read=read\n",
+ " show_sum=show_sum\n",
+ "count = int\n",
+ "count=int(raw_input(\"How many elements are there in the vector: \"))\n",
+ "v1= vector(count)\n",
+ "v1.read()\n",
+ "v1.show_sum()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many elements are there in the vector: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter vector [ 0 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 1 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 2 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 3 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 4 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Vector sum= 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vector2.cpp, Page-415"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def show(self):\n",
+ " for i in range(self._vector__size):\n",
+ " print self.elem(i), \", \",\n",
+ "class vector:\n",
+ " __v=[int]\n",
+ " __size=int\n",
+ " def __init__(self, vector_size):\n",
+ " if isinstance(vector_size, int):\n",
+ " self.__size= vector_size\n",
+ " self.__v=[int]*vector_size\n",
+ " else:\n",
+ " print \"Copy construcor invoked\"\n",
+ " self.__size=vector_size.__size\n",
+ " self.__v=[int]*vector_size.__size\n",
+ " for i in range(vector_size.__size):\n",
+ " self.__v[i]=vector_size.__v[i]\n",
+ " def elem(self,i):\n",
+ " if i>=self.__size:\n",
+ " print \"Error: Out of Range\"\n",
+ " return -1\n",
+ " return self.__v[i]\n",
+ " def __del__(self):\n",
+ " del self.__v\n",
+ " show=show\n",
+ "v1=vector(5)\n",
+ "v2=vector(5)\n",
+ "for i in range(5):\n",
+ " if v2.elem(i)!=-1:\n",
+ " v2._vector__v[i]=i+1\n",
+ "v1=v2\n",
+ "v3=vector(v2)\n",
+ "print \"Vector v1: \",\n",
+ "v1.show()\n",
+ "print \"\\nvector v2: \",\n",
+ "v2.show()\n",
+ "print \"\\nvector v3: \",\n",
+ "v3.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Copy construcor invoked\n",
+ "Vector v1: 1 , 2 , 3 , 4 , 5 , \n",
+ "vector v2: 1 , 2 , 3 , 4 , 5 , \n",
+ "vector v3: 1 , 2 , 3 , 4 , 5 , \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-matrix.cpp, Page-418"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "TRUE=1\n",
+ "FALSE=0\n",
+ "def __del__(self):\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " del self._matrix__p[i]\n",
+ " del self._matrix__p\n",
+ "def add(self, a, b):\n",
+ " self._matrix__MaxRow=a._matrix__MaxRow\n",
+ " self._matrix__MaxCol=a._matrix__MaxCol\n",
+ " if (a._matrix__MaxRow!=b._matrix__MaxRow)|(a._matrix__MaxCol!=b._matrix__MaxCol):\n",
+ " print \"Error: invalid matrix order for addition\"\n",
+ " return\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " self._matrix__p[i][j]=a._matrix__p[i][j]+b._matrix__p[i][j]\n",
+ "def sub(self, a, b):\n",
+ " self._matrix__MaxRow=a._matrix__MaxRow\n",
+ " self._matrix__MaxCol=a._matrix__MaxCol\n",
+ " if (a._matrix__MaxRow!=b._matrix__MaxRow)|(a._matrix__MaxCol!=b._matrix__MaxCol):\n",
+ " print \"Error: invalid matrix order for subtraction\"\n",
+ " return\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " self._matrix__p[i][j]=a._matrix__p[i][j]-b._matrix__p[i][j]\n",
+ "def mul(self, a, b):\n",
+ " self._matrix__MaxRow=a._matrix__MaxRow\n",
+ " self._matrix__MaxCol=a._matrix__MaxCol\n",
+ " if (a._matrix__MaxCol!=b._matrix__MaxRow):\n",
+ " print \"Error: invalid matrix order for multiplication\"\n",
+ " return\n",
+ " for i in range(a._matrix__MaxRow):\n",
+ " for j in range(b._matrix__MaxCol):\n",
+ " self._matrix__p[i][j]=0\n",
+ " for k in range(a._matrix__MaxCol):\n",
+ " self._matrix__p[i][j]+=a._matrix__p[i][j]*b._matrix__p[i][j]\n",
+ "def eql(self, b):\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " if self._matrix__p[i][i]!=b._matrix__p[i][j]:\n",
+ " return 0\n",
+ " return 1\n",
+ "def read(self):\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " print \"Matrix[\", i, \",\",j,\"] =? \",\n",
+ " self._matrix__p[i][j]=int(raw_input())\n",
+ "def show(self):\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " print self._matrix__p[i][j], \" \",\n",
+ " print \"\"\n",
+ "class matrix:\n",
+ " __MaxRow=int\n",
+ " __MaxCol=int\n",
+ " __p=[int]\n",
+ " def __init__(self, row=0, col=0):\n",
+ " self.__MaxRow=row\n",
+ " self.__MaxCol=col\n",
+ " if row>0:\n",
+ " self.__p=[[int]*self.__MaxCol]*self.__MaxRow\n",
+ " __del__=__del__\n",
+ " read=read\n",
+ " show=show\n",
+ " add=add\n",
+ " sub=sub\n",
+ " mul=mul\n",
+ " eql=eql\n",
+ "print \"Enter Matrix A details...\"\n",
+ "m=int(raw_input(\"How many rows? \"))\n",
+ "n=int(raw_input(\"How many columns? \"))\n",
+ "a=matrix(m,n)\n",
+ "a.read()\n",
+ "print \"Enter Matrix B details...\"\n",
+ "p=int(raw_input(\"How many rows? \"))\n",
+ "q=int(raw_input(\"How many columns? \"))\n",
+ "b=matrix(p,q)\n",
+ "b.read()\n",
+ "print \"Matrix A is...\"\n",
+ "a.show()\n",
+ "print \"Matrix B is...\"\n",
+ "b.show()\n",
+ "c=matrix(m,n)\n",
+ "c.add(a,b)\n",
+ "print \"C=A+B...\"\n",
+ "c.show()\n",
+ "d=matrix(m,n)\n",
+ "d.sub(a,b)\n",
+ "print \"D=A-B...\"\n",
+ "d.show()\n",
+ "e=matrix(m,q)\n",
+ "e.mul(a,b)\n",
+ "print \"E=A*B...\"\n",
+ "e.show()\n",
+ "print \"(Is matrix A equal to matrix B)? \",\n",
+ "if(a.eql(b)):\n",
+ " print \"Yes\"\n",
+ "else:\n",
+ " print \"No\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Matrix A details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many rows? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many columns? 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrix[ 0 , 0 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 0 , 1 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 0 , 2 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 0 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 1 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 2 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 0 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 1 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 2 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Matrix B details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many rows? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many columns? 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrix[ 0 , 0 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 0 , 1 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 0 , 2 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 0 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 1 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 2 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 0 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 1 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 2 ] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix A is...\n",
+ "2 2 2 \n",
+ "2 2 2 \n",
+ "2 2 2 \n",
+ "Matrix B is...\n",
+ "1 1 1 \n",
+ "1 1 1 \n",
+ "1 1 1 \n",
+ "C=A+B...\n",
+ "3 3 3 \n",
+ "3 3 3 \n",
+ "3 3 3 \n",
+ "D=A-B...\n",
+ "1 1 1 \n",
+ "1 1 1 \n",
+ "1 1 1 \n",
+ "E=A*B...\n",
+ "6 6 6 \n",
+ "6 6 6 \n",
+ "6 6 6 \n",
+ "(Is matrix A equal to matrix B)? No\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-person.cpp, Page-423"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self, NameIn, AddressIn, PhoneIn):\n",
+ " self._Person__name=NameIn\n",
+ " self._Person__address=AddressIn\n",
+ " self._Person__phone=PhoneIn\n",
+ "#inline\n",
+ "def __del__(self):\n",
+ " del self._Person__name\n",
+ " del self._Person__address\n",
+ " del self._Person__phone\n",
+ "def getname(self):\n",
+ " return self._Person__name\n",
+ "def getaddress(self):\n",
+ " return self._Person__address\n",
+ "def getphone(self):\n",
+ " return self._Person__phone\n",
+ "def changename(self, NameIn):\n",
+ " if(self._Person__name):\n",
+ " del self._Person__name\n",
+ " self._Person__name=NameIn\n",
+ "class Person:\n",
+ " __name=[str]\n",
+ " __address=[str]\n",
+ " __phone=[str]\n",
+ " __init__=__init__\n",
+ " __del__=__del__\n",
+ " getname=getname\n",
+ " getaddress=getaddress\n",
+ " getphone=getphone\n",
+ " changename=changename\n",
+ "def printperson(p):\n",
+ " if(p.getname()):\n",
+ " print \"Name: \", p.getname()\n",
+ " if(p.getaddress()):\n",
+ " print \"Address: \", p.getaddress()\n",
+ " if(p.getphone()):\n",
+ " print \"Phone: \", p.getphone()\n",
+ "me=Person(\"Rajkumar\", \"E-mail: raj@cdabc.erne.in\", \"91-080-5584271\")\n",
+ "printperson(me)\n",
+ "you=Person(\"XYZ\", \"-not sure-\", \"-not sure-\")\n",
+ "print \"You XYZ by default...\"\n",
+ "printperson(you)\n",
+ "you.changename(\"ABC\")\n",
+ "print \"You changed XYZ to ABC...\"\n",
+ "printperson(you)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Rajkumar\n",
+ "Address: E-mail: raj@cdabc.erne.in\n",
+ "Phone: 91-080-5584271\n",
+ "You XYZ by default...\n",
+ "Name: XYZ\n",
+ "Address: -not sure-\n",
+ "Phone: -not sure-\n",
+ "You changed XYZ to ABC...\n",
+ "Name: ABC\n",
+ "Address: -not sure-\n",
+ "Phone: -not sure-\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-graph.cpp, Page-425"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self):\n",
+ " if(self._Graphics__nobjects[0]==False):\n",
+ " self._Graphics__setgraphicsmode()\n",
+ " self._Graphics__nobjects[0]+=1\n",
+ "def __del__(self):\n",
+ " self._Graphics__nobjects[0]-=1\n",
+ " if(self._Graphics__nobjects[0]==False):\n",
+ " self._Graphics__settextmode()\n",
+ "class Graphics:\n",
+ " __nobjects=[0]\n",
+ " def __setgraphicsmode(self):\n",
+ " pass\n",
+ " def __settextmode(self):\n",
+ " pass\n",
+ " __init__=__init__\n",
+ " __del__=__del__\n",
+ " def getcount(self):\n",
+ " return self.__nobjects[0]\n",
+ "def my_func():\n",
+ " obj=Graphics()\n",
+ " print \"No. of Graphics' objects while in my_func=\", obj.getcount()\n",
+ "obj1=Graphics()\n",
+ "print \"No. of Graphics' objects before in my_func=\", obj1.getcount()\n",
+ "my_func()\n",
+ "print \"No. of Graphics' objects after in my_func=\", obj1.getcount()\n",
+ "obj2=Graphics()\n",
+ "obj3=Graphics()\n",
+ "obj4=Graphics()\n",
+ "print \"Value of static member nobjects after all 3 more objects...\"\n",
+ "print \"In obj1= \", obj1.getcount()\n",
+ "print \"In obj2= \", obj2.getcount()\n",
+ "print \"In obj3= \", obj3.getcount()\n",
+ "print \"In obj4= \", obj4.getcount()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No. of Graphics' objects before in my_func= 1\n",
+ "No. of Graphics' objects while in my_func= 2\n",
+ "No. of Graphics' objects after in my_func= 1\n",
+ "Value of static member nobjects after all 3 more objects...\n",
+ "In obj1= 4\n",
+ "In obj2= 4\n",
+ "In obj3= 4\n",
+ "In obj4= 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example Page-428"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def distance(self, a, b):\n",
+ " self.x=a.x-b.x\n",
+ " self.y=a.y-b.y\n",
+ "def display(self):\n",
+ " print \"x= \",self.x\n",
+ " print \"y= \", self.y\n",
+ "class point:\n",
+ " __x=int\n",
+ " __y=int\n",
+ " def __init__(self, a=None, b=None):\n",
+ " if isinstance(a, int):\n",
+ " self.x=a\n",
+ " self.y=b\n",
+ " else:\n",
+ " self.x=self.y=0\n",
+ " def __del__(self):\n",
+ " pass\n",
+ " distance=distance\n",
+ " display=display\n",
+ "p1=point(40,18)\n",
+ "p2=point(12,9)\n",
+ "p3=point()\n",
+ "p3.distance(p1,p2)\n",
+ "print \"Coordinates of P1: \"\n",
+ "p1.display()\n",
+ "print \"Coordinates of P2: \"\n",
+ "p2.display()\n",
+ "print \"distance between P1 and P2: \"\n",
+ "p3.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Coordinates of P1: \n",
+ "x= 40\n",
+ "y= 18\n",
+ "Coordinates of P2: \n",
+ "x= 12\n",
+ "y= 9\n",
+ "distance between P1 and P2: \n",
+ "x= 28\n",
+ "y= 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example Page-430"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def display(self):\n",
+ " print \"a =\", self.a,\n",
+ " print \"b =\", self.b\n",
+ "class data:\n",
+ " __a=int\n",
+ " __b=float\n",
+ " def __init__(self, x=None, y=None):\n",
+ " if isinstance(x, int):\n",
+ " self.a=x\n",
+ " self.b=y\n",
+ " elif isinstance(x, data):\n",
+ " self.a=x.a\n",
+ " self.b=x.b\n",
+ " else:\n",
+ " self.a=0\n",
+ " self.b=0\n",
+ " display=display\n",
+ "d1=data()\n",
+ "d2=data(12,9.9)\n",
+ "d3=data(d2)\n",
+ "print \"For default constructor: \"\n",
+ "d1.display()\n",
+ "print\"For parameterized constructor: \"\n",
+ "d2.display()\n",
+ "print \"For Copy Constructor: \"\n",
+ "d3.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For default constructor: \n",
+ "a = 0 b = 0\n",
+ "For parameterized constructor: \n",
+ "a = 12 b = 9.9\n",
+ "For Copy Constructor: \n",
+ "a = 12 b = 9.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/Tarun KumarDas/Chapter9.ipynb b/sample_notebooks/Tarun KumarDas/Chapter9.ipynb
new file mode 100755
index 00000000..320477a8
--- /dev/null
+++ b/sample_notebooks/Tarun KumarDas/Chapter9.ipynb
@@ -0,0 +1,227 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:023bb2358c5a7a6740b1b9a08290e11f954e790555a353817bbe84615e4679e6"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "CHAPTER 9: VALVE DIAGRAMS AND VALVE GEARS"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.5 Page 150"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#initialisation of variable\n",
+ "from math import pi,sqrt,acos,asin,atan,cos,sin,tan\n",
+ "p=20#in\n",
+ "l=100#in\n",
+ "r=120#r.p.m\n",
+ "v=3.5#in\n",
+ "l2=1#in\n",
+ "l3=1/8#in\n",
+ "v1=1.44#omega in/sec\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "V=p*(1.06/1.166)#omega in./sec\n",
+ "R=(V/v1)#omega in/sec\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"The ratio of velocity of the piston to the velocity is\",round(R,3),\"Omega in/sec\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The ratio of velocity of the piston to the velocity is 12.626 Omega in/sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.7 Page 151"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#initialisation of variable\n",
+ "from math import pi,sqrt,acos,asin,atan,cos,sin,tan\n",
+ "v=0.6#in\n",
+ "m=1.0#in\n",
+ "t=0.75#in\n",
+ "p=4#in\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "D=t/m#in\n",
+ "A=(p*m/D)#in\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"the travel and laps of the value is\",round(A,3),\"in\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the travel and laps of the value is 5.333 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.10 Page 154"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#initialisation of variable\n",
+ "from math import pi,sqrt,acos,asin,atan,cos,sin,tan\n",
+ "l=1.5#in\n",
+ "p=4.0#in\n",
+ "v=0.98#in\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "T=(l*p/v)#in\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"the particulars of a value and it eccentric is\",round(T,3),\"in\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the particulars of a value and it eccentric is 6.122 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.12 Page 156"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#initialisation of variable\n",
+ "from math import pi,sqrt,acos,asin,atan,cos,sin,tan\n",
+ "p=1/10#in\n",
+ "v1=3/4#in\n",
+ "v2=3/5#in\n",
+ "m=1*1/2#in\n",
+ "l=4#cranks\n",
+ "a1=1.25#in\n",
+ "a2=0.7#in\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "C=a1/a2#in\n",
+ "A=l*a1/a2#in\n",
+ "S=(A/2-a1)#in\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"the travel of the value is\",round(S,3),\"in\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the travel of the value is 2.321 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.17 Page 161"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#initialisation of variable\n",
+ "from math import pi,sqrt,acos,asin,atan,cos,sin,tan\n",
+ "v=3*1/2#in\n",
+ "a=30#degree\n",
+ "l=0.8#in\n",
+ "v1=0.2#in\n",
+ "L=0.13#in\n",
+ "m=1.075#in\n",
+ "d=0.58#in\n",
+ "p=1.875#in\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "V=(p-d)#in\n",
+ "P=V+1.25#in\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"the main value and the maximum opening to steam is\",round(P,3),\"in\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the main value and the maximum opening to steam is 2.545 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/VikasPrasad/chapter1.ipynb b/sample_notebooks/VikasPrasad/chapter1.ipynb
new file mode 100755
index 00000000..9e1549a9
--- /dev/null
+++ b/sample_notebooks/VikasPrasad/chapter1.ipynb
@@ -0,0 +1,166 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "1: Overview of Data Structures and Algorithms"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "1, 20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Thermostat:\n",
+ "\t\"\"\"A simple thermostat class\"\"\"\n",
+ "\t#since private instance variables don't exist in Python, hence using a convention: name prefixed with an underscore,\n",
+ " #to treat them as non-public part\n",
+ "\t_currentTemp = 0.0\n",
+ "\t_desiredTemp = 0.0\n",
+ "\n",
+ "\tdef furnace_on(self):\n",
+ "\t\t#method body goes here\n",
+ "\t\tpass\n",
+ "\n",
+ "\tdef furnace_off(self):\n",
+ "\t\t#method bisy goes here\n",
+ "\t\tpass\n",
+ "#end class Thermostat"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "2, 22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#demonstrates basic OOP syntax\n",
+ "\n",
+ "class BankAccount:\n",
+ "\t\"\"\"A simple bank account class\"\"\"\n",
+ "\t#since private instance variables don't exist in Python, hence using a convention: name prefixed with an underscore,\n",
+ " #to treat them as non-public part\n",
+ "\t_balance = 0.0\t#account balance\n",
+ "\n",
+ "\tdef __init__(self, openingBalance):\t#special method to cerate objects with instances customized to a specific initial state\n",
+ "\t\tself._balance = openingBalance\n",
+ "\n",
+ "\tdef deposit(self, amount):\t#makes deposit\n",
+ "\t\tself._balance = self._balance + amount\n",
+ "\n",
+ "\tdef withdraw(self, amount):\t#makes withdrawl\n",
+ "\t\tself._balance = self._balance - amount\n",
+ "\n",
+ "\tdef display(self):\t#displays balance\n",
+ "\t\tprint 'Balance=', self._balance\n",
+ "#end class BankAccount\n",
+ "\n",
+ "ba1 = BankAccount(100.00)\t#create account\n",
+ "\n",
+ "print 'Before transactions, ',\n",
+ "ba1.display()\t#display balance\n",
+ "\n",
+ "ba1.deposit(74.35)\t#make deposit\n",
+ "ba1.withdraw(20.00)\t#make withdrawl\n",
+ "\n",
+ "print 'After transactions, ',\n",
+ "ba1.display()\t#display balance\n",
+ "#end"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Before transactions, Balance= 100.0\n",
+ "After transactions, Balance= 154.35\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "3, 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#creating string objects\n",
+ "str1 = ''\n",
+ "str2 = 'George'\n",
+ "\n",
+ "#verifying results\n",
+ "print str1\n",
+ "print str2\n",
+ "\n",
+ "#naming string object\n",
+ "str3 = 'amanuensis'\n",
+ "\n",
+ "#verifying results\n",
+ "print str3\n",
+ "\n",
+ "#accessing specific characters from string using [] operator\n",
+ "ch1 = str2[3]\n",
+ "\n",
+ "#verifying results\n",
+ "print ch1\n",
+ "\n",
+ "#finding and printing number of characters in a string\n",
+ "print len(str1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "George\n",
+ "amanuensis\n",
+ "r\n",
+ "0\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/VikasPrasad/chapter1_1.ipynb b/sample_notebooks/VikasPrasad/chapter1_1.ipynb
new file mode 100755
index 00000000..9e1549a9
--- /dev/null
+++ b/sample_notebooks/VikasPrasad/chapter1_1.ipynb
@@ -0,0 +1,166 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "1: Overview of Data Structures and Algorithms"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "1, 20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Thermostat:\n",
+ "\t\"\"\"A simple thermostat class\"\"\"\n",
+ "\t#since private instance variables don't exist in Python, hence using a convention: name prefixed with an underscore,\n",
+ " #to treat them as non-public part\n",
+ "\t_currentTemp = 0.0\n",
+ "\t_desiredTemp = 0.0\n",
+ "\n",
+ "\tdef furnace_on(self):\n",
+ "\t\t#method body goes here\n",
+ "\t\tpass\n",
+ "\n",
+ "\tdef furnace_off(self):\n",
+ "\t\t#method bisy goes here\n",
+ "\t\tpass\n",
+ "#end class Thermostat"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "2, 22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#demonstrates basic OOP syntax\n",
+ "\n",
+ "class BankAccount:\n",
+ "\t\"\"\"A simple bank account class\"\"\"\n",
+ "\t#since private instance variables don't exist in Python, hence using a convention: name prefixed with an underscore,\n",
+ " #to treat them as non-public part\n",
+ "\t_balance = 0.0\t#account balance\n",
+ "\n",
+ "\tdef __init__(self, openingBalance):\t#special method to cerate objects with instances customized to a specific initial state\n",
+ "\t\tself._balance = openingBalance\n",
+ "\n",
+ "\tdef deposit(self, amount):\t#makes deposit\n",
+ "\t\tself._balance = self._balance + amount\n",
+ "\n",
+ "\tdef withdraw(self, amount):\t#makes withdrawl\n",
+ "\t\tself._balance = self._balance - amount\n",
+ "\n",
+ "\tdef display(self):\t#displays balance\n",
+ "\t\tprint 'Balance=', self._balance\n",
+ "#end class BankAccount\n",
+ "\n",
+ "ba1 = BankAccount(100.00)\t#create account\n",
+ "\n",
+ "print 'Before transactions, ',\n",
+ "ba1.display()\t#display balance\n",
+ "\n",
+ "ba1.deposit(74.35)\t#make deposit\n",
+ "ba1.withdraw(20.00)\t#make withdrawl\n",
+ "\n",
+ "print 'After transactions, ',\n",
+ "ba1.display()\t#display balance\n",
+ "#end"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Before transactions, Balance= 100.0\n",
+ "After transactions, Balance= 154.35\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "3, 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#creating string objects\n",
+ "str1 = ''\n",
+ "str2 = 'George'\n",
+ "\n",
+ "#verifying results\n",
+ "print str1\n",
+ "print str2\n",
+ "\n",
+ "#naming string object\n",
+ "str3 = 'amanuensis'\n",
+ "\n",
+ "#verifying results\n",
+ "print str3\n",
+ "\n",
+ "#accessing specific characters from string using [] operator\n",
+ "ch1 = str2[3]\n",
+ "\n",
+ "#verifying results\n",
+ "print ch1\n",
+ "\n",
+ "#finding and printing number of characters in a string\n",
+ "print len(str1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "George\n",
+ "amanuensis\n",
+ "r\n",
+ "0\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/YogeshPatil/Chapter_11.ipynb b/sample_notebooks/YogeshPatil/Chapter_11.ipynb
new file mode 100755
index 00000000..f749209f
--- /dev/null
+++ b/sample_notebooks/YogeshPatil/Chapter_11.ipynb
@@ -0,0 +1,494 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Voltage Regulators"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 11.1, Page No. 414"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# op-amp series voltage regulator design\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vin_min = 18-3 # min input voltage specification\n",
+ "Vin_max = 18+3 # max input voltage specification\n",
+ "Vout = 9 # output voltage specification\n",
+ "Iout_min = 10*10**-3 # min output current specification\n",
+ "Iout_max = 50*10**-3 # max output current specification\n",
+ "Vz = 5.6 # zener breakdown voltage\n",
+ "Pzmax = 0.5 # Maximum power dissipation in zener\n",
+ "\n",
+ "#Calculations\n",
+ "R1 = 10*10**3 # assumed\n",
+ "R2 = R1/((Vout/Vz)-1)\n",
+ "R3 = (Vin_min-Vz)/Iout_max\n",
+ "Iz = (Vin_max-Vz)/R3\n",
+ "Pd = Iz*Vz\n",
+ "beta = 30 # assumed\n",
+ "Ib = Iout_max/(beta+1)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Element values for designed circuit are as follows:\\nR1 = %d k-ohm\\nR2 = %.2f k-ohm\"%(R1/1000,R2/1000))\n",
+ "print(\"R3 = %.3f k-ohm\\nIB = %.2f mA\"%(R3/1000,Ib*1000))\n",
+ "#Answer for R3 is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element values for designed circuit are as follows:\n",
+ "R1 = 10 k-ohm\n",
+ "R2 = 16.47 k-ohm\n",
+ "R3 = 0.188 k-ohm\n",
+ "IB = 1.61 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 11.2, Page No. 420"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Regulator using IC 723\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vout = 5 # Required output voltage\n",
+ "Iout = 100*10**-3 # Required output current\n",
+ "Vin_min = 15-(0.2*15) # Min input voltage\n",
+ "Vin_max = 15+(0.2*15) # Max input voltage\n",
+ "Isc = 150*10**-3 # Short circuit current requirement\n",
+ "Vsense = 0.7 # short circuit voltage\n",
+ "Vref = 7.15 # reference votage for IC 723\n",
+ "Id = 1*10**-3 # potential divider current\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "Rsc = Vsense/Isc\n",
+ "R1 = (Vref-Vout)/Id\n",
+ "R1std = 2.2*10**3 \n",
+ "R2 = R1std/((Vref/Vout)-1)\n",
+ "R2std = 5.1*10**3 \n",
+ "R3 = R1std*R2std/(R1std+R2std)\n",
+ "R3std = 1.5*10**3 \n",
+ "\n",
+ "#Result\n",
+ "print(\"R1 = %.3f k-ohm\\t We use %.1f k-ohm as standard resistor.\"%(R1/1000,R1std/1000))\n",
+ "print(\"R2 = %.3f k-ohm\\t We use %.1f k-ohm as standard resistor.\"%(R2/1000,R2std/1000))\n",
+ "print(\"R3 = %.3f k-ohm\\t We use %.1f k-ohm as standard resistor.\"%(math.floor((R3/1000)*1000)/1000,R3std/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "R1 = 2.150 k-ohm\t We use 2.2 k-ohm as standard resistor.\n",
+ "R2 = 5.116 k-ohm\t We use 5.1 k-ohm as standard resistor.\n",
+ "R3 = 1.536 k-ohm\t We use 1.5 k-ohm as standard resistor.\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 11.3, Page No. 421"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ic 723 based positive voltage regulator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vout = 12.0 # output voltage\n",
+ "Il = 500*10**-3 # load current\n",
+ "Isc = 600*10**-3 # short circuit current\n",
+ "Vref = 7.0 # IC 723 reference voltage \n",
+ "Vsense = 0.6 # voltage at short circuit\n",
+ "\n",
+ "#Calculation\n",
+ "R1 = 4.7*10**3 # assumed\n",
+ "R2 = Vref*R1/(Vout-Vref)\n",
+ "R2std = 6.8*10**3 \n",
+ "Rsc = Vsense/Isc\n",
+ "R3 = R2std*R1/(R2std+R1)\n",
+ "Psc = Isc**2*Rsc*1000\n",
+ "I = Vout/(R1+R2std)\n",
+ "I= math.floor(I*10**6)/10**6\n",
+ "P1 = I**2*R1*1000\n",
+ "P2 = I**2*R2std*1000\n",
+ "\n",
+ "#Result\n",
+ "print(\"R1 = %.1f k-ohm\\nR2 = %.2f k-ohm = %.1f k-ohm(standard value)\\nRsc = %.1f ohm\"%(R1/1000,R2/1000,R2std/1000,Rsc))\n",
+ "print(\"\\nPower wattage:\\nPsc = %.0f mW\\nP1 = %.3f mW\\nP2 = %.3f mW\"%(Psc,math.floor(P1*1000)/1000,P2))\n",
+ "print(\"Hence, both R1 and R2 may be selected safely of 1/16th watt power rating.\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "R1 = 4.7 k-ohm\n",
+ "R2 = 6.58 k-ohm = 6.8 k-ohm(standard value)\n",
+ "Rsc = 1.0 ohm\n",
+ "\n",
+ "Power wattage:\n",
+ "Psc = 360 mW\n",
+ "P1 = 5.112 mW\n",
+ "P2 = 7.397 mW\n",
+ "Hence, both R1 and R2 may be selected safely of 1/16th watt power rating.\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 11.4, Page No. 426"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Regulator design using IC 723(refer to fig. 11.26)\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vout = 6 # output voltage\n",
+ "Il = 1 # load current\n",
+ "Isc = 0.250 # short circuit \n",
+ "Vref = 7 # reference voltage\n",
+ "Vbe = 0.7 # base-emitter junction voltage\n",
+ "\n",
+ "#Calculations\n",
+ "R1 = 2.7*10**3 # assumed\n",
+ "R2 = Vout*R1/(Vref-Vout)\n",
+ "kRsc = Vbe/Isc\n",
+ "k =1-(((Il-Isc)*kRsc)/Vout)\n",
+ "R4 = 10*10**3 # assumed \n",
+ "R3 = (1-k)*R4\n",
+ "Rsc = kRsc/k\n",
+ "R = (R1*R2)/(R1+R2)\n",
+ "\n",
+ "#Result\n",
+ "print(\"R1 = %.1f k-ohm\\nR2 = %.1f k-ohm\\nR3 = %.1f k-ohm\\nR4 = %.1f k-ohm\\nR = %.2f k-ohm\"%(R1/1000,R2/1000,R3/1000,R4/1000,R/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "R1 = 2.7 k-ohm\n",
+ "R2 = 16.2 k-ohm\n",
+ "R3 = 3.5 k-ohm\n",
+ "R4 = 10.0 k-ohm\n",
+ "R = 2.31 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 11.5, Page No.432"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Current source design using IC7812\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "RL = 25.0 # load resistance\n",
+ "P = 10.0 # power \n",
+ "I = 0.5 # current required\n",
+ "V = 12.0 # rated voltage\n",
+ "\n",
+ "#Calculations\n",
+ "R = V/I\n",
+ "Vout = V+(I*RL)\n",
+ "Vin = Vout+2\n",
+ "\n",
+ "#Result\n",
+ "print(\"R = %d ohm\\nVout = %.1f V\\nVin = %.1f V\"%(R,Vout,Vin))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "R = 24 ohm\n",
+ "Vout = 24.5 V\n",
+ "Vin = 26.5 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 11.6, Page NO. 432"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# min and max voltage of regulator(refer fig.11.34)\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Iq = 10*10**-3 # quiescent current\n",
+ "Vreg = 15.0 # regulated output voltage\n",
+ "R2 = 0 # min value of potentiometer\n",
+ "R1 = 40.0 # R1 resistor\n",
+ "\n",
+ "#Calculations\n",
+ "Vout = (1+(R2/R1))*Vreg+(Iq*R2)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Vout = %d V\"%Vout)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vout = 15 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 11.7, Page No. 432"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# current source using 7805\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Il = 0.2 # required load current\n",
+ "RL = 22.0 # load resistance\n",
+ "P = 10.0 # required power\n",
+ "Iq = 4.2*10**-3 # quiescent current\n",
+ "Vr = 5 # regulated output voltage\n",
+ "\n",
+ "#Calculation\n",
+ "R = Vr/(Il-Iq)\n",
+ "Vout = Vr+Il*RL\n",
+ "Vin = Vout+2\n",
+ "\n",
+ "#Result\n",
+ "print(\"R = %f ohm\\nVout = %.1f V\\nVin = %.1f V\"%(R,Vout,Vin))\n",
+ "# Answer for R is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "R = 25.536261 ohm\n",
+ "Vout = 9.4 V\n",
+ "Vin = 11.4 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 11.8, Page No.435"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Regulated outpuut voltage(refer fig. 11.38)\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1 = 220.0 # resistance R1\n",
+ "R2 = 1500.0 # Resistance R2\n",
+ "Iadj = 100*10**-6 # adj. current\n",
+ "\n",
+ "\n",
+ "#Calculartions\n",
+ "Vout = (1.25*(1+(R2/R1)))+(Iadj*R2)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Vout = %.2f V\"%Vout)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vout = 9.92 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 11.9, Page No. 435"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Output voltage range\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1 = 820.0 # resistance R1\n",
+ "R2min = 0 # min potentiometer resistance\n",
+ "R2max = 10*10**3 # max potentiometer resistance\n",
+ "Iadj = 100*10**-6 # adj. current\n",
+ "\n",
+ "#calculations\n",
+ "Vmin = 1.25*(1+(R2min/R1))+(Iadj*R2min)\n",
+ "Vmax = 1.25*(1+(R2max/R1))+(Iadj*R2max)\n",
+ "\n",
+ "#Result\n",
+ "print(\"The output can be varied in the range %.2f V to %.2f V\"%(Vmin,Vmax))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The output can be varied in the range 1.25 V to 17.49 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 11.10, Page No. 436"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Maximum load current\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vbe = 1.0 # base emitter junction voltage\n",
+ "beta = 15.0 # current gain\n",
+ "R1 = 7.0 # resistance R1\n",
+ "Iout = 1.0 # max output current from IC \n",
+ "#Calculations\n",
+ "Il = ((1+beta)*Iout) - beta*(Vbe/R1)\n",
+ "Il = math.floor(Il*100)/100\n",
+ "#Result\n",
+ "print(\"IC which can supply maximum 1A can supply maximum load of %.2f A, with the help of the current boosting arrangements\"%Il)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "IC which can supply maximum 1A can supply maximum load of 13.85 A, with the help of the current boosting arrangements\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/YogeshPatil/Chapter_2.ipynb b/sample_notebooks/YogeshPatil/Chapter_2.ipynb
new file mode 100755
index 00000000..2eef0dcc
--- /dev/null
+++ b/sample_notebooks/YogeshPatil/Chapter_2.ipynb
@@ -0,0 +1,229 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter No.2 : Operational Amplifier Fundamentals"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.1, Page No. 59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Input bias and input offset current\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ib1 = 18*10**-6 # base current of transistor 1\n",
+ "Ib2 = 22*10**-6 # base current of transistor 2\n",
+ "\n",
+ "#Calculations\n",
+ "#(i)\n",
+ "Ib = (Ib1+Ib2)/2\n",
+ "#(ii)\n",
+ "Iios = abs(Ib1-Ib2)\n",
+ "\n",
+ "#Result\n",
+ "print(\"(i) Input bias current = %d micro-A\\n(ii) Input offset current = %.0f micro-A\"%(Ib*10**6,Iios*10**6))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Input bias current = 20 micro-A\n",
+ "(ii) Input offset current = 4 micro-A\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.2, Page No. 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Maximum frequency of operation\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vin = 3.0 # input voltage\n",
+ "sr = 0.5*10**6 # slew rate in V/Sec\n",
+ "\n",
+ "#Calculations\n",
+ "Vm = Vin/2\n",
+ "fm = sr/(2*math.pi*Vm)\n",
+ "fm = fm /1000 \n",
+ "\n",
+ "#Result\n",
+ "print(\"Maximum frequency of operation is %.3f kHz\"%(math.floor(fm*1000)/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum frequency of operation is 53.051 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.3, Page No. 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Slew rate \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Icq = 15*10**-6 # Maximum op-amp current \n",
+ "C = 35*10**-12 # equivalent capacitance\n",
+ "V = 12.0 # input voltage \n",
+ "\n",
+ "#Calculations\n",
+ "S = Icq/C\n",
+ "S = S/10**6\n",
+ "\n",
+ "#Result\n",
+ "print(\"Slew rate = %.4f V/micro-sec\"%(math.floor(S*10**4)/10**4))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Slew rate = 0.4285 V/micro-sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.4, Page No. 66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Slew rate and maximum possible frequency of input\n",
+ "\n",
+ "import math\n",
+ "# Variable declaration\n",
+ "Icq = 10*10**-6 # maximum op-amp current\n",
+ "C = 33*10**-12 # equivalent capacitance\n",
+ "V = 12 # peak value of input voltage\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "S = Icq/C\n",
+ "fm = S/(2*math.pi*V)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Slew rate = %.3f V/micro-sec\\nfm = %.3f kHz\"%(S/10**6,fm/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Slew rate = 0.303 V/micro-sec\n",
+ "fm = 4.019 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.5, Page No. 66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Common mode rejection ratio(refere to fig 2.24)\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1 = 1000.0 # resistance 1\n",
+ "R2_1_E = 90000.0 # resistance R2(1-E)\n",
+ "R2 = 100000.0 # resistance R2\n",
+ "\n",
+ "#Calculations\n",
+ "Aid = R2/R1\n",
+ "E = 1-(R2_1_E/R2)\n",
+ "Acm = R2*E/(R1+R2)\n",
+ "CMRR = Aid/Acm\n",
+ "CMRR = 20*math.log10(CMRR)\n",
+ "\n",
+ "#Result\n",
+ "print(\"CMRR = %d dB\"%CMRR)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "CMRR = 60 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/YogeshPatil/Chapter_2_1.ipynb b/sample_notebooks/YogeshPatil/Chapter_2_1.ipynb
new file mode 100755
index 00000000..2eef0dcc
--- /dev/null
+++ b/sample_notebooks/YogeshPatil/Chapter_2_1.ipynb
@@ -0,0 +1,229 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter No.2 : Operational Amplifier Fundamentals"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.1, Page No. 59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Input bias and input offset current\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ib1 = 18*10**-6 # base current of transistor 1\n",
+ "Ib2 = 22*10**-6 # base current of transistor 2\n",
+ "\n",
+ "#Calculations\n",
+ "#(i)\n",
+ "Ib = (Ib1+Ib2)/2\n",
+ "#(ii)\n",
+ "Iios = abs(Ib1-Ib2)\n",
+ "\n",
+ "#Result\n",
+ "print(\"(i) Input bias current = %d micro-A\\n(ii) Input offset current = %.0f micro-A\"%(Ib*10**6,Iios*10**6))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Input bias current = 20 micro-A\n",
+ "(ii) Input offset current = 4 micro-A\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.2, Page No. 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Maximum frequency of operation\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vin = 3.0 # input voltage\n",
+ "sr = 0.5*10**6 # slew rate in V/Sec\n",
+ "\n",
+ "#Calculations\n",
+ "Vm = Vin/2\n",
+ "fm = sr/(2*math.pi*Vm)\n",
+ "fm = fm /1000 \n",
+ "\n",
+ "#Result\n",
+ "print(\"Maximum frequency of operation is %.3f kHz\"%(math.floor(fm*1000)/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum frequency of operation is 53.051 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.3, Page No. 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Slew rate \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Icq = 15*10**-6 # Maximum op-amp current \n",
+ "C = 35*10**-12 # equivalent capacitance\n",
+ "V = 12.0 # input voltage \n",
+ "\n",
+ "#Calculations\n",
+ "S = Icq/C\n",
+ "S = S/10**6\n",
+ "\n",
+ "#Result\n",
+ "print(\"Slew rate = %.4f V/micro-sec\"%(math.floor(S*10**4)/10**4))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Slew rate = 0.4285 V/micro-sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.4, Page No. 66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Slew rate and maximum possible frequency of input\n",
+ "\n",
+ "import math\n",
+ "# Variable declaration\n",
+ "Icq = 10*10**-6 # maximum op-amp current\n",
+ "C = 33*10**-12 # equivalent capacitance\n",
+ "V = 12 # peak value of input voltage\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "S = Icq/C\n",
+ "fm = S/(2*math.pi*V)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Slew rate = %.3f V/micro-sec\\nfm = %.3f kHz\"%(S/10**6,fm/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Slew rate = 0.303 V/micro-sec\n",
+ "fm = 4.019 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.5, Page No. 66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Common mode rejection ratio(refere to fig 2.24)\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1 = 1000.0 # resistance 1\n",
+ "R2_1_E = 90000.0 # resistance R2(1-E)\n",
+ "R2 = 100000.0 # resistance R2\n",
+ "\n",
+ "#Calculations\n",
+ "Aid = R2/R1\n",
+ "E = 1-(R2_1_E/R2)\n",
+ "Acm = R2*E/(R1+R2)\n",
+ "CMRR = Aid/Acm\n",
+ "CMRR = 20*math.log10(CMRR)\n",
+ "\n",
+ "#Result\n",
+ "print(\"CMRR = %d dB\"%CMRR)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "CMRR = 60 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/YogeshPatil/Chapter_2_2.ipynb b/sample_notebooks/YogeshPatil/Chapter_2_2.ipynb
new file mode 100755
index 00000000..2eef0dcc
--- /dev/null
+++ b/sample_notebooks/YogeshPatil/Chapter_2_2.ipynb
@@ -0,0 +1,229 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter No.2 : Operational Amplifier Fundamentals"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.1, Page No. 59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Input bias and input offset current\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ib1 = 18*10**-6 # base current of transistor 1\n",
+ "Ib2 = 22*10**-6 # base current of transistor 2\n",
+ "\n",
+ "#Calculations\n",
+ "#(i)\n",
+ "Ib = (Ib1+Ib2)/2\n",
+ "#(ii)\n",
+ "Iios = abs(Ib1-Ib2)\n",
+ "\n",
+ "#Result\n",
+ "print(\"(i) Input bias current = %d micro-A\\n(ii) Input offset current = %.0f micro-A\"%(Ib*10**6,Iios*10**6))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Input bias current = 20 micro-A\n",
+ "(ii) Input offset current = 4 micro-A\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.2, Page No. 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Maximum frequency of operation\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vin = 3.0 # input voltage\n",
+ "sr = 0.5*10**6 # slew rate in V/Sec\n",
+ "\n",
+ "#Calculations\n",
+ "Vm = Vin/2\n",
+ "fm = sr/(2*math.pi*Vm)\n",
+ "fm = fm /1000 \n",
+ "\n",
+ "#Result\n",
+ "print(\"Maximum frequency of operation is %.3f kHz\"%(math.floor(fm*1000)/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum frequency of operation is 53.051 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.3, Page No. 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Slew rate \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Icq = 15*10**-6 # Maximum op-amp current \n",
+ "C = 35*10**-12 # equivalent capacitance\n",
+ "V = 12.0 # input voltage \n",
+ "\n",
+ "#Calculations\n",
+ "S = Icq/C\n",
+ "S = S/10**6\n",
+ "\n",
+ "#Result\n",
+ "print(\"Slew rate = %.4f V/micro-sec\"%(math.floor(S*10**4)/10**4))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Slew rate = 0.4285 V/micro-sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.4, Page No. 66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Slew rate and maximum possible frequency of input\n",
+ "\n",
+ "import math\n",
+ "# Variable declaration\n",
+ "Icq = 10*10**-6 # maximum op-amp current\n",
+ "C = 33*10**-12 # equivalent capacitance\n",
+ "V = 12 # peak value of input voltage\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "S = Icq/C\n",
+ "fm = S/(2*math.pi*V)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Slew rate = %.3f V/micro-sec\\nfm = %.3f kHz\"%(S/10**6,fm/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Slew rate = 0.303 V/micro-sec\n",
+ "fm = 4.019 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.5, Page No. 66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Common mode rejection ratio(refere to fig 2.24)\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1 = 1000.0 # resistance 1\n",
+ "R2_1_E = 90000.0 # resistance R2(1-E)\n",
+ "R2 = 100000.0 # resistance R2\n",
+ "\n",
+ "#Calculations\n",
+ "Aid = R2/R1\n",
+ "E = 1-(R2_1_E/R2)\n",
+ "Acm = R2*E/(R1+R2)\n",
+ "CMRR = Aid/Acm\n",
+ "CMRR = 20*math.log10(CMRR)\n",
+ "\n",
+ "#Result\n",
+ "print(\"CMRR = %d dB\"%CMRR)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "CMRR = 60 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/YogeshPatil/Chapter_2_3.ipynb b/sample_notebooks/YogeshPatil/Chapter_2_3.ipynb
new file mode 100755
index 00000000..2eef0dcc
--- /dev/null
+++ b/sample_notebooks/YogeshPatil/Chapter_2_3.ipynb
@@ -0,0 +1,229 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter No.2 : Operational Amplifier Fundamentals"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.1, Page No. 59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Input bias and input offset current\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ib1 = 18*10**-6 # base current of transistor 1\n",
+ "Ib2 = 22*10**-6 # base current of transistor 2\n",
+ "\n",
+ "#Calculations\n",
+ "#(i)\n",
+ "Ib = (Ib1+Ib2)/2\n",
+ "#(ii)\n",
+ "Iios = abs(Ib1-Ib2)\n",
+ "\n",
+ "#Result\n",
+ "print(\"(i) Input bias current = %d micro-A\\n(ii) Input offset current = %.0f micro-A\"%(Ib*10**6,Iios*10**6))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Input bias current = 20 micro-A\n",
+ "(ii) Input offset current = 4 micro-A\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.2, Page No. 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Maximum frequency of operation\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vin = 3.0 # input voltage\n",
+ "sr = 0.5*10**6 # slew rate in V/Sec\n",
+ "\n",
+ "#Calculations\n",
+ "Vm = Vin/2\n",
+ "fm = sr/(2*math.pi*Vm)\n",
+ "fm = fm /1000 \n",
+ "\n",
+ "#Result\n",
+ "print(\"Maximum frequency of operation is %.3f kHz\"%(math.floor(fm*1000)/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum frequency of operation is 53.051 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.3, Page No. 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Slew rate \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Icq = 15*10**-6 # Maximum op-amp current \n",
+ "C = 35*10**-12 # equivalent capacitance\n",
+ "V = 12.0 # input voltage \n",
+ "\n",
+ "#Calculations\n",
+ "S = Icq/C\n",
+ "S = S/10**6\n",
+ "\n",
+ "#Result\n",
+ "print(\"Slew rate = %.4f V/micro-sec\"%(math.floor(S*10**4)/10**4))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Slew rate = 0.4285 V/micro-sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.4, Page No. 66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Slew rate and maximum possible frequency of input\n",
+ "\n",
+ "import math\n",
+ "# Variable declaration\n",
+ "Icq = 10*10**-6 # maximum op-amp current\n",
+ "C = 33*10**-12 # equivalent capacitance\n",
+ "V = 12 # peak value of input voltage\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "S = Icq/C\n",
+ "fm = S/(2*math.pi*V)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Slew rate = %.3f V/micro-sec\\nfm = %.3f kHz\"%(S/10**6,fm/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Slew rate = 0.303 V/micro-sec\n",
+ "fm = 4.019 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 2.5, Page No. 66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Common mode rejection ratio(refere to fig 2.24)\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1 = 1000.0 # resistance 1\n",
+ "R2_1_E = 90000.0 # resistance R2(1-E)\n",
+ "R2 = 100000.0 # resistance R2\n",
+ "\n",
+ "#Calculations\n",
+ "Aid = R2/R1\n",
+ "E = 1-(R2_1_E/R2)\n",
+ "Acm = R2*E/(R1+R2)\n",
+ "CMRR = Aid/Acm\n",
+ "CMRR = 20*math.log10(CMRR)\n",
+ "\n",
+ "#Result\n",
+ "print(\"CMRR = %d dB\"%CMRR)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "CMRR = 60 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/ajinkyakhair/Untitled3.ipynb b/sample_notebooks/ajinkyakhair/Untitled3.ipynb
new file mode 100755
index 00000000..c9360e01
--- /dev/null
+++ b/sample_notebooks/ajinkyakhair/Untitled3.ipynb
@@ -0,0 +1,105 @@
+{
+ "metadata": {
+ "celltoolbar": "Raw Cell Format",
+ "name": "",
+ "signature": "sha256:1b9250434a66c555344f74813ca967ce998b1c86d33424d56ca71d7c748c63ce"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1: Interference"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7, Page number 1-19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "#Given Data:\n",
+ "i=30 #angle of incidence\n",
+ "u=1.43 #Refractive index of a soap film\n",
+ "lamda=6*10**-7 #wavelength of light\n",
+ "n=1 #For minimum thickness\n",
+ "\n",
+ "#Calculations:\n",
+ "#u=sin i/sin r #Snell's law .So,\n",
+ "r=math.degrees(math.asin(math.sin(i)/u)) #angle of reflection\n",
+ "\n",
+ "#Now, condition of minima in transmitted system is\n",
+ "#2ut*cos(r)=(2n-1)lam/2\n",
+ "t=lamda/(2*2*u*math.cos(r)) #minimum thickness of film\n",
+ "print\"Minimum thickness of film is \",t,\"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Minimum thickness of film is 1.09096619878e-07 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.8, Page number 1-19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#Given Data:\n",
+ "\n",
+ "lamda = 5893*10**-10 #Wavelength of light\n",
+ "theta = 1 #assuming value of theta\n",
+ "\n",
+ "#We know, B=lam/(2*u*theta). Here u=1\n",
+ "B = lamda/(2*theta) #fringe spacing\n",
+ "n=20 #interference fringes\n",
+ "\n",
+ "#Calculations:\n",
+ "#t=n*B*tan(theta)\n",
+ "t = 20*B*theta #Thickness of wire\n",
+ "print\"Thickness of wire is =\",t,\"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Thickness of wire is = 5.893e-06 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/ajinkyakhair/Untitled3_1.ipynb b/sample_notebooks/ajinkyakhair/Untitled3_1.ipynb
new file mode 100755
index 00000000..c9360e01
--- /dev/null
+++ b/sample_notebooks/ajinkyakhair/Untitled3_1.ipynb
@@ -0,0 +1,105 @@
+{
+ "metadata": {
+ "celltoolbar": "Raw Cell Format",
+ "name": "",
+ "signature": "sha256:1b9250434a66c555344f74813ca967ce998b1c86d33424d56ca71d7c748c63ce"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1: Interference"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7, Page number 1-19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "#Given Data:\n",
+ "i=30 #angle of incidence\n",
+ "u=1.43 #Refractive index of a soap film\n",
+ "lamda=6*10**-7 #wavelength of light\n",
+ "n=1 #For minimum thickness\n",
+ "\n",
+ "#Calculations:\n",
+ "#u=sin i/sin r #Snell's law .So,\n",
+ "r=math.degrees(math.asin(math.sin(i)/u)) #angle of reflection\n",
+ "\n",
+ "#Now, condition of minima in transmitted system is\n",
+ "#2ut*cos(r)=(2n-1)lam/2\n",
+ "t=lamda/(2*2*u*math.cos(r)) #minimum thickness of film\n",
+ "print\"Minimum thickness of film is \",t,\"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Minimum thickness of film is 1.09096619878e-07 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.8, Page number 1-19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#Given Data:\n",
+ "\n",
+ "lamda = 5893*10**-10 #Wavelength of light\n",
+ "theta = 1 #assuming value of theta\n",
+ "\n",
+ "#We know, B=lam/(2*u*theta). Here u=1\n",
+ "B = lamda/(2*theta) #fringe spacing\n",
+ "n=20 #interference fringes\n",
+ "\n",
+ "#Calculations:\n",
+ "#t=n*B*tan(theta)\n",
+ "t = 20*B*theta #Thickness of wire\n",
+ "print\"Thickness of wire is =\",t,\"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Thickness of wire is = 5.893e-06 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/harishsahu/Chapter1.ipynb b/sample_notebooks/harishsahu/Chapter1.ipynb
new file mode 100755
index 00000000..40f0220e
--- /dev/null
+++ b/sample_notebooks/harishsahu/Chapter1.ipynb
@@ -0,0 +1,134 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e3cd5ced27f4cedce3cbdbb3b5b1f422b536f401e599f719b4c9b39198a059c3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter1-Mohrs circle"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1-pg12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "##Mohr's circle\n",
+ "#calculate center of the circle and maxi principal stress and pricipal stress and maxi shearing stresss\n",
+ "import numpy\n",
+ "from numpy.linalg import inv\n",
+ "import math\n",
+ "sigma=((40+80)/2.)\n",
+ "print'%s %.2f %s'%(\"center of the circle in MPa = \",sigma,\"\")\n",
+ "\n",
+ "##solution a\n",
+ "x=((80-40)**2.);\n",
+ "y=30**2.;\n",
+ "sigma1=60.+math.sqrt((.25*x)+y)\n",
+ "print'%s %.2f %s'%(\"maxi pricipal stress in MPa = \",sigma1,\"\");## print'%s %.2f %s'%laying result\n",
+ "sigma2=60.-math.sqrt((.25*x)+y)\n",
+ "print'%s %.2f %s'%(\"mini pricipal stress in MPa = \",sigma2,\"\");## print'%s %.2f %s'%laying result\n",
+ "theta1=((math.atan((30./20.))/2)*57.3)\n",
+ "print'%s %.2f %s'%(\"pricipal stresses in degree\",theta1,\"\");## print'%s %.2f %s'%laying result\n",
+ "theta2=(((math.atan(30/20.))+180.)/2.)*57.3\n",
+ "print'%s %.2f %s'%(\"pricipal stresses in degree\",theta2,\"\");## print'%s %.2f %s'%laying result\n",
+ "\n",
+ "##solution b\n",
+ "tau=math.sqrt((.25*x)+y)\n",
+ "print'%s %.2f %s'%(\"maxi shearing stress in MPa = \",tau,\"\");## print'%s %.2f %s'%laying result\n",
+ "theta3=theta1+45.\n",
+ "print'%s %.2f %s'%(\"stress in MPa = \",theta3,\"\");## print'%s %.2f %s'%laying result\n",
+ "theta4=theta2+45\n",
+ "print'%s %.2f %s'%(\"stress in MPa = \",theta4,\"\");## print'%s %.2f %s'%laying result\n",
+ "\n",
+ "##final solution in matrix form\n",
+ "p=([[80 ,30], [30 ,40]])\n",
+ "print(p) \n",
+ "q=([[sigma1, 0 ],[0 ,sigma2]])\n",
+ "print(q)\n",
+ "r=([[sigma ,-tau], [-tau ,sigma]])\n",
+ "print(r)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "center of the circle in MPa = 60.00 \n",
+ "maxi pricipal stress in MPa = 96.06 \n",
+ "mini pricipal stress in MPa = 23.94 \n",
+ "pricipal stresses in degree 28.16 \n",
+ "pricipal stresses in degree 5185.16 \n",
+ "maxi shearing stress in MPa = 36.06 \n",
+ "stress in MPa = 73.16 \n",
+ "stress in MPa = 5230.16 \n",
+ "[[80, 30], [30, 40]]\n",
+ "[[96.05551275463989, 0], [0, 23.944487245360108]]\n",
+ "[[60.0, -36.05551275463989], [-36.05551275463989, 60.0]]\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2-pg17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "##Mohr's circle\n",
+ "#calculate radius of the circle in and orientation of the stress\n",
+ "import math\n",
+ "radius=((14+28)/2.)\n",
+ "print'%s %.2f %s'%(\"radius of the circle in degree = \",radius,\"\")\n",
+ "sigma1=(7+radius *math.cos(60/57.3))\n",
+ "print'%s %.2f %s'%(\" the circle in MPa = \",sigma1,\"\")\n",
+ "sigma2=(7-radius *math.cos(60/57.3))\n",
+ "print'%s %.2f %s'%(\" the circle in MPa = \",sigma2,\"\")\n",
+ "tau1=radius*math.sin(60./57.3)\n",
+ "print'%s %.2f %s'%(\" orientation of the stresses in MPa = \",tau1,\"\")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "radius of the circle in degree = 21.00 \n",
+ " the circle in MPa = 17.50 \n",
+ " the circle in MPa = -3.50 \n",
+ " orientation of the stresses in MPa = 18.19 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/harishsahu/Chapter1_1.ipynb b/sample_notebooks/harishsahu/Chapter1_1.ipynb
new file mode 100755
index 00000000..40f0220e
--- /dev/null
+++ b/sample_notebooks/harishsahu/Chapter1_1.ipynb
@@ -0,0 +1,134 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e3cd5ced27f4cedce3cbdbb3b5b1f422b536f401e599f719b4c9b39198a059c3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter1-Mohrs circle"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1-pg12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "##Mohr's circle\n",
+ "#calculate center of the circle and maxi principal stress and pricipal stress and maxi shearing stresss\n",
+ "import numpy\n",
+ "from numpy.linalg import inv\n",
+ "import math\n",
+ "sigma=((40+80)/2.)\n",
+ "print'%s %.2f %s'%(\"center of the circle in MPa = \",sigma,\"\")\n",
+ "\n",
+ "##solution a\n",
+ "x=((80-40)**2.);\n",
+ "y=30**2.;\n",
+ "sigma1=60.+math.sqrt((.25*x)+y)\n",
+ "print'%s %.2f %s'%(\"maxi pricipal stress in MPa = \",sigma1,\"\");## print'%s %.2f %s'%laying result\n",
+ "sigma2=60.-math.sqrt((.25*x)+y)\n",
+ "print'%s %.2f %s'%(\"mini pricipal stress in MPa = \",sigma2,\"\");## print'%s %.2f %s'%laying result\n",
+ "theta1=((math.atan((30./20.))/2)*57.3)\n",
+ "print'%s %.2f %s'%(\"pricipal stresses in degree\",theta1,\"\");## print'%s %.2f %s'%laying result\n",
+ "theta2=(((math.atan(30/20.))+180.)/2.)*57.3\n",
+ "print'%s %.2f %s'%(\"pricipal stresses in degree\",theta2,\"\");## print'%s %.2f %s'%laying result\n",
+ "\n",
+ "##solution b\n",
+ "tau=math.sqrt((.25*x)+y)\n",
+ "print'%s %.2f %s'%(\"maxi shearing stress in MPa = \",tau,\"\");## print'%s %.2f %s'%laying result\n",
+ "theta3=theta1+45.\n",
+ "print'%s %.2f %s'%(\"stress in MPa = \",theta3,\"\");## print'%s %.2f %s'%laying result\n",
+ "theta4=theta2+45\n",
+ "print'%s %.2f %s'%(\"stress in MPa = \",theta4,\"\");## print'%s %.2f %s'%laying result\n",
+ "\n",
+ "##final solution in matrix form\n",
+ "p=([[80 ,30], [30 ,40]])\n",
+ "print(p) \n",
+ "q=([[sigma1, 0 ],[0 ,sigma2]])\n",
+ "print(q)\n",
+ "r=([[sigma ,-tau], [-tau ,sigma]])\n",
+ "print(r)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "center of the circle in MPa = 60.00 \n",
+ "maxi pricipal stress in MPa = 96.06 \n",
+ "mini pricipal stress in MPa = 23.94 \n",
+ "pricipal stresses in degree 28.16 \n",
+ "pricipal stresses in degree 5185.16 \n",
+ "maxi shearing stress in MPa = 36.06 \n",
+ "stress in MPa = 73.16 \n",
+ "stress in MPa = 5230.16 \n",
+ "[[80, 30], [30, 40]]\n",
+ "[[96.05551275463989, 0], [0, 23.944487245360108]]\n",
+ "[[60.0, -36.05551275463989], [-36.05551275463989, 60.0]]\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2-pg17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "##Mohr's circle\n",
+ "#calculate radius of the circle in and orientation of the stress\n",
+ "import math\n",
+ "radius=((14+28)/2.)\n",
+ "print'%s %.2f %s'%(\"radius of the circle in degree = \",radius,\"\")\n",
+ "sigma1=(7+radius *math.cos(60/57.3))\n",
+ "print'%s %.2f %s'%(\" the circle in MPa = \",sigma1,\"\")\n",
+ "sigma2=(7-radius *math.cos(60/57.3))\n",
+ "print'%s %.2f %s'%(\" the circle in MPa = \",sigma2,\"\")\n",
+ "tau1=radius*math.sin(60./57.3)\n",
+ "print'%s %.2f %s'%(\" orientation of the stresses in MPa = \",tau1,\"\")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "radius of the circle in degree = 21.00 \n",
+ " the circle in MPa = 17.50 \n",
+ " the circle in MPa = -3.50 \n",
+ " orientation of the stresses in MPa = 18.19 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/harishsahu/Chapter1_2.ipynb b/sample_notebooks/harishsahu/Chapter1_2.ipynb
new file mode 100755
index 00000000..ba50b05f
--- /dev/null
+++ b/sample_notebooks/harishsahu/Chapter1_2.ipynb
@@ -0,0 +1,134 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c5f8065703fbeb58a71f73144f936d51092395de25fe2bd4b3e4c9b6e159ad53"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter1-Mohrs circle"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1-pg12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "##Mohr's circle\n",
+ "#calculate center of the circle and maxi principal stress and pricipal stress and maxi shearing stresss\n",
+ "import numpy\n",
+ "from numpy.linalg import inv\n",
+ "import math\n",
+ "sigma=((40+80)/2.)\n",
+ "print'%s %.2f %s'%(\"center of the circle in MPa = \",sigma,\"\")\n",
+ "\n",
+ "##solution a\n",
+ "x=((80-40)**2.);\n",
+ "y=30**2.;\n",
+ "sigma1=60.+math.sqrt((.25*x)+y)\n",
+ "print'%s %.2f %s'%(\"maxi pricipal stress in MPa = \",sigma1,\"\");## print'%s %.2f %s'%laying result\n",
+ "sigma2=60.-math.sqrt((.25*x)+y)\n",
+ "print'%s %.2f %s'%(\"mini pricipal stress in MPa = \",sigma2,\"\");## print'%s %.2f %s'%laying result\n",
+ "theta1=((math.atan((30./20.))/2)*57.3)\n",
+ "print'%s %.2f %s'%(\"pricipal stresses in degree\",theta1,\"\");## print'%s %.2f %s'%laying result\n",
+ "theta2=(((math.atan(30/20.))+180.)/2.)*57.3\n",
+ "print'%s %.2f %s'%(\"pricipal stresses in degree\",theta2,\"\");## print'%s %.2f %s'%laying result\n",
+ "\n",
+ "##solution b\n",
+ "tau=math.sqrt((.25*x)+y)\n",
+ "print'%s %.2f %s'%(\"maxi shearing stress in MPa = \",tau,\"\");## print'%s %.2f %s'%laying result\n",
+ "theta3=theta1+45.\n",
+ "print'%s %.2f %s'%(\"stress in MPa = \",theta3,\"\");## print'%s %.2f %s'%laying result\n",
+ "theta4=theta2+45\n",
+ "print'%s %.2f %s'%(\"stress in MPa = \",theta4,\"\");## print'%s %.2f %s'%laying result\n",
+ "\n",
+ "##final solution in matrix form\n",
+ "p=([[80 ,30], [30 ,40]])\n",
+ "print(p) \n",
+ "q=([[sigma1, 0 ],[0 ,sigma2]])\n",
+ "print(q)\n",
+ "r=([[sigma ,-tau], [-tau ,sigma]])\n",
+ "print(r)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "center of the circle in MPa = 60.00 \n",
+ "maxi pricipal stress in MPa = 96.06 \n",
+ "mini pricipal stress in MPa = 23.94 \n",
+ "pricipal stresses in degree 28.16 \n",
+ "pricipal stresses in degree 5185.16 \n",
+ "maxi shearing stress in MPa = 36.06 \n",
+ "stress in MPa = 73.16 \n",
+ "stress in MPa = 5230.16 \n",
+ "[[80, 30], [30, 40]]\n",
+ "[[96.05551275463989, 0], [0, 23.944487245360108]]\n",
+ "[[60.0, -36.05551275463989], [-36.05551275463989, 60.0]]\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2-pg17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "##Mohr's circle\n",
+ "#calculate radius of the circle in and orientation of the stress\n",
+ "import math\n",
+ "radius=((14+28)/2.)\n",
+ "print'%s %.2f %s'%(\"radius of the circle in degree = \",radius,\"\")\n",
+ "sigma1=(7+radius *math.cos(60/57.3))\n",
+ "print'%s %.2f %s'%(\" the circle in MPa = \",sigma1,\"\")\n",
+ "sigma2=(7-radius *math.cos(60/57.3))\n",
+ "print'%s %.2f %s'%(\" the circle in MPa = \",sigma2,\"\")\n",
+ "tau1=radius*math.sin(60./57.3)\n",
+ "print'%s %.2f %s'%(\" orientation of the stresses in MPa = \",tau1,\"\")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "radius of the circle in degree = 21.00 \n",
+ " the circle in MPa = 17.50 \n",
+ " the circle in MPa = -3.50 \n",
+ " orientation of the stresses in MPa = 18.19 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file