summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Antennas_and_Wave_Propagation/README.txt10
-rw-r--r--Antennas_and_Wave_Propagation/chapter11.ipynb100
-rw-r--r--Antennas_and_Wave_Propagation/chapter12.ipynb195
-rw-r--r--Antennas_and_Wave_Propagation/chapter15.ipynb830
-rw-r--r--Antennas_and_Wave_Propagation/chapter16.ipynb101
-rw-r--r--Antennas_and_Wave_Propagation/chapter17.ipynb323
-rw-r--r--Antennas_and_Wave_Propagation/chapter19.ipynb136
-rw-r--r--Antennas_and_Wave_Propagation/chapter2.ipynb486
-rw-r--r--Antennas_and_Wave_Propagation/chapter21.ipynb343
-rw-r--r--Antennas_and_Wave_Propagation/chapter23.ipynb302
-rw-r--r--Antennas_and_Wave_Propagation/chapter24.ipynb332
-rw-r--r--Antennas_and_Wave_Propagation/chapter25.ipynb242
-rw-r--r--Antennas_and_Wave_Propagation/chapter3.ipynb175
-rw-r--r--Antennas_and_Wave_Propagation/chapter4.ipynb272
-rw-r--r--Antennas_and_Wave_Propagation/chapter5.ipynb312
-rw-r--r--Antennas_and_Wave_Propagation/chapter6.ipynb182
-rw-r--r--Antennas_and_Wave_Propagation/chapter7.ipynb386
-rw-r--r--Antennas_and_Wave_Propagation/chapter8.ipynb192
-rw-r--r--Antennas_and_Wave_Propagation/chapter9.ipynb65
-rw-r--r--Antennas_and_Wave_Propagation/screenshots/snapshot1.pngbin0 -> 70906 bytes
-rw-r--r--Antennas_and_Wave_Propagation/screenshots/snapshot2.pngbin0 -> 52668 bytes
-rw-r--r--Antennas_and_Wave_Propagation/screenshots/snapshot3.pngbin0 -> 83321 bytes
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/README.txt10
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch1.ipynb184
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch10.ipynb455
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch11.ipynb256
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch12.ipynb210
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch13.ipynb223
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch14.ipynb90
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch15.ipynb240
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch16.ipynb185
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch17.ipynb225
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch2.ipynb398
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch3.ipynb123
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch4.ipynb456
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch6.ipynb406
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch7.ipynb112
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch8.ipynb466
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/ch9.ipynb494
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/screenshots/15ImpulseTurbines.pngbin0 -> 143416 bytes
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/screenshots/1PropertiesOfFluids.pngbin0 -> 173956 bytes
-rw-r--r--Fluid_Mechanics_With_Engineering_Applications/screenshots/8.pngbin0 -> 129686 bytes
-rw-r--r--Mastering_C/chapter1.ipynb170
-rw-r--r--Mastering_C/chapter10.ipynb913
-rw-r--r--Mastering_C/chapter11.ipynb1993
-rw-r--r--Mastering_C/chapter12.ipynb4076
-rw-r--r--Mastering_C/chapter15.ipynb99
-rw-r--r--Mastering_C/chapter16.ipynb116
-rw-r--r--Mastering_C/chapter2.ipynb981
-rw-r--r--Mastering_C/chapter3.ipynb584
-rw-r--r--Mastering_C/chapter4.ipynb1567
-rw-r--r--Mastering_C/chapter5.ipynb1515
-rw-r--r--Mastering_C/chapter6.ipynb603
-rw-r--r--Mastering_C/chapter7.ipynb2482
-rw-r--r--Mastering_C/chapter8.ipynb2252
-rw-r--r--Mastering_C/chapter9.ipynb1463
-rw-r--r--Mastering_C/screenshots/interest.pngbin0 -> 69524 bytes
-rw-r--r--Mastering_C/screenshots/matrix.pngbin0 -> 43479 bytes
-rw-r--r--Mastering_C/screenshots/stack.pngbin0 -> 44229 bytes
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C10_1.ipynb430
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C11_1.ipynb694
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C12_1.ipynb358
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C13_1.ipynb496
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C14_1.ipynb509
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C15_1.ipynb321
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C16_1.ipynb344
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C2_1.ipynb212
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C3_1.ipynb555
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C4_1.ipynb236
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C5_1.ipynb733
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C6_1.ipynb490
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C7_1.ipynb63
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C8_1.ipynb544
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/C9_1.ipynb297
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/README.txt10
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/2_2.pngbin0 -> 24698 bytes
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/2_2_(1).pngbin0 -> 24698 bytes
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/3_4.pngbin0 -> 27701 bytes
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/3_4_(1).pngbin0 -> 27701 bytes
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/4_1.pngbin0 -> 20737 bytes
-rw-r--r--Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/4_1_(1).pngbin0 -> 20737 bytes
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter1.ipynb28
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter10_1.ipynb104
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter10_2.ipynb104
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter11.ipynb62
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter11_2.ipynb62
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter12_1.ipynb488
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter12_2.ipynb488
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter13_1.ipynb146
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter13_2.ipynb146
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter14_1.ipynb188
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter14_2.ipynb188
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter15.ipynb28
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter15_1.ipynb28
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter15_2.ipynb28
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter1_1.ipynb28
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter1_2.ipynb28
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter2_1.ipynb251
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter2_2.ipynb251
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter3.ipynb322
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter3_1.ipynb322
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter4_1.ipynb35
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter4_2.ipynb35
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter5.ipynb239
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter5_1.ipynb239
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter6_1.ipynb188
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter6_2.ipynb188
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter7_1.ipynb167
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter7_2.ipynb167
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter8.ipynb209
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter8_1.ipynb209
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter9_1.ipynb188
-rwxr-xr-xOptical_Fiber_Communication_Principles_and_Practice/Chapter9_2.ipynb188
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/Chapter_10.ipynb (renamed from Optical_Fiber_Communication_Principles_and_Practice/Chapter10.ipynb)0
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/Chapter_11.ipynb (renamed from Optical_Fiber_Communication_Principles_and_Practice/Chapter11_1.ipynb)23
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/Chapter_12.ipynb (renamed from Optical_Fiber_Communication_Principles_and_Practice/Chapter12.ipynb)8
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/Chapter_13.ipynb (renamed from Optical_Fiber_Communication_Principles_and_Practice/Chapter13.ipynb)0
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/Chapter_14.ipynb (renamed from Optical_Fiber_Communication_Principles_and_Practice/Chapter14.ipynb)0
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/Chapter_2.ipynb (renamed from Optical_Fiber_Communication_Principles_and_Practice/Chapter2.ipynb)0
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/Chapter_3.ipynb (renamed from Optical_Fiber_Communication_Principles_and_Practice/Chapter3_2.ipynb)6
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/Chapter_4.ipynb (renamed from Optical_Fiber_Communication_Principles_and_Practice/Chapter4.ipynb)0
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/Chapter_5.ipynb (renamed from Optical_Fiber_Communication_Principles_and_Practice/Chapter5_2.ipynb)2
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/Chapter_6.ipynb (renamed from Optical_Fiber_Communication_Principles_and_Practice/Chapter6.ipynb)0
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/Chapter_7.ipynb (renamed from Optical_Fiber_Communication_Principles_and_Practice/Chapter7.ipynb)0
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/Chapter_8.ipynb (renamed from Optical_Fiber_Communication_Principles_and_Practice/Chapter8_2.ipynb)6
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/Chapter_9.ipynb (renamed from Optical_Fiber_Communication_Principles_and_Practice/Chapter9.ipynb)0
-rw-r--r--Optical_Fiber_Communications_Principles_and_Practice/README.txt10
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_001.png (renamed from Optical_Fiber_Communication_Principles_and_Practice/screenshots/Selection_001.png)bin86216 -> 86216 bytes
-rw-r--r--Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_001_1.pngbin0 -> 86216 bytes
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_002.png (renamed from Optical_Fiber_Communication_Principles_and_Practice/screenshots/Selection_002.png)bin89779 -> 89779 bytes
-rw-r--r--Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_002_1.pngbin0 -> 89779 bytes
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel.png (renamed from Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes.png)bin10443 -> 10443 bytes
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_1.png (renamed from Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_1.png)bin10443 -> 10443 bytes
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes.png (renamed from Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_2.png)bin10443 -> 10443 bytes
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_1.png (renamed from Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_3.png)bin10443 -> 10443 bytes
-rw-r--r--[-rwxr-xr-x]Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_2.png (renamed from Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_4.png)bin10443 -> 10443 bytes
-rw-r--r--Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_3.pngbin0 -> 10443 bytes
-rw-r--r--Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_4.pngbin0 -> 10443 bytes
-rw-r--r--Optical_Fiber_Communications_Principles_and_Practice/techsupport0
-rw-r--r--Principles_Of_Fluid_Mechanics/README.txt10
-rw-r--r--Principles_Of_Fluid_Mechanics/ch1.ipynb275
-rw-r--r--Principles_Of_Fluid_Mechanics/ch10.ipynb200
-rw-r--r--Principles_Of_Fluid_Mechanics/ch11.ipynb284
-rw-r--r--Principles_Of_Fluid_Mechanics/ch2.ipynb823
-rw-r--r--Principles_Of_Fluid_Mechanics/ch3.ipynb101
-rw-r--r--Principles_Of_Fluid_Mechanics/ch4.ipynb346
-rw-r--r--Principles_Of_Fluid_Mechanics/ch5.ipynb1167
-rw-r--r--Principles_Of_Fluid_Mechanics/ch6.ipynb236
-rw-r--r--Principles_Of_Fluid_Mechanics/ch7.ipynb1067
-rw-r--r--Principles_Of_Fluid_Mechanics/ch8.ipynb532
-rw-r--r--Principles_Of_Fluid_Mechanics/ch9.ipynb152
-rw-r--r--Principles_Of_Fluid_Mechanics/screenshots/10TheBoundaryLayer.pngbin0 -> 145559 bytes
-rw-r--r--Principles_Of_Fluid_Mechanics/screenshots/1BasicConcepts.pngbin0 -> 145023 bytes
-rw-r--r--Principles_Of_Fluid_Mechanics/screenshots/9PotentialFlow.pngbin0 -> 147703 bytes
-rw-r--r--Principles_of_Data_structures_using_C_and_C++/README.txt10
-rw-r--r--Principles_of_Data_structures_using_C_and_C++/chapter2.ipynb136
-rw-r--r--Principles_of_Data_structures_using_C_and_C++/chapter3.ipynb950
-rw-r--r--Principles_of_Data_structures_using_C_and_C++/chapter4.ipynb818
-rw-r--r--Principles_of_Data_structures_using_C_and_C++/chapter5.ipynb2664
-rw-r--r--Principles_of_Data_structures_using_C_and_C++/chapter6.ipynb1682
-rw-r--r--Principles_of_Data_structures_using_C_and_C++/chapter7.ipynb688
-rw-r--r--Principles_of_Data_structures_using_C_and_C++/chapter8.ipynb1181
-rw-r--r--Principles_of_Data_structures_using_C_and_C++/chapter9.ipynb1894
-rw-r--r--Principles_of_Data_structures_using_C_and_C++/screenshots/graph.pngbin0 -> 44958 bytes
-rw-r--r--Principles_of_Data_structures_using_C_and_C++/screenshots/queue.pngbin0 -> 29210 bytes
-rw-r--r--Principles_of_Data_structures_using_C_and_C++/screenshots/stack.pngbin0 -> 48065 bytes
-rw-r--r--Programming_With_Java_A_Primer/README.txt10
-rw-r--r--Programming_With_Java_A_Primer/chapter10.ipynb133
-rw-r--r--Programming_With_Java_A_Primer/chapter11.ipynb151
-rw-r--r--Programming_With_Java_A_Primer/chapter12.ipynb231
-rw-r--r--Programming_With_Java_A_Primer/chapter13.ipynb267
-rw-r--r--Programming_With_Java_A_Primer/chapter16.ipynb426
-rw-r--r--Programming_With_Java_A_Primer/chapter17.ipynb61
-rw-r--r--Programming_With_Java_A_Primer/chapter18.ipynb372
-rw-r--r--Programming_With_Java_A_Primer/chapter3.ipynb178
-rw-r--r--Programming_With_Java_A_Primer/chapter4.ipynb191
-rw-r--r--Programming_With_Java_A_Primer/chapter5.ipynb325
-rw-r--r--Programming_With_Java_A_Primer/chapter6.ipynb245
-rw-r--r--Programming_With_Java_A_Primer/chapter7.ipynb309
-rw-r--r--Programming_With_Java_A_Primer/chapter8.ipynb319
-rw-r--r--Programming_With_Java_A_Primer/chapter9.ipynb475
-rw-r--r--Programming_With_Java_A_Primer/screenshots/chapter13.pngbin0 -> 45033 bytes
-rw-r--r--Programming_With_Java_A_Primer/screenshots/chapter18.pngbin0 -> 56599 bytes
-rw-r--r--Programming_With_Java_A_Primer/screenshots/chapter9.pngbin0 -> 51102 bytes
-rw-r--r--Water_and_Wastewater_Engineering/README.txt10
-rw-r--r--Water_and_Wastewater_Engineering/ch10.ipynb111
-rw-r--r--Water_and_Wastewater_Engineering/ch11.ipynb227
-rw-r--r--Water_and_Wastewater_Engineering/ch12.ipynb236
-rw-r--r--Water_and_Wastewater_Engineering/ch13.ipynb229
-rw-r--r--Water_and_Wastewater_Engineering/ch14.ipynb550
-rw-r--r--Water_and_Wastewater_Engineering/ch15.ipynb221
-rw-r--r--Water_and_Wastewater_Engineering/ch16.ipynb64
-rw-r--r--Water_and_Wastewater_Engineering/ch2.ipynb374
-rw-r--r--Water_and_Wastewater_Engineering/ch3.ipynb348
-rw-r--r--Water_and_Wastewater_Engineering/ch4.ipynb287
-rw-r--r--Water_and_Wastewater_Engineering/ch5.ipynb311
-rw-r--r--Water_and_Wastewater_Engineering/ch6.ipynb163
-rw-r--r--Water_and_Wastewater_Engineering/ch7.ipynb156
-rw-r--r--Water_and_Wastewater_Engineering/ch8.ipynb202
-rw-r--r--Water_and_Wastewater_Engineering/ch9.ipynb297
-rw-r--r--Water_and_Wastewater_Engineering/screenshots/16Machinery&Equipment.pngbin0 -> 100525 bytes
-rw-r--r--Water_and_Wastewater_Engineering/screenshots/2WaterSystems.pngbin0 -> 147103 bytes
-rw-r--r--Water_and_Wastewater_Engineering/screenshots/9GroundwaterFlow.pngbin0 -> 130091 bytes
203 files changed, 57361 insertions, 5354 deletions
diff --git a/Antennas_and_Wave_Propagation/README.txt b/Antennas_and_Wave_Propagation/README.txt
new file mode 100644
index 00000000..d97e6a43
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Koushik S
+Course: be
+College/Institute/Organization: Visvesvaraya Technological University
+Department/Designation: Electronics and Communication
+Book Title: Antennas and Wave Propagation
+Author: John. D. Kraus, Ronald J Marhefka and Ahmad S Khan
+Publisher: Tata McGraw Hill Education Private Limited, New Delhi - 110 008
+Year of publication: 2012
+Isbn: 987-0-07-067155-3
+Edition: Fourth Edition \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter11.ipynb b/Antennas_and_Wave_Propagation/chapter11.ipynb
new file mode 100644
index 00000000..5d30b647
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter11.ipynb
@@ -0,0 +1,100 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 11: Broadband and Frequency-Independent Antennas<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 11-1.1, Page number: 423<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "d = 4 #spacing (mm)\n",
+ "D = 100 #distance between the openings (mm)\n",
+ "\n",
+ "#Calculation\n",
+ "lambda_short = 10*d #Shortest wavelength (mm)\n",
+ "lambda_long = 2*D #Longest wavelength (mm)\n",
+ "bandwidth = lambda_long/lambda_short #Bandwidth (unitless)\n",
+ "\n",
+ "#Result\n",
+ "print \"The approximate bandwidth is\", bandwidth,\"to 1\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The approximate bandwidth is 5 to 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 11-7.1, Page number: 438<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import atan,pi,log\n",
+ "\n",
+ "#Variable declaration\n",
+ "gain_dbi = 7.0 #Gain (dBi)\n",
+ "bandwidth = 4 #Relative bandwidth (unitless)\n",
+ "s_lambda = 0.15 #Spacing (lambda)\n",
+ "k = 1.2 #Scale constant (unitless)\n",
+ "\n",
+ "#Calculation\n",
+ "alpha = atan((1-1/k)/(4*s_lambda))*180/pi #Apex angle (degrees)\n",
+ "n = round(log(bandwidth)/log(k)) #Number of elements(unitless)\n",
+ "n += 1\n",
+ "n += 2 #Number of elements considering conservative design (unitless)\n",
+ "\n",
+ "#Result\n",
+ "print \"The apex angle is\", round(alpha,1), \"degrees\"\n",
+ "print \"The number of elements is\", n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The apex angle is 15.5 degrees\n",
+ "The number of elements is 11.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter12.ipynb b/Antennas_and_Wave_Propagation/chapter12.ipynb
new file mode 100644
index 00000000..5d140dce
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter12.ipynb
@@ -0,0 +1,195 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 12: The Cylindrical Antenna and the Moment Method (MM)<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 12-12.1, Page number: 472<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi\n",
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "N = 3 #Piecewise sinusoidal dipole modes (unitless)\n",
+ "l = 1/10.0 #Dipole length (lambda)\n",
+ "z11_exact = 0.4935 - 3454j #Exact impedence vector(ohm)\n",
+ "z11_apprx = 0.4944 - 3426j #approximate impedence vector(ohm)\n",
+ "z12_exact = 0.4935 + 1753j #Exact impedence vector(ohm)\n",
+ "z12_apprx = 0.4945 + 1576j #approximate impedence vector(ohm)\n",
+ "z13_exact = 0.4935 + 129.9j #Exact impedence vector(ohm)\n",
+ "z13_apprx = 0.4885 + 132.2j #approximate impedence vector(ohm)\n",
+ "\n",
+ "#Calculations\n",
+ "N2 = N + 1 #Number of equal segments (unitless)\n",
+ "d = l/4 #Length of each segment (lambda)\n",
+ "Rmn = 20*(2*pi*d)**2 #Real part of elements of Z-matrix, Zmn (VA)\n",
+ "zmat_apprx = np.array([[(z11_apprx+z13_apprx), z12_apprx],\n",
+ " [2*z12_apprx, z11_apprx]])\n",
+ " #Z(impedence) matrix (unitless)\n",
+ "vmat = np.array([0,1]) #Voltage matrix (unitless)\n",
+ "i1,i2 = np.linalg.solve(zmat_apprx,vmat) #Current matrix (unitless)\n",
+ "i_ratio = i2/i1 #Current ratio (unitless)\n",
+ "zin = vmat[1]/i2 #Input impedence (ohm)\n",
+ "\n",
+ "\n",
+ "zmat_exact = np.array([[(z11_exact+z13_exact), z12_exact],\n",
+ " [2*z12_exact, z11_exact]])\n",
+ "i1_e,i2_e = np.linalg.solve(zmat_exact,vmat) #Current matrix (unitless)\n",
+ "i_ratio_exact = i2_e/i1_e #Current ratio (unitless)\n",
+ "zin_exact = vmat[1]/i2_e #Input impedence (ohm)\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print \"The current ratio is \", np.around(i_ratio,4)\n",
+ "print \"This is nearly equal to 1.9,\" \\\n",
+ " \"indicating a nearly triangular current distribution\"\n",
+ "print \"The input impdence is \", np.around(zin,3), \"ohm using approximate values\"\n",
+ "print \"The input impedence is \", np.around(zin_exact,3), \"ohm using exact values\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The current ratio is (2.09+0.0013j)\n",
+ "This is nearly equal to 1.9,indicating a nearly triangular current distribution\n",
+ "The input impdence is (1.891-1917.848j) ohm using approximate values\n",
+ "The input impedence is (2.083-1605.074j) ohm using exact values\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 12-12.2, Page number: 473<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import tan, pi\n",
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "z_load = 2.083 + 1605j #conjugate matched load (ohm)\n",
+ "e0 = 1.0 #Electric field magnitude (unitless)\n",
+ "l = 1/10.0 #length of dipole (lambda)\n",
+ "imag = 0+1j #Imaginary number \n",
+ "\n",
+ "z11_exact = 0.4935 - 3454j #Exact impedence vector(ohm)\n",
+ "z11_apprx = 0.4944 - 3426j #approximate impedence vector(ohm)\n",
+ "z12_exact = 0.4935 + 1753j #Exact impedence vector(ohm)\n",
+ "z12_apprx = 0.4945 + 1576j #approximate impedence vector(ohm)\n",
+ "z13_exact = 0.4935 + 129.9j #Exact impedence vector(ohm)\n",
+ "z13_apprx = 0.4885 + 132.2j #approximate impedence vector(ohm)\n",
+ "\n",
+ "#Calculation\n",
+ "d = l/4 #Length of each segment (lambda)\n",
+ "vm = (2*e0/(2*pi))*tan(2*pi*d/2) #Voltage vector (VA)\n",
+ "z22 = z11_exact + z_load #Impedence matrix for loaded dipole (VA)\n",
+ "zmat_exact = np.array([[(z11_exact+z13_exact), z12_exact],\n",
+ " [2*z12_exact, z22]])\n",
+ " #Z(impedence) matrix (unitless)\n",
+ "vmat = np.array([vm,vm]) #Voltage matrix (unitless)\n",
+ "i1,i2 = np.linalg.solve(zmat_exact,vmat) #Current matrix (unitless)\n",
+ "i3 = i1 #Current vector (unitless)\n",
+ "\n",
+ "e_zn = (60*tan(2*pi*d/2))*imag #Free space electric field (V/m)\n",
+ "\n",
+ "e_s = i1*e_zn + i2*e_zn + i3*e_zn #Scattered field (V/m)\n",
+ "\n",
+ "sigma = 4*pi*(abs(e_s)**2)/(abs(e0)**2) #Radar Cross section (lambda**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"The radar cross section using exact values of Z matrix is\", round(sigma,4),\\\n",
+ " \"lambda^2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The radar cross section using exact values of Z matrix is 0.1805 lambda^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 12-12.3, Page number: 475<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "z11_exact = 2-1921j #Exact impedence vector (ohm)\n",
+ "z12_exact = 1.9971-325.1j #Exact impedence vector (ohm)\n",
+ "\n",
+ "z11_apprx = 1.9739-1992j #Approximate impedence vector (ohm)\n",
+ "z12_apprx = 1.9739-232.8j #Approximate impedence vector (ohm)\n",
+ "\n",
+ "vmat = np.array([1,0])\n",
+ "\n",
+ "#Calculations\n",
+ "zmat_exact = np.array([[z11_apprx, z12_apprx],\n",
+ " [z12_apprx, z11_apprx]]) \n",
+ " #Impedence matrix (unitless)\n",
+ "i1,i2 = np.linalg.solve(zmat_exact,vmat)\n",
+ " #Current matrix (unitless)\n",
+ "zin = 1/i1\n",
+ "\n",
+ "#Result\n",
+ "print \"The input impedence for order N = 2 is\", np.around(zin,3), \"ohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The input impedence for order N = 2 is (1.539-1964.795j) ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter15.ipynb b/Antennas_and_Wave_Propagation/chapter15.ipynb
new file mode 100644
index 00000000..223fe26f
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter15.ipynb
@@ -0,0 +1,830 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 15: Antennas for Special Applications<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 15-2.1, Page number 524<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "freq = 100e3 #Frequency (Hz)\n",
+ "height = 150 #Height of antenna(m)\n",
+ "RL = 2 #Loss resistance (ohm)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/freq #Wavelength (m)\n",
+ "hp = height/wave_lt #Antenna (physical) height (lambda)\n",
+ "he = hp/2 #Effective height (lambda)\n",
+ "\n",
+ "Rr = 400*(hp**2) #Radiation resistance (ohm)\n",
+ "\n",
+ "R_E = Rr/(Rr+RL) #Radiation efficiency (unitless)\n",
+ "\n",
+ "#Results\n",
+ "print \"The Effective height of the antenna is \", he, \"lambda\"\n",
+ "print \"The Radiation resistance for 150m vertical radiator is\", Rr, \"ohm\"\n",
+ "print \"The radiation efficiency is\", round(R_E,2), \"or\", round(R_E*100,2), \"%\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Effective height of the antenna is 0.025 lambda\n",
+ "The Radiation resistance for 150m vertical radiator is 1.0 ohm\n",
+ "The radiation efficiency is 0.33 or 33.33 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 15-4.1, Page number: 529</h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "%pylab inline\n",
+ "import numpy as np\n",
+ "from math import pi, sin, sqrt, radians\n",
+ "from pylab import *\n",
+ "from cmath import sqrt\n",
+ "import matplotlib.pyplot as plt\n",
+ "\n",
+ "#Variable declaration\n",
+ "eps_r1 = 16 #Real part of relative permittivity of ground (unitless)\n",
+ "sigma = 1e-2 #conductivity of ground (mho per meter)\n",
+ "eps_0 = 8.85e-12 #Air permittivity (F/m)\n",
+ "f1 = 1e6 #Frequency (Hz)\n",
+ "f2 = 100e6 #Frequency (Hz)\n",
+ "\n",
+ "#Calculation\n",
+ "eps_r11 = sigma/(2*pi*f1*eps_0) #Loss part of relative permittivity for f1 (unitless)\n",
+ "eps_r11_2 = sigma/(2*pi*f2*eps_0) #Loss part of relative permittivity for f2 (unitless)\n",
+ "\n",
+ "eps_ra = eps_r1 -(1j)*eps_r11 #Relative permittivity for f1 (unitless)\n",
+ "eps_rb = eps_r1 -(1j)*eps_r11_2 #Relative permittivity for f2 (unitless)\n",
+ "\n",
+ "n1 = sqrt(eps_ra) #Refractive index for f1 (unitless)\n",
+ "n2 = sqrt(eps_rb) #Refractive index for f2 (unitless)\n",
+ "E_perp1 = [1 + (abs((sin(alpha) - n1)/(sin(alpha)+n1))*exp(1j*(2*pi*sin(alpha) + angle((sin(alpha) - n1)/(sin(alpha)+n1))))) \\\n",
+ " for alpha in arange(0,pi/2,pi/180)] \n",
+ "\n",
+ "E_perp2 = [1 + (abs((sin(alpha) - n2)/(sin(alpha)+n2))*exp(1j*(2*pi*sin(alpha) + angle((sin(alpha) - n2)/(sin(alpha)+n2))))) \\\n",
+ " for alpha in arange(0,pi/2,pi/180)]\n",
+ "\n",
+ "E_perp1_rel = E_perp1/max(E_perp1) #Relative electric field for f1 (unitless)\n",
+ "\n",
+ "E_perp2_rel = E_perp2/max(E_perp2) #Relative electric field for f2 (unitless)\n",
+ "\n",
+ "theta = arange(0,pi/2,pi/180)\n",
+ "\n",
+ "polar(theta,E_perp1_rel,'g',label=\"1MHz\")\n",
+ "polar(theta,E_perp2_rel,'b--',label=\"100MHz\")\n",
+ "legend(loc=\"upper left\")\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print \"The loss parameter for 1MHz is \", round(eps_r11)\n",
+ "print \"The loss parameter for 100MHz is \", round(eps_r11_2,2)\n",
+ "print \"The relative permittivity for 1MHz is \", np.around(eps_ra)\n",
+ "print \"The relative permittivity for 100MHz is \", np.around(eps_rb,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The loss parameter for 1MHz is 180.0\n",
+ "The loss parameter for 100MHz is 1.8\n",
+ "The relative permittivity for 1MHz is (16-180j)\n",
+ "The relative permittivity for 100MHz is (16-1.8j)\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "/usr/lib/python2.7/dist-packages/numpy/core/numeric.py:460: ComplexWarning: Casting complex values to real discards the imaginary part\n",
+ " return array(a, dtype, copy=False, order=order)\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "iVBORw0KGgoAAAANSUhEUgAAARMAAAENCAYAAAAsdYFTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzsnXdcU+f3xz9hCKiAgqAMUQERF2jddVJ33VpbV92tteNb\n26+t3a11FrXWaq17gbMuhuAWEVcVEBEQEBkiO8wECCQ5vz/4kS+RlYT7JAHzfr3y0pv73HNOLsm5\nzzjPOTwiIujQoUNHA9HTtAE6dOhoGuiciQ4dOjhB50x06NDBCTpnokOHDk7QORMdOnRwgs6Z6NCh\ngxN0zkRHjWzbtg09e/ZEjx49sG3bNgBAbm4uRo8eDRcXF4wZMwb5+fmy9osXL0avXr1w4cIFTZms\nQ8PonImOajx58gT79u3DgwcPEBERAX9/fyQkJGDjxo0YPXo04uLiMHLkSGzcuFHW3sHBAaGhoThy\n5IiGrdehKXTOREc1nj59igEDBsDY2Bj6+voYPnw4zpw5A19fXyxYsAAAsGDBApw/fx4AYGBgAKFQ\nCJFIpEmzdWgYnTPRUY0ePXrg1q1byM3NRXFxMQICApCamorMzEy0bdsWANC2bVtkZmYCAFxdXSEW\nizF8+HB88sknmjRdhwYx0LQBOrQPV1dXrFq1CmPGjEGLFi3Qq1cv6Ovry7Xh8Xjg8Xiy461bt6rb\nTB1ahq5noqNGFi9ejIcPH+LmzZto3bo1XFxc0LZtW2RkZAAA0tP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zC44mDDG7IKDCWPMLjiYMMbs4n+vNvwywIT7aAAAAABJRU5ErkJggg==\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x7f9dca6680d0>"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 15-12.1, Page number: 541</h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "%pylab inline\n",
+ "from math import pi,acos,sqrt,log10,atan\n",
+ "import cmath\n",
+ "import numpy as np\n",
+ "from pylab import *\n",
+ "\n",
+ "#Variable declaration\n",
+ "f = 60e6 #Frequency(Hz)\n",
+ "dep = 20 #Depth of antenna location (m)\n",
+ "sigma = 1.33e-2 #Conductivity (mho per m)\n",
+ "eps0 = 8.85e-12 #Air Permittivity (F/m)\n",
+ "epr1 = 80 #Real part of relative permittivity (unitless)\n",
+ "alphat = 10 #Elevation angle (degrees)\n",
+ "cl = 1 #Circumference (lambda)\n",
+ "pitch = 12.5 #Pitch angle (degrees)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "\n",
+ "dir_gb = 3 #Directivity of George Brown turnstile (unitless)\n",
+ "Aer_gb = 6 #Effective aperture of George Brown turnstile (unitless)\n",
+ "r = 1e3 #Distance between transmitter and receiver (m)\n",
+ "Pt = 100 #Transmitted power (W)\n",
+ "\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "epr11 = sigma/(eps0*2*pi*f) #Loss term of relative permittivity (unitless)\n",
+ "epr = epr1 + 1j*epr11 #Relative permittivity (unitless)\n",
+ "alphac = acos(sqrt(1/epr1)) #Critical angle (degrees)\n",
+ "alpha = acos(cos(radians(alphat))/sqrt(epr1)) #Angle of incidence (degrees)\n",
+ "\n",
+ "n1=12 #Number of turns\n",
+ "rad = cl/(2*pi) #Radius of loop (lambda)\n",
+ "sl = tan(radians(12.5))\n",
+ "hpbw1 = 52/(cl*sqrt(n1*sl)) #Half power beamwidth for 12 turns(degrees)\n",
+ "dir1 = 12*(cl**2)*n1*sl #Directivity for 12 turns (unitless)\n",
+ "n2 = n1*2 #Number of turns\n",
+ "hpbw2 = 52/(cl*sqrt(n2*sl)) #Half power beamwidth for 24 turns(degrees)\n",
+ "dir2 = 12*(cl**2)*n2*sl #Directivity for 24 turns (unitless)\n",
+ "num = 20 #Number of turns chosen\n",
+ "\n",
+ "p_perp = [(sin(theta)-cmath.sqrt(epr - cos(theta)**2))/(sin(theta)+cmath.sqrt(epr - cos(theta)**2)) \\\n",
+ " for theta in arange(0,pi,pi/180)]\n",
+ " #Reflection coefficient (unitless)\n",
+ "p_pall = [(epr*sin(theta)-cmath.sqrt(epr - cos(theta)**2))/(epr*sin(theta)+cmath.sqrt(epr - cos(theta)**2)) \\\n",
+ " for theta in arange(0,pi,pi/180)]\n",
+ " #Reflection coefficient (unitless)\n",
+ "\n",
+ "Sr = 0.5*(np.absolute(p_perp)**2 + np.absolute(p_pall)**2) #Relative power density reflected (unitless)\n",
+ "St = 1 - Sr #Relative power density transmitted (unitless)\n",
+ " \n",
+ "theta = arange(0,pi,pi/180)\n",
+ "subplot(1,2,1)\n",
+ "plot(theta,St)\n",
+ "xlim([0,pi/2])\n",
+ "title(\"Relative power vs Elevation angle\")\n",
+ "\n",
+ "\n",
+ "subplot(1,2,2, polar=True)\n",
+ "plot(theta,St)\n",
+ "title(\"Pattern of transmission\")\n",
+ "\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "diam = wave_lt/(sqrt(epr1)*pi) #Submerged helix diameter (m)\n",
+ "att_cons = (pi*epr11)/(wave_lt*sqrt(epr1)) #Attenuation constant for water (Np/m)\n",
+ "att_d = 20*log10(exp(-att_cons*dep)) #Attenuation in the water path (dB)\n",
+ "Dir = 12*(cl**2)*num*sl #Directivity for 20 turn helix (unitless)\n",
+ "Ae = Dir*(wave_lt**2)/(4*pi) #Effective aperture (m^2)\n",
+ "\n",
+ "Pr = Pt*Ae*dir_gb/((r**2)*(wave_lt**2)) #Received power(W)\n",
+ "\n",
+ "St = np.around(St,2)\n",
+ "loss_inter = 10*log10(St[10]) #Loss at the interface for alpha = 83.68 (dB)\n",
+ "tot_loss = round(abs(att_d + loss_inter)) #Total loss (dB)\n",
+ "Pr_act = Pr/(10**(tot_loss/10)) #Net Actual received power (W)\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print \"Half power beamwidth for 12 turns is \", round(hpbw1), \"degrees\"\n",
+ "print \"Directivity for 12 turns is \", round(dir1,1)\n",
+ "print \"Half power beamwidth for 24 turns is \", round(hpbw2), \"degrees\"\n",
+ "print \"Directivity for 24 turns is \", round(dir2,1)\n",
+ "print \"A helix of \", num, \"turns is chosen for reasonable compromise\"\n",
+ "print \"The signal level at the distance of 1km is\", round(Pr_act,10), \"W\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Half power beamwidth for 12 turns is 32.0 degrees\n",
+ "Directivity for 12 turns is 31.9\n",
+ "Half power beamwidth for 24 turns is 23.0 degrees\n",
+ "Directivity for 24 turns is 63.8\n",
+ "A helix of 20 turns is chosen for reasonable compromise\n",
+ "The signal level at the distance of 1km is 8e-09 W\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "iVBORw0KGgoAAAANSUhEUgAAAYMAAAEKCAYAAADw2zkCAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzsnXdYFFf3x79LU5HeBQRUjKAoIIhKRLBrEpTEblQUNSZq\nonlDLPG1JtZoivqq+LObiMYWrMQKGlGqYhdF6UW61IXdPb8/JkxYWNjCAqvO53nm2b0zt5yZnZ0z\n9557z+EREYGDg4OD451GraUF4ODg4OBoeThlwMHBwcHBKQMODg4ODk4ZcHBwcHCAUwYcHBwcHOCU\nAQcHBwcHmlgZ+Pj4YM+ePQqVTUlJga6uLriZr03DypUrMWXKlGZv9/fff8ew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5r7ty5OHv2LJydnaFSqfDFF1+02baOGGuSYHvnX2y7xJ5/xpg8su8mksqQk9SkfBkcOHAAMTEx\nOHz4sOx2zZ8/Hx999BEUCgWI6KY2Sq2vsbERqamp2L9/P2pqajB27FiMGTMGQ4YMkVzXhx9+CH9/\nfyQkJODixYuYPHky0tLSYGdn12HZ1og5/1J0dP7FkHL+GWPydFowcHFxQV5enrCdl5cndJO0tU9+\nfj5cXFxk1QUAp0+fxty5cxEfH99mN4SYuk6cOCFMnCstLcXu3bthbW2NyMhIWfUNGjQIjo6OsLW1\nha2tLcaPH4+0tLSbgoGYupKSkrBo0SIAgIeHBwYPHozz588jKCio1dfbHrHnXywx518MKeefMSZT\nZw1ONDY2kru7O2VnZ1N9fX2HA8jJycltDjqKqSs3N5c8PDwoOTlZ73a19PTTT9PmzZv1qi8jI4Mm\nTpxIarWarl+/Tr6+vnT27FlZdf3zn/+kxYsXExFRcXExubi4UFlZWZvty87OFjWA3N75F1OX2PMv\npq6WOjr/jDF5Ou3KwJCT1MTU9f7776O8vFzoZ7a2tsaxY8dk1WXo1+nl5YUpU6bAz88PFhYWmDt3\nLry9vWXVtXDhQjzzzDNQqVTQarX4+OOP0bdv31bbNnv2bBw8eBClpaUYNGgQ3nvvPTQ2Ngp1SZkk\n2FFdYs+/mLoYY8bHk84YY4zxspeMMcY4GDDGGAMHA8YYY+BgwBhjDBwMGGOMgYMBY4wxcDBgjDEG\nDgaMMcYA/B/PBcUPbKxwhwAAAABJRU5ErkJggg==\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x7fdf86780510>"
+ ]
+ }
+ ],
+ "prompt_number": 43
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 15-13.1, Page number: 546<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import atan,pi\n",
+ "\n",
+ "#Variable declaration\n",
+ "freq = 3e9 #Frequency (Hz)\n",
+ "Re_Zc = 14.4e-3 #Real part of intrinsic impedence of copper (ohm)\n",
+ "Zd = 377 #Intrinsic impedence of air (ohm)\n",
+ "\n",
+ "#Calculation\n",
+ "tau = atan(Re_Zc/Zd)*180/pi #Tilt angle (degrees)\n",
+ "\n",
+ "#Result\n",
+ "print \"The tilt angle is\", round(tau,4), \"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The tilt angle is 0.0022 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 88
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 15-13.2, Page number: 546<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import atan,pi,sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "freq = 3e9 #Frequency (Hz)\n",
+ "eps_r = 80 #Relative permittivity of water (unitless)\n",
+ "\n",
+ "#Calculation\n",
+ "tau = atan(1/sqrt(eps_r))*180/pi #Forward Tilt angle (degrees)\n",
+ "\n",
+ "#Result\n",
+ "print \"The forward tilt angle is\", round(tau,1), \"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The forward tilt angle is 6.4 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 89
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 15-13.3, Page number: 550<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import acos,pi\n",
+ "\n",
+ "#Variable declaration\n",
+ "lambda_g = 1.5 #Wavelength in guide (lambda)\n",
+ "m = -1 #Mode number\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "phi = acos((1/lambda_g)+m)*180/pi #Forward Tilt angle (degrees)\n",
+ "\n",
+ "#Result\n",
+ "print \"The beam angle is\", round(phi,1), \"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The beam angle is 109.5 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 90
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 15-14.1, Page number:552<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi, log10, sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "freq = 4e9 #Frequency (Hz)\n",
+ "T_sys = 100 #System Temperature (K)\n",
+ "S_N = 20 #Signal to Noise ratio (dB)\n",
+ "bandwidth = 30e6 #Bandwidth (Hz)\n",
+ "P_trans = 5 #Satellite transponder power (W)\n",
+ "dia = 2 #Satellite parabolic dish diameter (m)\n",
+ "sat_spacing = 2 #Spacing between satellites (degrees)\n",
+ "r = 36000e3 #Downlink distance (m)\n",
+ "k = 1.38e-23 #Boltzmann's constant (J/K)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "\n",
+ "#Calculation\n",
+ "wave_lt = c/freq\n",
+ "s_n = (wave_lt**2)/(16*(pi**2)*(r**2)*k*T_sys*bandwidth) \n",
+ "s_n = 10*log10(s_n) #Signal to noise ratio for isotropic antennas (dB)\n",
+ "\n",
+ "Ae = 0.5*pi*(dia**2)/4 #Effective Aperture (m^2)\n",
+ "Gs = 4*pi*Ae/(wave_lt**2) \n",
+ "Gs = 10*log10(Gs) #Antenna Gain (dB)\n",
+ "\n",
+ "Ge = 20 - s_n - Gs - 10*log10(P_trans) #Required earth station antenna gain(dB)\n",
+ "Ae_e = (10**(Ge/10))*(wave_lt**2)/(4*pi) \n",
+ " #Required earth station effective aperture (m^2)\n",
+ "Ap = Ae_e*2 #Required Physical aperture (m^2)\n",
+ "\n",
+ "De = 2*sqrt(Ap/pi) #Required diameter of earth-station antenna(m)\n",
+ "hpbw = 65/(De/wave_lt) #Half power beam width (degree)\n",
+ "bwfn = 145/(De/wave_lt) #Beamwidth between first null (degree)\n",
+ "\n",
+ "#Results\n",
+ "print \"The required parabolic dish diameter of earth station antenna is\"\\\n",
+ " , round(De,1), \"m\"\n",
+ "print \"The Half power beamwidth is\", round(hpbw,1), \"degrees\"\n",
+ "print \"The beamwidth between first null is\", round(bwfn,1), \"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The required parabolic dish diameter of earth station antenna is 3.1 m\n",
+ "The Half power beamwidth is 1.6 degrees\n",
+ "The beamwidth between first null is 3.5 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 93
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 15-20.1, Page number: 568<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import *\n",
+ "\n",
+ "#Variable declaration\n",
+ "Tr = 45 #Satellite receiver temperature (K)\n",
+ "rcp_gain = 6 #Right circularly polarized antenna gain (dBi)\n",
+ "rcp_quad_gain = 3 #RCP gain of quadrifilar helix antenna (dBi)\n",
+ "bandwidth = 9.6e3 #Bandwidth (Hz)\n",
+ "snr = 10 #Required Signal-to-Noise ratio (dB)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "f = 1.65e9 #Frequency (Hz)\n",
+ "r = 780e3 #Distance to the satellite (m)\n",
+ "Ta = 300 #Antenna temperature (K)\n",
+ "k = 1.4e-23 #Boltzmann's constant (J/K)\n",
+ "theta = 10 #Zenith angle (degree)\n",
+ "Tr_handheld = 75 #Hand held receiver temperature (K)\n",
+ "Tsky = 6 #Sky Temperature (K)\n",
+ "theta_horz = 80 #Zenith angle for horizontal dipole (degree)\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "Ld = (wave_lt/(4*pi*r))**2 #Spatial loss factor(unitless)\n",
+ "Ld_db = 10*log10(Ld) #Spatial loss factor(dB)\n",
+ "\n",
+ "Tsys_up = Ta + Tr #Satellite system temperature (K)\n",
+ "N = k*Tsys_up*bandwidth #Noise power(W)\n",
+ "N_db = 10*log10(N) #Noise power (dB)\n",
+ "\n",
+ "E_vert = cos(pi*cos(theta*pi/180)/2)/sin(theta*pi/180)\n",
+ " #Pattern factor for vertical lambda/2 dipole (unitless)\n",
+ "E_vert_db = 20*log10(E_vert)\n",
+ "\n",
+ "Pt_vert_up = snr - (2.15 + round(E_vert_db,1) - 3) - \\\n",
+ " rcp_gain + round(N_db) - round(Ld_db)\n",
+ " #Uplink power for vertical lambda/2 antenna (dB)\n",
+ "Pt_vert_up = 10**(Pt_vert_up/10) \n",
+ " #Uplink power for vertical lambda/2 antenna (W)\n",
+ "\n",
+ "Ta_down = 0.5*(Ta)+0.5*(Tsky)+3 #Downlink antenna temperature (K)\n",
+ "Tsys_down = Ta_down + Tr_handheld #System temperature(K)\n",
+ "N_down = k*Tsys_down*bandwidth #Noise power (W)\n",
+ "N_down_db = 10*log10(N_down) #Noise power (dB)\n",
+ "Pt_vert_down = snr -(2.15+ round(E_vert_db,1) - 3) - \\\n",
+ " rcp_gain + round(N_down_db) - round(Ld_db)\n",
+ " #Downlink power for vertical lambda/2 antenna (dB)\n",
+ "Pt_vert_down = 10**(Pt_vert_down/10)\n",
+ " #Downlink power for vertical lambda/2 antenna (W)\n",
+ "\n",
+ "E_horz = cos(pi*cos(theta_horz*pi/180)/2)/sin(theta_horz*pi/180)\n",
+ " #Pattern factor for horizontal lambda/2 dipole (unitless)\n",
+ "E_horz_db = round(20*log10(E_horz),1)\n",
+ "Pt_horz_up = snr -(2.15 + E_horz_db - 3) - \\\n",
+ " rcp_gain + round(N_db) - round(Ld_db)\n",
+ " #Uplink power for horizonal lambda/2 dipole (dB)\n",
+ "Pt_horz_up = 10**(Pt_horz_up/10)\n",
+ " #Uplink power for horizonal lambda/2 dipole (W)\n",
+ "\n",
+ "Pt_horz_down = snr -(2.15 + E_horz_db - 3) - \\\n",
+ " rcp_gain + round(N_down_db) - round(Ld_db)\n",
+ " #Downlink power for horizonal lambda/2 dipole (dB)\n",
+ "Pt_horz_down = 10**(Pt_horz_down/10)\n",
+ " #Downlink power for horizonal lambda/2 dipole (W)\n",
+ "\n",
+ "Pt_quad_up = snr -(rcp_quad_gain + E_horz_db) - \\\n",
+ " rcp_gain + round(N_db) - round(Ld_db)\n",
+ " #Uplink power for RCP quadrifilar helix antenna (dB)\n",
+ "Pt_quad_up = 10**(Pt_quad_up/10)\n",
+ " #Uplink power for RCP quadrifilar helix antenna (W)\n",
+ "\n",
+ "Ta_quad = 0.85*(Tsky) + 0.15*(Ta) #Downlink antenna temperature (K)\n",
+ "Tsys_quad = Ta_quad + Tr_handheld #System temperature(K)\n",
+ "N_quad = k*Tsys_quad*bandwidth #Noise power (W)\n",
+ "N_quad_db = 10*log10(N_quad) #Noise power (dB)\n",
+ "\n",
+ "Pt_quad_down = snr -(rcp_quad_gain + E_horz_db) - \\\n",
+ " rcp_gain + round(N_quad_db) - round(Ld_db)\n",
+ " #Downlink power for RCP quadrifilar helix antenna (dB)\n",
+ "Pt_quad_down = 10**(Pt_quad_down/10)\n",
+ " #Downlink power for RCP quadrifilar helix antenna (W)\n",
+ "\n",
+ "#Results\n",
+ "print \"The Uplink power for vertical lambda/2 dipole is\", round(Pt_vert_up,1),\"W\"\n",
+ "print \"The Uplink power for horizontal lambda/2 dipole is\", round(Pt_horz_up,3),\"W\"\n",
+ "print \"The Uplink power for RCP quadrifilar helix antenna is\", round(Pt_quad_up,3),\"W\"\n",
+ "\n",
+ "print \"The downlink power for vertical lambda/2 dipole is\", round(Pt_vert_down,1),\"W\"\n",
+ "print \"The downlink power for horizontal lambda/2 dipole is\", round(Pt_horz_down,3),\"W\"\n",
+ "print \"The downlink power for RCP quadrifilar helix antenna is\",\\\n",
+ " round(Pt_quad_down,3),\"W\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Uplink power for vertical lambda/2 dipole is 25.4 W\n",
+ "The Uplink power for horizontal lambda/2 dipole is 0.507 W\n",
+ "The Uplink power for RCP quadrifilar helix antenna is 0.209 W\n",
+ "The downlink power for vertical lambda/2 dipole is 16.0 W\n",
+ "The downlink power for horizontal lambda/2 dipole is 0.32 W\n",
+ "The downlink power for RCP quadrifilar helix antenna is 0.066 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 94
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 15-20.2, Page number: 571<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import *\n",
+ "\n",
+ "#Variable declaration\n",
+ "f = 1.6e9 #Frequency (Hz)\n",
+ "r = 1400e3 #Height (m)\n",
+ "r_sep = 3500e3 #Height for 10 degree seperation (m)\n",
+ "c = 3e8 #Speed of light(m/s)\n",
+ "Ta = 300 #Satellite antenna temperature (K)\n",
+ "Tr = 45 #Satellite receiver temperature (K)\n",
+ "k = 1.3e-23 #Boltzmann's constant (J/K)\n",
+ "bandwidth = 9.6e3 #Bandwidth (Hz)\n",
+ "snr = 6 #Signal to noise ratio (dB)\n",
+ "rcp_gain = 3 #Helix gain(dB)\n",
+ "beam_angle = 25 #RCP spot beam (degree)\n",
+ "Tsky = 6 #Sky Temperature (K)\n",
+ "Tr_handheld = 75 #Hand held receiver temperature (K)\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "Ld = (wave_lt/(4*pi*r))**2 \n",
+ "Ld = 10*log10(Ld) #Propagation loss factor (dB)\n",
+ "sat_gain = 40000/(beam_angle**2)\n",
+ "sat_gain = 10*log10(sat_gain) #Satellite gain (dB)\n",
+ "\n",
+ "Tsys = Ta+Tr #System temperature (K)\n",
+ "N = k*Tsys*bandwidth #Noise power (W)\n",
+ "N_db = 10*log10(N) #Noise power (dB)\n",
+ "\n",
+ "Pt_up = snr - (rcp_gain) - (sat_gain) + N_db - Ld #Uplink power (dB)\n",
+ "Pt_up = 10**(Pt_up/10) #Uplink power (W)\n",
+ "\n",
+ "Ta_quad = 0.85*(Tsky) + 0.15*(Ta) #Downlink antenna temperature (K)\n",
+ "Tsys_quad = Ta_quad + Tr_handheld #System temperature(K)\n",
+ "N_quad = k*Tsys_quad*bandwidth #Noise power (W)\n",
+ "N_quad_db = 10*log10(N_quad) #Noise power (dB)\n",
+ "\n",
+ "Pt_down = snr - (rcp_gain) - (sat_gain) + round(N_quad_db) - round(Ld) \n",
+ " #Downlink power (dB)\n",
+ "Pt_down = 10**(Pt_down/10) #Downlink power (W)\n",
+ "\n",
+ "Ld_sep = (wave_lt/(4*pi*r_sep))**2 \n",
+ "Ld_sep = 10*log10(Ld_sep) #Propagation loss factor(dB)\n",
+ "\n",
+ "Pt_sep = snr - (rcp_gain) - sat_gain + ceil(N_db) - round(Ld_sep)\n",
+ " #Uplink power (dB)\n",
+ "Pt_sep = 10**(Pt_sep/10) #Uplink power (W)\n",
+ "\n",
+ "#Results\n",
+ "print \"The Satellite gain is\", round(sat_gain,1),\"dB\"\n",
+ "print \"The Uplink power required is\", round(Pt_up,3),\"W\"\n",
+ "print \"The Downlink power required is\",round(Pt_down,4),\"W\"\n",
+ "print \"The uplink power required for 10 deg. from horizon is\",round(Pt_sep,3),\"W\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Satellite gain is 18.1 dB\n",
+ "The Uplink power required is 0.012 W\n",
+ "The Downlink power required is 0.0039 W\n",
+ "The uplink power required for 10 deg. from horizon is 0.078 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 97
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 15-20.3, Page number: 572<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import *\n",
+ "\n",
+ "#Variable declaration\n",
+ "f = 30e9 #Frequency (Hz)\n",
+ "Tr = 300 #Receiver temperature (K)\n",
+ "Ta = 275 #Satellite antenna temperature (K)\n",
+ "h = 1400e3 #Height (m)\n",
+ "bw = 9.6e3 #Bandwidth per channel (Hz)\n",
+ "rcp_gain = 10 #RCP satellite gain (dBi)\n",
+ "rain_att = 10 #Rain attenuation (dB)\n",
+ "k = 1.4e-23 #Boltzmann's constant (J/K)\n",
+ "snr = 10 #Required SNR (dB)\n",
+ "ap_eff = 0.7 #Aperture efficiency (unitless)\n",
+ "Ta_2 = 10 #Dish antenna temperature (K)\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "Ld = (wave_lt/(4*pi*r))**2 #Spatial loss factor(unitless)\n",
+ "Ld_db = 10*log10(Ld) #Spatial loss factor(dB)\n",
+ "Tsys = Ta+Tr #System temperature (K)\n",
+ "\n",
+ "N = k*Tsys*bw #Propagation loss due to rain (W)\n",
+ "N = 10*log10(N) #Propagation loss due to rain (dB)\n",
+ "\n",
+ "Dr = -rcp_gain + snr - Ld_db + N + rain_att #Antenna gain (dB)\n",
+ "Dr = 10**(Dr/10) #Antenna gain (unitless)\n",
+ "\n",
+ "Dr_req = Dr/ap_eff #Required antenna gain (unitless)\n",
+ "Dr_req_db = 10*log10(Dr_req) #Required antenna gain (dB)\n",
+ "\n",
+ "dish_dia = 2*wave_lt*sqrt(Dr_req/28) #Required diameter of dish (m)\n",
+ "\n",
+ "hpbw = sqrt(40000/Dr_req) #Half power beam width (degrees)\n",
+ "\n",
+ "Tsys2 = Ta_2 + Tr #System temperature(K)\n",
+ "N2 = k*Tsys2*bw #Propagation loss due to rain(W)\n",
+ "N2 = 10*log10(N2) #Propagation loss due to rain(dB)\n",
+ "\n",
+ "Pt_db = snr - Dr_req_db - rcp_gain + N2 - Ld_db + rain_att \n",
+ " #Transmitted power (dB)\n",
+ "Pt = 10**(Pt_db/10)\n",
+ "\n",
+ "#Results\n",
+ "print \"The uplink antenna gain required is\", round(Dr_req_db,0), \"dB\"\n",
+ "print \"The required dish size\", round(dish_dia,3), \"m\"\n",
+ "print \"The HPBW is\", round(hpbw,1), \"degrees\"\n",
+ "print \"The downlink satellite power required is\", round(Pt,3), \"W\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The uplink antenna gain required is 35.0 dB\n",
+ "The required dish size 0.221 m\n",
+ "The HPBW is 3.4 degrees\n",
+ "The downlink satellite power required is 0.377 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 102
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 15-21.1, Page number: 574</h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi\n",
+ "\n",
+ "dia = 1000 #diameter of asteroid (m)\n",
+ "prc = 0.4 #Power reflection coefficient of asteroid (unitless)\n",
+ "f = 4e9 #Frequency (Hz)\n",
+ "P = 1e9 #Power (W)\n",
+ "s = 20e3 #Asteroid speed (m/s)\n",
+ "ast_dis = 0.4 #Distance of asteroid (AU)\n",
+ "au = 1.5e11 #Astronomical Unit (m)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "k = 1.38e-23 #Boltzmann's constant (m^2 kg s^-2 K^-1)\n",
+ "Tsys = 10 #System temperature (K)\n",
+ "B = 1e6 #Bandwidth (Hz)\n",
+ "snr = 10 #Signal to noise ratio (dB)\n",
+ "eap = 0.75 #Aperture efficiency (unitless)\n",
+ "\n",
+ "sigma = prc*pi*s**2 #Radar cross section (m^2)\n",
+ "ast_dm = au*ast_dis #Astroid distance (m)\n",
+ "lmda = c/f #Wavelength(m)\n",
+ "\n",
+ "d4 = (64*(lmda**2)*(ast_dm**4)*k*Tsys*B*snr)/((eap**2)*pi*(sigma)*P)\n",
+ "d = d4**(0.25) #Diameter of dish (m)\n",
+ "\n",
+ "delf = 2*s/lmda #Doppler shift (Hz)\n",
+ "delt = 2*(ast_dm)/c #Time delay (s)\n",
+ "\n",
+ "timp = ast_dm/s #Time before impact (s) \n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print \"The diameter of the dish is\", round(d), \"m\"\n",
+ "print \"The doppler shift is %.1f Hz\" % delf\n",
+ "print \"The time delay for the radar signal is\", delt, \"s\"\n",
+ "print \"The time before impact is\", timp, \"s\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The diameter of the dish is 292.0 m\n",
+ "The doppler shift is 533333.3 Hz\n",
+ "The time delay for the radar signal is 400.0 s\n",
+ "The time before impact is 3000000.0 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 153
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 15-26.1, Page number: 584<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "t1 = 0.3e-9 #Echo time off the top of pavement (s)\n",
+ "t2 = 2.4e-9 #Echo time off bottom of pavement (s)\n",
+ "t3 = 14.4e-9 #Echo time off bottom of water pocket (s)\n",
+ "er_1 = 4 #Relative permittivity of pavement (unitless)\n",
+ "er_2 = 81 #Relative permittivity of water pocket (unitless)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "\n",
+ "#Calculations\n",
+ "d1 = (t2-t1)*c/(2*sqrt(er_1))\n",
+ "d2 = (t3-t2)*c/(2*sqrt(er_2))\n",
+ "\n",
+ "#Result\n",
+ "print \"The thickness of pavement is\", round(d1,2),\"m\"\n",
+ "print \"The thickness of water pocket is\", round(d2,2), \"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The thickness of pavement is 0.16 m\n",
+ "The thickness of water pocket is 0.2 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 104
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter16.ipynb b/Antennas_and_Wave_Propagation/chapter16.ipynb
new file mode 100644
index 00000000..00fc2d2e
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter16.ipynb
@@ -0,0 +1,101 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 16: Practical Design Considerations of Large Aperture Antennas<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 16-2.1, Page number: 608<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import cos, pi, log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "delta = 1/20.0 #rms deviation (lambda)\n",
+ "\n",
+ "#Calculations\n",
+ "del_phi = 4*pi*delta*180/pi #Phase error (degrees)\n",
+ "kg = cos(del_phi*pi/180)**2 #Gain-loss (unitless)\n",
+ "kg = 10*log10(kg) #Gain-loss (dB)\n",
+ "\n",
+ "#Result\n",
+ "print \"The gain reduction is\", round(abs(kg),1), \"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The gain reduction is 1.8 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 16-2.2, Page number: 609<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import tan,pi, log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "del_phi = 36.0 #rms phase error (degrees)\n",
+ "n_irr = 100.0 #Number of irregularities\n",
+ "\n",
+ "#Calculations\n",
+ "max_side = tan(del_phi*pi/180)**2\n",
+ "max_side = -10*log10(max_side)\n",
+ " #Maximum side-lobe level (dB)\n",
+ "ran_side = (1/n_irr)*tan(del_phi*pi/180)**2\n",
+ "ran_side = -10*log10(ran_side)\n",
+ " #Random side-lobe level (dB)\n",
+ "\n",
+ "#Result\n",
+ "print \"The maximum side lobe level from main lobe is\", round(max_side,1),\"dB\"\n",
+ "print \"The random side lobe level from main lobe is\", round(ran_side,1),\"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum side lobe level from main lobe is 2.8 dB\n",
+ "The random side lobe level from main lobe is 22.8 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter17.ipynb b/Antennas_and_Wave_Propagation/chapter17.ipynb
new file mode 100644
index 00000000..e9d63ef2
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter17.ipynb
@@ -0,0 +1,323 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 17: Antenna Temperature, Remote Sensing and Radar Cross Section<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 17-1.1, Page number: 623<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi\n",
+ "\n",
+ "#Variable declaration\n",
+ "Ta = 0.24 #Antenna temperature (K)\n",
+ "ang = 0.005 #Subtended angle (degrees)\n",
+ "hpbw = 0.116 #Antenna half power beamwidth (degrees)\n",
+ "\n",
+ "#Calculations\n",
+ "Ts = Ta*(hpbw**2)/(pi*(ang**2/4))\n",
+ "\n",
+ "#Result\n",
+ "print \"The averate temperature of the surface is\", round(Ts), \"K\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The averate temperature of the surface is 164.0 K\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 17-1.2, Page number: 625<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi, sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "eff_aper = 500 #Antenna effective aperture (m^2)\n",
+ "wave_lt = 20e-2 #Wavelength (m)\n",
+ "Tsky = 10.0 #sky temperature (K)\n",
+ "Tgnd = 300.0 #Ground temperature (K)\n",
+ "beam_eff = 0.7 #Beam efficiency (unitless)\n",
+ "aper_eff = 0.5 #Aperture efficiency (unitless)\n",
+ "\n",
+ "#Calculations\n",
+ "phy_aper = aper_eff/eff_aper #Physical aperture (m^2)\n",
+ "diam = 2*sqrt(phy_aper/pi) #Antenna diameter (m)\n",
+ "diam_l = diam/wave_lt #Antenna diameter (lambda)\n",
+ "\n",
+ "ta_sky = Tsky*beam_eff #Sky contribution to antenna temp. (K)\n",
+ "ta_side = 0.5*Tsky*(1-beam_eff) #Side-lobe contribution to antenna temp. (K)\n",
+ "ta_back = 0.5*Tgnd*(1-beam_eff) #Back-lobe contribution to antenna temp. (K)\n",
+ "\n",
+ "Ta = ta_sky + ta_side + ta_back\n",
+ "\n",
+ "#Result\n",
+ "print \"The total antenna temperature is\", Ta, \"K\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The total antenna temperature is 53.5 K\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 17-2.1, Page number: 629<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "Tn = 50.0 #Noise temperature (K)\n",
+ "Tphy = 300.0 #Physical temperature (K)\n",
+ "Eff = 0.99 #Efficiency (unitless)\n",
+ "Tn_stg = 80.0 #Noise temperature of first 3 stages (K)\n",
+ "gain_db = 13.0 #Gain (dB)\n",
+ "Tphy_tr = 300 #Transmission line physical temperature (K)\n",
+ "Eff_tr = 0.9 #Transmission line efficiency (unitless)\n",
+ "\n",
+ "#Calculations\n",
+ "gain = 10**(gain_db/10)\n",
+ "T_r = Tn_stg + Tn_stg/(gain) + Tn_stg/(gain**2)\n",
+ " #Receiver noise temperature (K)\n",
+ "Tsys = Tn + Tphy*(1/Eff - 1) + Tphy_tr*(1/Eff_tr - 1) + (1/Eff_tr)*T_r\n",
+ " #System temperature (K)\n",
+ "\n",
+ "#Result\n",
+ "print \"The system temperature is\", round(Tsys), \"K\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The system temperature is 180.0 K\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 17-2.2, Page number: 630<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "phy_aper = 2208 #Physical aperture (m^2)\n",
+ "f = 1415e6 #Frequency (Hz)\n",
+ "aper_eff = 0.54 #Aperture efficiency (unitless)\n",
+ "Tsys = 50 #System temperature (K)\n",
+ "bw = 100e6 #RF Bandwidth (Hz)\n",
+ "t_const = 10 #Output time constant (s)\n",
+ "sys_const = 2.2 #System constant (unitless)\n",
+ "k = 1.38e-23 #Boltzmann's constant (J/K)\n",
+ "\n",
+ "#Calculations\n",
+ "Tmin = sys_const*Tsys/(sqrt(bw*t_const)) #Minimum detectable temperature(K)\n",
+ "eff_aper = aper_eff*phy_aper #Effective aperture (m^2)\n",
+ "Smin = 2*k*Tmin/eff_aper #Minimum detectable flux density (W/m^2/Hz)\n",
+ "\n",
+ "#Result\n",
+ "print \"The minimum detectable flux density is %.1e W/m^2/Hz\" % Smin"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum detectable flux density is 8.1e-29 W/m^2/Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 17-3.1, Page number: 631<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi, log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "k = 1.38e-23 #Boltzmann's constant (J/K)\n",
+ "trans_pow = 5 #Transponder power (W)\n",
+ "r = 36000e3 #Distance (m)\n",
+ "wave_lt = 7.5e-2 #Wavelength (m)\n",
+ "ant_gain = 30 #Antenna gain (dB)\n",
+ "earth_ant = 38 #Earth station antenna gain (dB)\n",
+ "Tsys = 100 #Earth station receiver system temperature (K)\n",
+ "bw = 30e6 #Bandwidth (Hz)\n",
+ "\n",
+ "#Calculations\n",
+ "s_n = wave_lt**2/(16*(pi**2)*(r**2)*k*Tsys*bw)\n",
+ "s_n = 10*log10(s_n) #Signal to Noise ratio (dB)\n",
+ "\n",
+ "trans_pow_db = 10*log10(trans_pow) #Transponder power (dB)\n",
+ "erp = ant_gain + trans_pow_db #Effective radiated power (dB)\n",
+ "\n",
+ "s_n_downlink = erp + earth_ant + s_n #Signal to Noise ratio downlink(dB)\n",
+ "\n",
+ "#Result\n",
+ "print \"The earth station S/N ratio is\", round(s_n_downlink,1), \"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The earth station S/N ratio is 13.2 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 17-4.1, Page number: 634<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import exp\n",
+ "\n",
+ "#Variable declaration\n",
+ "tf = 0.693 #Absorption co-efficient (unitless)\n",
+ "Te = 305 #Earth temperature (K)\n",
+ "Ta = 300 #Satellite antenna temperature (K)\n",
+ "\n",
+ "#Calculations\n",
+ "Tf = (Ta - Te*exp(-tf))/(1-exp(-tf))\n",
+ "\n",
+ "#Result\n",
+ "print \"The forest temperature is\", round(Tf), \"K\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The forest temperature is 295.0 K\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 17-5.1, Page number: 639<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "f = 10e9 #Frequency (Hz)\n",
+ "wind_speed = 350 #Wind speed (km/h)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "vr = 1e3 #Differential velocity (m/h)\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "freq_shift = 2*(wind_speed*1000/3600)/wave_lt \n",
+ " #Doppler Frequency shift (Hz)\n",
+ "T = 1/(2*freq_shift) #Pulse repetition interval (s)\n",
+ "prf = 1/T #Pulse repetition frequency (Hz)\n",
+ "\n",
+ "fmin = 2*(vr/3600)/wave_lt #Frequency resolution (Hz)\n",
+ "N = 1/(round(fmin,1)*T) #Number of pulses \n",
+ "\n",
+ "#Result\n",
+ "print \"The minimum pulse repetition frequency is\", round(prf,-3), \"Hz\"\n",
+ "print \"The number of pulses to be sampled is\", round(N)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum pulse repetition frequency is 13000.0 Hz\n",
+ "The number of pulses to be sampled is 699.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter19.ipynb b/Antennas_and_Wave_Propagation/chapter19.ipynb
new file mode 100644
index 00000000..e7875d72
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter19.ipynb
@@ -0,0 +1,136 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 19: The Fourier Transform Relation between Aperture Distribution and Far-field Pattern<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 19-8.1, Page number: 690<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sin, pi\n",
+ "\n",
+ "#Variable declaration\n",
+ "gal_ext = 400000 #Extent of galaxy (light-years)\n",
+ "alpha = 0.032 #Extent of galaxy (degrees)\n",
+ "f = 5e9 #Frequency (Hz)\n",
+ "a = 36e3 #Maximum VLA Spacing (m)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "wid = 0.03 #Width of image (degrees)\n",
+ "hei = 0.008 #Height of image (degrees)\n",
+ "flux_den = 2.5e-23 #Average flux density (W/m^2)\n",
+ "bw = 1e9 #Bandwidth (Hz)\n",
+ "\n",
+ "#Calculations\n",
+ "dist = gal_ext/sin(alpha*pi/180) #Distance to the galaxy (light-years)\n",
+ "dist_m = dist*(365*24*3600*c)\n",
+ "\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "a_lambda = a/wave_lt #Spacing in wavelength (unitless)\n",
+ "pix_size = 51/a_lambda #Resolution or Pixel size (degrees)\n",
+ "pix_size_arc = pix_size*3600 #Pixel size (arc seconds)\n",
+ "\n",
+ "area = wid*hei #Area of image (square degrees)\n",
+ "area_arc = area*(3600**2) #Area of image (arc seconds)\n",
+ "num_pix = area_arc/pix_size_arc**2 #Number of pixels\n",
+ "\n",
+ "rad_pow = flux_den*4*pi*(dist_m**2)*bw\n",
+ "\n",
+ "#Result\n",
+ "print \"The distance to the galaxy is\", round(dist,-8), \"light years\"\n",
+ "print \"The resolution or pixel size is\", round(pix_size_arc,2), \"arc seconds\"\n",
+ "print \"The number of pixels is\", round(num_pix)\n",
+ "print \"The radio power of the galaxy is %.1e W\" % rad_pow"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The distance to the galaxy is 700000000.0 light years\n",
+ "The resolution or pixel size is 0.31 arc seconds\n",
+ "The number of pixels is 33218.0\n",
+ "The radio power of the galaxy is 1.4e+37 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 19-8.2, Page number:691<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi, log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "f = 10e9 #Frequency (Hz)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "dia = 100 #Dish diameter (m)\n",
+ "aper_eff = 0.725 #Aperture efficiency (unitless)\n",
+ "\n",
+ "#Calculation\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "hpbw = 66/(dia/wave_lt) #Half power beam width (degrees)\n",
+ "\n",
+ "gain = 41000/(hpbw**2) #Gain from beamwidth (unitless)\n",
+ "gain_db = 10*log10(gain) #Gain from beamwidth (dBi)\n",
+ "\n",
+ "gain_ap = 4*(pi**2)*(dia/2)**2*(aper_eff)/(wave_lt**2) \n",
+ " #Gain from effective aperture(unitless)\n",
+ "gain_ap_db = 10*log10(gain_ap) #Gain from effective aperture (dBi)\n",
+ "\n",
+ "side_lobe = -23 #First side lobe level from table (dB)\n",
+ "\n",
+ "#Result\n",
+ "print \"The Half Power Beamwidth is\", round(hpbw,3), \"degrees\"\n",
+ "print \"The gain from beamwidth is\", round(gain_db), \"dBi\"\n",
+ "print \"The gain from effective aperture is\", round(gain_ap_db), \"dBi\"\n",
+ "print \"The first side-lobe level is\", side_lobe,\"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Half Power Beamwidth is 0.02 degrees\n",
+ "The gain from beamwidth is 80.0 dBi\n",
+ "The gain from effective aperture is 79.0 dBi\n",
+ "The first side-lobe level is -23 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter2.ipynb b/Antennas_and_Wave_Propagation/chapter2.ipynb
new file mode 100644
index 00000000..84f28496
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter2.ipynb
@@ -0,0 +1,486 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 2: Antenna Basics<h2>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2-3.1, Page number: 14<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "e_half_power = 1/math.sqrt(2) #E(theta) at half power (relative quantity)\n",
+ "\n",
+ "#Calculation\n",
+ "theta = math.acos(math.sqrt(e_half_power)) # theta (radians)\n",
+ "hpbw = 2*theta*180/math.pi # Half power beamwidth (degrees)\n",
+ "\n",
+ "#Result\n",
+ "print \"The half power beamwidth is \", round(hpbw), \"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The half power beamwidth is 66.0 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2-3.2, Page number: 14<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "e_half_power = 1/math.sqrt(2) #E(theta) at half power(unitless)\n",
+ "e_null = 0 #E(theta) = 0 at null points (unitless)\n",
+ "theta_1 = 0 #theta' (degrees)\n",
+ "theta = 1 #theta (degrees)\n",
+ "\n",
+ "#Calculation\n",
+ "for x in range(3): #Iterate till theta = i\n",
+ " theta = 0.5*math.acos(e_half_power/math.cos(theta_1*math.pi/180)) \n",
+ " #theta(radian)\n",
+ " theta_1 = theta*180/math.pi #set i = theta for next iteration (degrees)\n",
+ " \n",
+ "hpbw = 2*(theta*180/math.pi) #Half-power beamwidth (Degrees)\n",
+ "theta = 0.5*math.acos(e_null) #theta (radians)\n",
+ "fnbw = 2*(theta*180/math.pi) #Beamwidth between first null (degrees)\n",
+ "\n",
+ "#Result\n",
+ "print \"The half power beamwidth is\", round(hpbw), \"degrees\"\n",
+ "print \"The beamwidth between first nulls is \", round(fnbw), \"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The half power beamwidth is 41.0 degrees\n",
+ "The beamwidth between first nulls is 90.0 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2-4.1, Page number: 17<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import scipy.integrate\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "def integrand(x):\n",
+ " return math.sin(x) #Function sin(theta)\n",
+ "\n",
+ "def integrand2(x):\n",
+ " return 1 #Contant function\n",
+ "\n",
+ "#Calculation\n",
+ "omega = scipy.integrate.quad(integrand, 20*math.pi/180, 40*math.pi/180) \n",
+ "omega = omega[0]*(180/math.pi) * scipy.integrate.quad(integrand2 ,30 ,70)[0]\n",
+ "#Integration between the ranges gives solid angle, omega (square degrees)\n",
+ "\n",
+ "#Result\n",
+ "print \"The solid angle, omega is\", round(omega), \"square degrees\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The solid angle, omega is 398.0 square degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2-4.2, Page number: 17<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import scipy.integrate\n",
+ "\n",
+ "#Variable declaration\n",
+ "def func1(x,y):\n",
+ " return (math.cos(x)**4)*math.sin(x)*1 #Function for integration\n",
+ "\n",
+ "#Calculation\n",
+ "beam_area = scipy.integrate.dblquad(func1, 0, 2*math.pi, \n",
+ " lambda x: 0, lambda x: math.pi/2)\n",
+ "#Beam area (steradians)\n",
+ "\n",
+ "#Result\n",
+ "print \"The beam area of the given pattern is\", round(beam_area[0], 2), \"sr\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The beam area of the given pattern is 1.26 sr\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2-7.1, Page number: 21<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import scipy.integrate\n",
+ "from math import pi,sin,cos,log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "n = 10 #Number of isotropic point sources\n",
+ "dr = pi/2 #Distance(radians)\n",
+ "hpbw = 40 #Half power beamwidth (degrees)\n",
+ "def integrand(x,phi):\n",
+ " E_norm = (sin(pi/20))*(sin((pi/2)*(5*cos(phi)-6))/sin((pi/20)*(5*cos(phi)-6)))\n",
+ " return (E_norm**2)\n",
+ "\n",
+ "#Calculation\n",
+ "gain = scipy.integrate.dblquad(integrand, 0, 2*pi,\n",
+ " lambda x: 0, lambda x: pi/2)[0]\n",
+ "gain = (4*pi)/gain #Gain (unitless)\n",
+ "gain_db = 10*log10(gain)#Gain (dB)\n",
+ "gain_hpbw = 40000/(hpbw**2) #Gain from approx. equation (unitless)\n",
+ "gain_hpbw_db = 10*log10(gain_hpbw) #Gain from approx. equation (dB)\n",
+ "gain_diff = gain_hpbw_db - gain_db #Difference in gain (dB)\n",
+ "\n",
+ "#Result\n",
+ "print \"The gain G is\", round(gain_db,2),\"dB\"\n",
+ "print \"The gain from approx. equation is\", round(gain_hpbw_db),\"dB\"\n",
+ "print \"The difference is\", round(gain_diff,2),\"dB\"\n",
+ "\n",
+ "#The solution is incorrect due to the incorrect integration of the normalized power pattern\n",
+ "#As a result, the difference in gain is slightly higher"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The gain G is 10.01 dB\n",
+ "The gain from approx. equation is 14.0 dB\n",
+ "The difference is 3.97 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2-7.2, Page number: 21<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import scipy.integrate\n",
+ "\n",
+ "#Variable declaration\n",
+ "theta_hp = 90\n",
+ "phi_hp = 90\n",
+ "\n",
+ "def integrand(theta, phi):\n",
+ " return ((math.sin(theta)**3)*(math.sin(phi)**2))\n",
+ "\n",
+ "#Calculation\n",
+ "direct_exact = 4*math.pi/scipy.integrate.dblquad(integrand, 0, math.pi,\n",
+ " lambda x: 0, lambda x: math.pi)[0]\n",
+ " #Exact Directivity(No unit) \n",
+ "direct_apprx = 41253.0/(theta_hp*phi_hp) #Approximate directivity (No unit)\n",
+ "db_diff = 10*math.log10(direct_exact/direct_apprx) #Difference (decibels)\n",
+ "\n",
+ "#Result\n",
+ "print \"The exact directivity is\", round(direct_exact, 1)\n",
+ "print \"The approximate directivity is\", round(direct_apprx,1)\n",
+ "print \"The decibel difference is \", round(db_diff, 1), \"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The exact directivity is 6.0\n",
+ "The approximate directivity is 5.1\n",
+ "The decibel difference is 0.7 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2-10.1, Page number: 28<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "Z = 120*math.pi #Intrinsic impedence of free space (ohm)\n",
+ "\n",
+ "#Calculation\n",
+ "max_aper = Z/(320*math.pi**2) #Max. effective aperture (lambda^2)\n",
+ "direct = 4*math.pi*max_aper #directivity (unitless)\n",
+ "\n",
+ "#Result\n",
+ "print \"The maximum effective aperture is\", round(max_aper, 3), \"lambda^2\"\n",
+ "print \"The direcitivity is\", direct"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum effective aperture is 0.119 lambda^2\n",
+ "The direcitivity is 1.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2-10.2, Page number: 29<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "R_r = 73 #Radiation resistance (ohm)\n",
+ "\n",
+ "#Calculation\n",
+ "eff_aper = 30/(R_r*math.pi) #Effective aperture (lambda^2)\n",
+ "directivity = 4*math.pi*eff_aper #Directivity (unitless)\n",
+ "\n",
+ "#Result\n",
+ "print \"The effective aperture is\", round(eff_aper, 2), \"lambda^2\"\n",
+ "print \"The directivity is\", round(directivity,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The effective aperture is 0.13 lambda^2\n",
+ "The directivity is 1.64\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2-11.1, Page number: 31<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "P_t = 15 #Transmitter power (W)\n",
+ "A_et = 2.5 #Effective aperture of transmitter (meter^2)\n",
+ "A_er = 0.5 #Effective aperture of receiver (meter^2)\n",
+ "r = 15e3 #Distance between the antennas (Line of sight) (m)\n",
+ "freq = 5e9 #Frequency (Hz)\n",
+ "c = 3e8 #speed of light (m/s)\n",
+ "\n",
+ "#Calculation\n",
+ "wave_len = c/freq #Wavelength (m)\n",
+ "P_r = (P_t*A_et*A_er)/((r**2)*(wave_len**2)) #received power (W)\n",
+ "\n",
+ "#Result\n",
+ "print \"The power delivered to the receiver is\", round(P_r,6), \"watts\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The power delivered to the receiver is 2.3e-05 watts\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2-16.1, Page number: 40<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "E1 = 3 #Magnitude of electric field in x direction (V/m)\n",
+ "E2 = 6 #Magnitude of electric field in y direction (V/m)\n",
+ "Z = 377 #Intrinsic impedence of free space (ohm)\n",
+ "\n",
+ "#Calculation\n",
+ "avg_power = 0.5*(E1**2 + E2**2)/Z #average power per unit area (W/m^2)\n",
+ "\n",
+ "#Result\n",
+ "print \"The average power per unit area is\", avg_power, \"watts/meter^2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The average power per unit area is 0.0596816976127 watts/meter^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2-17.1, Page number: 43<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "AR_w = 4 #Axial Ratio for left elliptically polarized wave (unitless)\n",
+ "tau_w = 15 #Tilt angle for left elliptically polarized wave (degrees)\n",
+ "AR_a = -2 #Axial Ratio for right elliptically polarized wave (unitless) \n",
+ "tau_a = 45 #Tilt angle for right elliptically polarized wave (degrees)\n",
+ "tau_w2 = 20.7 #2*Tilt angle for left elliptically polarized wave (degrees) \n",
+ "tau_a2 = 39.3 #2*Tilt angle for right elliptically polarized wave (degrees)\n",
+ "\n",
+ "#Calculation\n",
+ "eps_a2 = 2*math.atan2(1,AR_a)*180/math.pi #polarisation latitude (degrees)\n",
+ "eps_w2 = 2*math.atan2(1,AR_w)*180/math.pi #antenna latitude (degrees)\n",
+ "gamma_w2 =math.acos(math.cos(eps_w2*math.pi/180)*math.cos(tau_w2*math.pi/180));\n",
+ " #great-circle angle - antenna (radians)\n",
+ "gamma_a2 =math.acos(math.cos(eps_a2*math.pi/180)*math.cos(tau_a2*math.pi/180));\n",
+ " #great-circle angle - wave (radians)\n",
+ "M_Ma = (gamma_w2*180/math.pi) + (gamma_a2*180/math.pi) \n",
+ " #total great-circle angle (degrees)\n",
+ "F = math.cos((M_Ma/2)*math.pi/180)**2 \n",
+ " #Polarisation matching factor (relative quantity)\n",
+ "\n",
+ "#Result\n",
+ "print \"The polarization matching factor is\", round(F,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The polarization matching factor is 0.44\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter21.ipynb b/Antennas_and_Wave_Propagation/chapter21.ipynb
new file mode 100644
index 00000000..270e96e9
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter21.ipynb
@@ -0,0 +1,343 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 21: Antenna Measurements<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 21-2.1, Page number: 720<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi\n",
+ "\n",
+ "#Variable declaration\n",
+ "f = 900e6 #Frequency (Hz)\n",
+ "length = 25e-3 #Length of antenna (m)\n",
+ "len_cell = 110e-3 #Length of handset chassis (m)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "del_L = 0.5 #Peak to Peak measurement uncertainty (dB)\n",
+ "\n",
+ "#Calculations\n",
+ "Dm = length + len_cell #Maximum Dimension of antenna (m)\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "r_rnf = (wave_lt/(2*pi)) #Outer boundary of reactive near field (m)\n",
+ "\n",
+ "r_ff = 2*(Dm**2)/wave_lt #Fraunhofer region (m)\n",
+ "\n",
+ "r2_ff = r_rnf/(10**(del_L/40)-1) \n",
+ " #Minimum distance where effect of near field is small (m)\n",
+ "\n",
+ "r3_ff = 2*Dm/(10**(del_L/10)-1)\n",
+ " #Minimum distance where effect of rotation of AUT is small (m)\n",
+ "\n",
+ "#Result\n",
+ "print \"The Outer boundary of reactive near field is at a distance\", round(r_rnf,3),\"m\"\n",
+ "print \"The Fraunhofer region starts at a distance\", round(r_ff,3),\"m\"\n",
+ "print \"The Minimum distance where effect of near field is small enough is\",\\\n",
+ " round(r2_ff,1),\"m\"\n",
+ "print \"The Minimum distance where effect of rotation of AUT is small enough \\\n",
+ "is\", round(r3_ff,1),\"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Outer boundary of reactive near field is at a distance 0.053 m\n",
+ "The Fraunhofer region starts at a distance 0.109 m\n",
+ "The Minimum distance where effect of near field is small enough is 1.8 m\n",
+ "The Minimum distance where effect of rotation of AUT is small enough is 2.2 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 21-2.2, Page number: 720<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi\n",
+ "\n",
+ "#Variable declaration\n",
+ "horn_len = 350e-3 #Length of horn (m)\n",
+ "ap_wid = 200e-3 #Aperture width (m)\n",
+ "ap_hei = 150e-3 #Aperture height (m)\n",
+ "del_L = 0.2 #Peak to peak uncertainty (dB)\n",
+ "f = 10e9 #Frequency (Hz)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "r_rnf = wave_lt/(2*pi) ##Outer boundary of reactive near field (m)\n",
+ "\n",
+ "r_ff = 2*(ap_wid**2)/wave_lt #Fraunhofer region (m)\n",
+ "\n",
+ "r2_ff = r_rnf/(10**(del_L/40)-1) \n",
+ " #Minimum distance where effect of near field is small (m)\n",
+ "\n",
+ "r3_ff = 2*horn_len/(10**(del_L/10)-1)\n",
+ " #Minimum distance where effect of rotation of AUT is small (m)\n",
+ "\n",
+ "#Result\n",
+ "print \"The Outer boundary of reactive near field is at a distance\", round(r_rnf,4),\"m\"\n",
+ "print \"The Fraunhofer region starts at a distance\", round(r_ff,1),\"m\"\n",
+ "print \"The Minimum distance where effect of near field is small enough is\",\\\n",
+ " round(r2_ff,2),\"m\"\n",
+ "print \"The Minimum distance where effect of rotation of AUT is small enough \\\n",
+ "is\", round(r3_ff,1),\"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Outer boundary of reactive near field is at a distance 0.0048 m\n",
+ "The Fraunhofer region starts at a distance 2.7 m\n",
+ "The Minimum distance where effect of near field is small enough is 0.41 m\n",
+ "The Minimum distance where effect of rotation of AUT is small enough is 14.9 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 21-2.3, Page number: 721<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "D = 0.5 #Antenna diameter (m)\n",
+ "f = 300e9 #Frequency (Hz)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "r_ff = 2*(D**2)/wave_lt #Fraunhofer region (m)\n",
+ "\n",
+ "#Result\n",
+ "print \"The Fraunhofer region starts at a distance\", r_ff,\"m\"\n",
+ "print \"At 300 GHz the attenuation of the atmosphere is around 10dB/km making\\\n",
+ " the measurement difficult in full-size ranges\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Fraunhofer region starts at a distance 500.0 m\n",
+ "At 300 GHz the attenuation of the atmosphere is around 10dB/km making the measurement difficult in full-size ranges\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 21-4.1, Page number: 726<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi\n",
+ "\n",
+ "#Variable declaration\n",
+ "D = 1 #Diameter of antenna (m)\n",
+ "f = 10e9 #Frequency (Hz)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "hpbw = 70*wave_lt/D #Half power beamwidth (degrees)\n",
+ "mea_dist = 2*(D**2)/wave_lt #Measurement distance (m)\n",
+ "trav_dist = hpbw*pi*mea_dist/180 #Traverse distance (m)\n",
+ "taper = ((0.5/(trav_dist/2))**2)*(-3) #Amplitude taper (dB)\n",
+ "\n",
+ "#Result\n",
+ "print \"The amplitude taper is\", round(taper,1), \"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The amplitude taper is -0.5 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 21-4.2, Page number: 735<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "pat_lev1 = -22.3 #Pattern level maximum (dB)\n",
+ "pat_lev2 = -23.7 #Pattern level minimum (dB)\n",
+ "\n",
+ "#Calculations\n",
+ "S = abs(pat_lev2-pat_lev1) #Amplitude ripple (dB)\n",
+ "a = (pat_lev1+pat_lev2)/2 #Pattern level (dB)\n",
+ "\n",
+ "R = a + 20*log10((10**(S/20) - 1)/(10**(S/20) + 1))\n",
+ " #Reflectivity (dB)\n",
+ "\n",
+ "#Result\n",
+ "print \"The reflectivity is\", round(R),\"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reflectivity is -45.0 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 21-5.1, Page number: 739<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi, sin, cos, log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "En = 1 #Field illuminating the AUT (unitless)\n",
+ "tilt_diff = 88 #Difference in tilt angles (degrees)\n",
+ "\n",
+ "#Calculations\n",
+ "En_pol = En*sin(tilt_diff*pi/180) #Co-polar component of field (unitless)\n",
+ "En_crosspol = En*cos(tilt_diff*pi/180)\n",
+ " #Cross-polar component of field (unitless)\n",
+ "meas_cross = 20*log10(En_crosspol)\n",
+ "\n",
+ "#Result\n",
+ "print \"The measure cross-polar level is\", round(meas_cross), \"dB\\\n",
+ " relative to the co-polar field\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The measure cross-polar level is -29.0 dB relative to the co-polar field\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 21-5.2, Page number: 743<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi, log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "f = 1.4e9 #Frequency (Hz)\n",
+ "Tant = 687 #Increase in antenna temperature (K)\n",
+ "phy_ap = 2210 #Physical aperture (m^2)\n",
+ "S = 1590 #Flux density of Cygnus A (Jy)\n",
+ "k = 1.38e-23 #Boltzmann's constant (J/k)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "gain = (8*pi*k*Tant)/(S*(10**-26)*wave_lt**2) #Gain(unitless)\n",
+ "gain_db = 10*log10(gain) #Gain (dBi)\n",
+ "\n",
+ "Ae = gain*wave_lt**2/(4*pi) #Effective area (m^2)\n",
+ "\n",
+ "eff_ap = Ae/phy_ap #Aperture efficiency (unitless)\n",
+ "\n",
+ "#Result\n",
+ "print \"The gain of the antenna is\", round(gain_db), \"dBi\"\n",
+ "print \"The aperture efficiency is\", round(eff_ap,2),\"or\",round(eff_ap*100),\"percent\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The gain of the antenna is 55.0 dBi\n",
+ "The aperture efficiency is 0.54 or 54.0 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter23.ipynb b/Antennas_and_Wave_Propagation/chapter23.ipynb
new file mode 100644
index 00000000..48d55109
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter23.ipynb
@@ -0,0 +1,302 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 23: Ground Wave Propagation<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 23-1.1, Page number: 783<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "f1 = 0.1 #Frequency (MHz)\n",
+ "f2 = 1.0 #Frequency (MHz)\n",
+ "f3 = 10.0 #Frequency (MHz)\n",
+ "\n",
+ "#Calculations\n",
+ "d1 = 50/(f1**(1.0/3)) #Distance for f1 (miles)\n",
+ "d2 = 50/(f2**(1.0/3)) #Distance for f2 (miles)\n",
+ "d3 = 50/(f3**(1.0/3)) #Distance for f3 (miles)\n",
+ "\n",
+ "#Result\n",
+ "print \"The distance for 100kHz is\", round(d1,2), \"miles\"\n",
+ "print \"The distance for 1MHz is\", d2, \"miles\"\n",
+ "print \"The distance for 10MHz is\", round(d3,2), \"miles\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The distance for 100kHz is 107.72 miles\n",
+ "The distance for 1MHz is 50.0 miles\n",
+ "The distance for 10MHz is 23.21 miles\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 23-2.1, Page number: 786<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi,sin\n",
+ "\n",
+ "#Variable declaration\n",
+ "f = 3e6 #Frequency (Hz)\n",
+ "sigma = 0.5 #Standard deviation of surface irregularities (unitless)\n",
+ "theta = 30 #Angle of incidence as measured from normal angle (degrees)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "R = 4*pi*sigma*sin(theta*pi/180)/wave_lt\n",
+ " #Roughness factor (unitless)\n",
+ "\n",
+ "#Result\n",
+ "print \"The roughness factor is\", round(R,9)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The roughness factor is 0.031415927\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 23-2.2, Page number: 786<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi,sin\n",
+ "\n",
+ "#Variable declaration\n",
+ "f = 10e6 #Frequency (Hz)\n",
+ "sigma = 5 #Standard deviation of surface irregularities (unitless)\n",
+ "theta1 = 30 #Angle of incidence as measured from normal angle (degrees)\n",
+ "theta2 = 45 #Angle of incidence as measured from normal angle (degrees)\n",
+ "theta3 = 60 #Angle of incidence as measured from normal angle (degrees)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "R1 = 4*pi*sigma*sin(theta1*pi/180)/wave_lt \n",
+ " #Roughness factor for theta1 (unitless)\n",
+ "R2 = 4*pi*sigma*sin(theta2*pi/180)/wave_lt\n",
+ " #Roughness factor for theta2 (unitless)\n",
+ "R3 = 4*pi*sigma*sin(theta3*pi/180)/wave_lt\n",
+ " #Roughness factor for theta3 (unitless)\n",
+ "\n",
+ "#Result\n",
+ "print \"The roughness factor for 30 degrees is\", round(R1,4)\n",
+ "print \"The roughness factor for 45 degrees is\", round(R2,3)\n",
+ "print \"The roughness factor for 60 degrees is\", round(R3,4)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The roughness factor for 30 degrees is 1.0472\n",
+ "The roughness factor for 45 degrees is 1.481\n",
+ "The roughness factor for 60 degrees is 1.8138\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 23-2.3, Page number: 787<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "f1 = 0.3 #Frequency (MHz)\n",
+ "f2 = 1 #Frequency (MHz)\n",
+ "f3 = 3 #Frequency (MHz)\n",
+ "sigma = 4e-5 #Standard deviation of surface irregularities (unitless)\n",
+ "\n",
+ "#Calculations\n",
+ "x1 = (18e3)*sigma/f1 #Parameter x for f1 (unitless)\n",
+ "x2 = (18e3)*sigma/f2 #Parameter x for f2 (unitless)\n",
+ "x3 = (18e3)*sigma/f3 #Parameter x for f3 (unitless)\n",
+ "\n",
+ "#Result\n",
+ "print \"The parameter x for 0.3MHz is\", x1\n",
+ "print \"The parameter x for 1MHz is\", x2\n",
+ "print \"The parameter x for 3MHz is\", x3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The parameter x for 0.3MHz is 2.4\n",
+ "The parameter x for 1MHz is 0.72\n",
+ "The parameter x for 3MHz is 0.24\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 23-5.1, Page number: 790<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi, sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "f1 = 5e3 #Frequency (Hz)\n",
+ "f2 = 50e3 #Frequency (Hz)\n",
+ "f3 = 500e3 #Frequency (Hz)\n",
+ "sigma = 5e-5 #Standard deviation of surface irregularities (unitless)\n",
+ "eps_r = 15.0 #Relative permittivity (unitless)\n",
+ "mu = pi*4e-7 #Absolute Permeability (H/m)\n",
+ "\n",
+ "#Calculations\n",
+ "w1 = 2*pi*f1 #Angular frequency (rad/s)\n",
+ "w2 = 2*pi*f2 #Angular frequency (rad/s)\n",
+ "w3 = 2*pi*f3 #Angular frequency (rad/s)\n",
+ "\n",
+ "\n",
+ "Zs1 = sqrt((w1*mu)/sqrt(sigma**2 + (w1**2)*eps_r))\n",
+ " #Surface impedence for f1 (ohm)\n",
+ "Zs2 = sqrt((w2*mu)/sqrt(sigma**2 + (w2**2)*eps_r))\n",
+ " #Surface impedence for f2 (ohm)\n",
+ "Zs3 = sqrt((w3*mu)/sqrt(sigma**2 + (w3**2)*eps_r))\n",
+ " #Surface impedence for f3 (ohm)\n",
+ "\n",
+ "#Result\n",
+ "print \"The surface impedence for 5kHz is\", round(Zs1,5), \"ohms\"\n",
+ "print \"The surface impedence for 50kHz is\", round(Zs2,5), \"ohms\"\n",
+ "print \"The surface impedence for 500kHz is\", round(Zs3,5), \"ohms\"\n",
+ "\n",
+ "#There has been a numerical mistake in the calculation/substitution of square root of\n",
+ "#(sigma**2 + (w1**2)*eps_r) and in the second case, the mistake in the calculation of\n",
+ "#(w2*mu)/sqrt(sigma**2 + (w2**2)*eps_r)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The surface impedence for 5kHz is 0.00057 ohms\n",
+ "The surface impedence for 50kHz is 0.00057 ohms\n",
+ "The surface impedence for 500kHz is 0.00057 ohms\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 23-7.1, Page number: 793<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi, atan, cos\n",
+ "\n",
+ "#Variable declaration\n",
+ "f = 2.0 #Frequency (MHz)\n",
+ "sigma = 5e-5 #Standard deviation of surface irregularities (unitless)\n",
+ "eps_r = 15.0 #Relative permittivity (unitless)\n",
+ "d = 20e3 #Distance (m)\n",
+ "eff = 0.5 #Antenna efficiency (unitless)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "E1 = 0.5e-3 #Ground wave electric field strength (V/m)\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/(f*10**6) #Wavelength (m)\n",
+ "x = (18e3)*sigma/f #Parameter x (unitless)\n",
+ "\n",
+ "b = atan((eps_r + 1)/x) #Phase constant (unitless)\n",
+ "\n",
+ "p = (pi/x)*(d/wave_lt)*cos(b) #Numerical distance (unitless)\n",
+ "\n",
+ "A = (2 + 0.3*p)/(2 + p + 0.6*(p**2)) #Reduction factor (unitless)\n",
+ "\n",
+ "E_t = E1 * d/A\n",
+ "\n",
+ "#Result\n",
+ "print \"The Electric field strength at the transmitted end is\", round(E_t,2),\"V/m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Electric field strength at the transmitted end is 445.72 V/m\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter24.ipynb b/Antennas_and_Wave_Propagation/chapter24.ipynb
new file mode 100644
index 00000000..a97a053a
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter24.ipynb
@@ -0,0 +1,332 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 24: Space Wave Propagation<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 24-9.1, Page number: 808<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "tx_h = 49.0 #Transmitting antenna height (m)\n",
+ "rx_h = 25.0 #Receiving antenna height (m)\n",
+ "f = 100e6 #Frequency (Hz)\n",
+ "tx_p = 100.0 #Transmitted power (W)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "a = 6370 #Earth's radius (km)\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "d0 = sqrt(2*(4.0/3.0)*(a/1000.0))*(sqrt(tx_h)+sqrt(rx_h))\n",
+ " #Line of Sight (LOS) distance (km)\n",
+ "d = d0*1000 #LOS (m)\n",
+ "Er = (88*sqrt(tx_p)/(wave_lt*(d**2)))*tx_h*rx_h\n",
+ " #Received signal strength (W)\n",
+ "\n",
+ "#Result\n",
+ "print \"The Line of Sight distance is\", round(d0,2), \"km\"\n",
+ "print \"The received signal strength is\", round(Er,6), \"W\"\n",
+ "\n",
+ "#The mistake is in the calculation of (88*sqrt(tx_p)/(wave_lt*(d**2))) where four orders of\n",
+ "#magnitude are ignored in the resulting calculation."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Line of Sight distance is 49.46 km\n",
+ "The received signal strength is 0.000147 W\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 1,
+ "text": [
+ "'The mistake is in the calculation of (88*sqrt(tx_p)/(wave_lt*(d**2))) where four orders of\\nmagnitude are ignored in the resulting calculation.'"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 24-9.2, Page number: 809<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "tx_h = 144 #Transmitting antenna height (m)\n",
+ "rx_h = 25 #Receiving antenna height (m)\n",
+ "k = 4.0/3.0 #Equivalent earth radius/Actual earth radius (unitless)\n",
+ "a = 6370 #Radius of earth (km)\n",
+ "\n",
+ "#Calculations\n",
+ "los = 4.12*(sqrt(tx_h) + sqrt(rx_h)) #Line of sight distance (km)\n",
+ "\n",
+ "horz = sqrt(2*k*a*(tx_h/1000.0)) #Surface range to radio horizon from radar (km)\n",
+ "\n",
+ "#Result\n",
+ "print \"The Radio horizon distance from radar is\", round(horz,2),\"km\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Radio horizon distance from radar is 49.46 km\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 24-9.3, Page number: 809<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "tx_h = 100 #Transmitting antenna height (m)\n",
+ "rx_h = 16 #Receiving antenna height (m)\n",
+ "tx_p = 40e3 #Transmitting antenna power radiation (W)\n",
+ "f = 100e6 #Frequency (Hz)\n",
+ "d = 10e3 #Distance (m)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "E = 1e-3 #Signal strength (V/m)\n",
+ "\n",
+ "#Calculations\n",
+ "los = 4.12*(sqrt(tx_h) + sqrt(rx_h)) #LOS distance (km)\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "\n",
+ "Es = (88*sqrt(tx_p)/(wave_lt*(d**2)))*tx_h*rx_h\n",
+ " #Field strength at distance d (V/m)\n",
+ "\n",
+ "dsig = sqrt(88*sqrt(tx_p)*tx_h*rx_h/(wave_lt*E))\n",
+ " #Distance at which field strength reduces to 1mV/m\n",
+ "\n",
+ "#Result\n",
+ "print \"The LOS distance is\", los, \"km\"\n",
+ "print \"The field strength at 10km is\", round(Es,5),\"V/m\"\n",
+ "print \"The distance at which field strength is 1mV/m is\", round(dsig,-1), \"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The LOS distance is 57.68 km\n",
+ "The field strength at 10km is 0.09387 V/m\n",
+ "The distance at which field strength is 1mV/m is 96880.0 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 24-9.4, Page number: 809<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi\n",
+ "\n",
+ "#Variable declaration\n",
+ "gain = 10 #Antenna gain (dB)\n",
+ "Wt = 500 #Power radiation (W)\n",
+ "d = 15e3 #Distance (m)\n",
+ "Wr = 2e-6 #Received power (W)\n",
+ "\n",
+ "#Calculations\n",
+ "Ae = Wr*(4*pi*(d**2))/(Wt*gain) #Effective area (m^2)\n",
+ "\n",
+ "#Result\n",
+ "print \"The effective area of the receiving antenna is\", round(Ae,2), \"m^2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The effective area of the receiving antenna is 1.13 m^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 24-9.5, Page number: 809<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "h = 1000 #Height of duct (m)\n",
+ "delM = 0.036 #Change in refractive modulus (unitless)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "\n",
+ "#Calculations\n",
+ "wl_max = 2.5*h*sqrt(delM*1e-6) #Maximum wavelength (m)\n",
+ "fmax = c/wl_max #Maximum frequency (Hz)\n",
+ "\n",
+ "#Result\n",
+ "print \"The maximum frequency that can be transmitted is\", round(fmax/1e6,1),\"MHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum frequency that can be transmitted is 632.5 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 24-12.1, Page number: 812<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi,sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "gain = 10 #Gain of transmitting antenna (dB)\n",
+ "P = 100 #Radiating power (W)\n",
+ "f = 1e6 #Frequency (Hz)\n",
+ "rx_gain = 15 #Gain of receiving antenna (dB)\n",
+ "d = 20e3 #Distance (m)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "v = 1000 #scattering volume (m^3)\n",
+ "sigma = 0.1 #Effective scattering cross-section (m^2)\n",
+ "\n",
+ "#Calculations\n",
+ "wl = c/f #Wavelength (m)\n",
+ "Pr_a = P*gain*rx_gain*(wl**2)/(4*pi*(4*pi*(d**2)))\n",
+ " #Received power in case (a) (W)\n",
+ "F = (2*sqrt(sigma*v))/(d*sqrt(pi)) #Attenuation Factor (unitless)\n",
+ "Pr_b = Pr_a*F #Received power in case (b) (W)\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print \"The received power in case (a) is\", round(Pr_a,5), \"W\"\n",
+ "print \"The received power in case (b) is\", round(Pr_b,10), \"W\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The received power in case (a) is 0.02137 W\n",
+ "The received power in case (b) is 1.20581e-05 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 24-14.1, Page number: 813<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "d = 3000 #Distance (km)\n",
+ "f = 3e3 #Frequency (MHz)\n",
+ "\n",
+ "#Calculations\n",
+ "path_l = 32.45 + 20*log10(f) + 20*log10(d)\n",
+ "\n",
+ "#Result\n",
+ "print \"The path loss between the two points is\", round(path_l,3), \"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The path loss between the two points is 171.535 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter25.ipynb b/Antennas_and_Wave_Propagation/chapter25.ipynb
new file mode 100644
index 00000000..b013f142
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter25.ipynb
@@ -0,0 +1,242 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 25: Sky Wave Propagation<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 25-5.1, Page number: 823<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "muf = 10e6 #Maximum usable frequency (Hz)\n",
+ "h = 300 #Height of reflection (km)\n",
+ "n = 0.9 #Maximum value of refractive index (unitless)\n",
+ "\n",
+ "#Calculations\n",
+ "Nmax = (1 - n**2)*(muf**2)/81 #Max. Number of electrons per cubic cm\n",
+ "fc = 9*sqrt(Nmax) #Critical frequency (Hz)\n",
+ "dskip = 2*h*sqrt((muf/fc)**2 - 1) #Skip distance (km)\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print \"The skip distance is\", round(dskip,1), \"km\"\n",
+ "\n",
+ "#Numerical error in the calculation of sqrt((muf/fc)**2 - 1) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2.34567901235e+11 4358898.94354\n",
+ "The skip distance is 1238.8 km\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 25-5.2, Page number: 823<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "fE = 3e6 #Critical frequency for E layer (Hz)\n",
+ "fF1 = 5e6 #Critical frequency for F1 layer (Hz)\n",
+ "fF2 = 9e6 #Critical frequency for F2 layer (Hz)\n",
+ "\n",
+ "#Calculations\n",
+ "N_E = (fE**2)/81 #Concentration of electrons in E layer (per cubic cm)\n",
+ "N_F1 = (fF1**2)/81 #Concentration of electrons in F1 layer (per cubic cm)\n",
+ "N_F2 = (fF2**2)/81 #Concentration of electrons in F2 layer (per cubic cm)\n",
+ "\n",
+ "#Result\n",
+ "print \"The concentration of electrons in E layer is\", round(N_E,-8), \"per cubic cm\"\n",
+ "print \"The concentration of electrons in F1 layer is\", round(N_F1,-8), \"per cubic cm\"\n",
+ "print \"The concentration of electrons in F2 layer is\", N_F2, \"per cubic cm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The concentration of electrons in E layer is 1.111e+11 per cubic cm\n",
+ "The concentration of electrons in F1 layer is 3.086e+11 per cubic cm\n",
+ "The concentration of electrons in F2 layer is 1e+12 per cubic cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 25-5.3, Page number: 823<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "N_E = 0.8*0.111e12 #Concentration of electrons in E layer (per cubic cm)\n",
+ "N_F1 = 0.8*0.3086e12 #Concentration of electrons in E layer (per cubic cm)\n",
+ "N_F2 = 0.8*1e12 #Concentration of electrons in E layer (per cubic cm)\n",
+ "\n",
+ "#Calculations\n",
+ "fE = 9*sqrt(N_E) #Critical frequency in E layer (Hz)\n",
+ "fF1 = 9*sqrt(N_F1) #Cricital frequency in F1 layer (Hz)\n",
+ "fF2 = 9*sqrt(N_F2) #Critical frequency in F2 layer (Hz)\n",
+ "\n",
+ "#Result\n",
+ "print \"The Critical frequency in E layer is\", round(fE,-4),\"Hz\"\n",
+ "print \"The Critical frequency in F1 layer is\", round(fF1,-4),\"Hz\"\n",
+ "print \"The Critical frequency in F2 layer is\", round(fF2,-3),\"Hz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Critical frequency in E layer is 2680000.0 Hz\n",
+ "The Critical frequency in F1 layer is 4470000.0 Hz\n",
+ "The Critical frequency in F2 layer is 8050000.0 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 25-6.1, Page number: 829<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import cos, sqrt, pi\n",
+ "\n",
+ "#Variable declaration\n",
+ "hD = 70 #Height of D layer (km)\n",
+ "hE = 130 #Height of E layer (km)\n",
+ "hF1 = 230 #Height of F1 layer (km)\n",
+ "hF2 = 350 #Height of F2 layer (km)\n",
+ "theta = 10*pi/180 #Angle of incidence (radians)\n",
+ "\n",
+ "#Calculations\n",
+ "temp = sqrt((cos(theta))**-2 - 1)\n",
+ "d1 = 2*hD*temp #Maximum single hop distance for D layer (km)\n",
+ "d2 = 2*hE*temp #Maximum single hop distance for E layer (km)\n",
+ "d3 = 2*hF1*temp #Maximum single hop distance for F1 layer (km)\n",
+ "d4 = 2*hF2*temp #Maximum single hop distance for F2 layer (km)\n",
+ "\n",
+ "#Result\n",
+ "print \"The Maximum single hop distance for D layer is\", round(d1,1), \"km\"\n",
+ "print \"The Maximum single hop distance for E layer is\", round(d2,2), \"km\"\n",
+ "print \"The Maximum single hop distance for F1 layer is\", round(d3,2), \"km\"\n",
+ "print \"The Maximum single hop distance for F2 layer is\", round(d4,1), \"km\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Maximum single hop distance for D layer is 24.7 km\n",
+ "The Maximum single hop distance for E layer is 45.85 km\n",
+ "The Maximum single hop distance for F1 layer is 81.11 km\n",
+ "The Maximum single hop distance for F2 layer is 123.4 km\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 25-9.1, Page number: 832<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi, sqrt, cos\n",
+ "\n",
+ "#Variable declaration\n",
+ "d = 200 #Height of layer (km)\n",
+ "beta = 20 #Takeoff angle (degrees)\n",
+ "R = 6370 #Earth's radius (km)\n",
+ "\n",
+ "#Calculations\n",
+ "phi_0 = 90 - beta #Take off angle for flat earth (degrees)\n",
+ "h = (d/2)/(sqrt((cos(phi_0*pi/180)**-2) - 1)) #Skip distance for case (a) (km)\n",
+ "\n",
+ "phi_02 = 90 - beta - 57.2*d/(2*R)\n",
+ " #Take off angle for spherical earth (degrees)\n",
+ "h2 = (d/2)/(sqrt((cos(phi_02*pi/180)**-2) - 1))\n",
+ " #Skip distance for case (b) (km)\n",
+ "\n",
+ "#Result\n",
+ "print \"The skip distance for case (a) is\", round(h,3), \"km\"\n",
+ "print \"The skip distance for case (b) is\", round(h2,2), \"km\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The skip distance for case (a) is 36.397 km\n",
+ "The skip distance for case (b) is 38.18 km\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter3.ipynb b/Antennas_and_Wave_Propagation/chapter3.ipynb
new file mode 100644
index 00000000..6656b2c8
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter3.ipynb
@@ -0,0 +1,175 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 3: The Antenna Family<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 3-3.2, Page number: 58<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "Z_0 = 377 #Intrinsic impedence of free space(ohm)\n",
+ "Z_d = 710 +0j #Terminal impedence of dipole cylinder (ohm)\n",
+ "\n",
+ "#Calculation\n",
+ "Z_s = (Z_0**2)/(4*Z_d) #Terminal impedence of the slot (ohm)\n",
+ "\n",
+ "#Result\n",
+ "print \"The terminal impedence of the slot is\", round(Z_s.real), \"ohms\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The terminal impedence of the slot is 50.0 ohms\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 3-6.1, Page number: 61<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "L = 10 #Horn length (lambda)\n",
+ "delta = 0.25 #Path length difference (lambda)\n",
+ "\n",
+ "#Calculation\n",
+ "theta = 2*math.acos(L/(L+delta)) #Horn flare angle (radians)\n",
+ "theta = theta*180/math.pi #Horn flare angle (degrees)\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print \"The largest flare angle for given delta is\",round(theta,1), \"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The largest flare angle for given delta is 25.4 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 3-7.1, Page number: 62<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "f = 599e6 #Frequency of TV Station (Hz)\n",
+ "E = 1e-6 #Field strength (V/m)\n",
+ "D = 20 #Diameter of antenna (m)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "Z_0 = 377 #Intrinsic impedence of free space (ohm) \n",
+ "\n",
+ "#Calculation\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "A_e = (D*(wave_lt**2))/(4*math.pi) #Effective aperture (m^2)\n",
+ "P_r = (E**2)*A_e/Z_0 #Received power (W)\n",
+ "\n",
+ "#Result\n",
+ "print \"The received power is\", round(P_r,17), \"W\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The received power is 1.06e-15 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 3-11.1, Page number: 66<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "n = 4 #Number of patch antennas (lambda)\n",
+ "diameter = 0.5 #diameter of patch antennas (lambda)\n",
+ "\n",
+ "#Calculation\n",
+ "A_e = n*diameter #Effective aperture (lambda^2)\n",
+ "D = (4*math.pi*A_e) #Directivity (unitless)\n",
+ "D_dbi = 10*math.log10(D) #Directivity (dBi)\n",
+ "ohm_a = (4*math.pi)/D #Beam area (steradians)\n",
+ "\n",
+ "#Result\n",
+ "print \"The directivity is\", round(D), \"or\", round(D_dbi), \"dBi\"\n",
+ "print \"The beam area is\", ohm_a, \"sr\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The directivity is 25.0 or 14.0 dBi\n",
+ "The beam area is 0.5 sr\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter4.ipynb b/Antennas_and_Wave_Propagation/chapter4.ipynb
new file mode 100644
index 00000000..e1fba10d
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter4.ipynb
@@ -0,0 +1,272 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 4: Radiation<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 4-4.1, Page number: 75<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "theta = 30 #Angle of radiation (degrees)\n",
+ "epsilon_0 = 8.854e-12 #Permittivity of free space (F/m)\n",
+ "I_dl = 10 #Current in length dl (A-m)\n",
+ "r = 100e3 #Distance of point from origin (m)\n",
+ "\n",
+ "#Calculation\n",
+ "E_mag = (I_dl*math.sin(theta*math.pi/180))/(4*math.pi*epsilon_0)\n",
+ " #Magnitude of Electric field vector (V/m)\n",
+ "H_mag = (I_dl*math.sin(theta*math.pi/180))/(4)\n",
+ " #Magnitude of Magnetic field vector (T)\n",
+ "\n",
+ "#Result\n",
+ "print \"The magnitude of E vector is \", round(E_mag,-9), \"V/m\"\n",
+ "print \"The magnitude of H vector is\", round(H_mag, 3), \"/pi T\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The magnitude of E vector is 45000000000.0 V/m\n",
+ "The magnitude of H vector is 1.25 /pi T\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 4-4.2, Page number: 76<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "v = 3e8 #Speed of light(m/s)\n",
+ "f = 10e6 #Frequency (Hz)\n",
+ "\n",
+ "#Calculation\n",
+ "w = 2*math.pi*f #Angular frequency(rad/s)\n",
+ "r = v/w #Distance (m)\n",
+ "\n",
+ "#Result\n",
+ "print \"The distance for the specified condition is\", round(r, 2), \"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The distance for the specified condition is 4.77 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 4-4.3, Page number: 76<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "f = 3e9 #Frequency (Hz)\n",
+ "\n",
+ "#Calculation\n",
+ "v = 0.6*c #60% of velocity of light (m/s)\n",
+ "w = 2*math.pi*f #Angular frequency (rad/s)\n",
+ "r = v/w #Distance (m)\n",
+ "\n",
+ "#Result\n",
+ "print \"The distance for the specified condition is\", round(r,6), \"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The distance for the specified condition is 0.009549 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 4-5.1, Page number: 80<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "dl = 1e-2 #Length of radiating element (m)\n",
+ "I_eff = 0.5 #Effective current (A)\n",
+ "f = 3e9 #Frequency (Hz)\n",
+ "c = 3e8 #Velocity of light (m/s)\n",
+ "\n",
+ "#Calculation\n",
+ "w = 2*math.pi*f #Angular Frequency (rad/s)\n",
+ "P = 20*(w**2)*(I_eff**2)*(dl**2)/(c**2) #Radiated power (W)\n",
+ "\n",
+ "#Result\n",
+ "print \"The radiated power is\", round(P, 2), \"W\"\n",
+ "\n",
+ "#The final result is incorrect in the book because of the calculation mistake"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The radiated power is 1.97 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 4-5.2, Page number: 80<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "L = 5 #Length of radiating element (m)\n",
+ "f1 = 30e3 #Frequency (Hz) \n",
+ "f2 = 30e6 #Frequency (Hz) \n",
+ "f3 = 15e6 #Frequency (Hz)\n",
+ "c = 3e8 #Velocity of light (m/s) \n",
+ "\n",
+ "#Calculation\n",
+ "wave_lt1 = c/f1 #Wavelength (m)\n",
+ "wave_lt1 /= 10\n",
+ "R_r1 = 800*(L/wave_lt1)**2 #Radiation resistance (ohm)\n",
+ "\n",
+ "wave_lt2 = c/f2 #Wavelength (m)\n",
+ "L = wave_lt2/2 #Effective length (m)\n",
+ "R_r2 = 200*(L/wave_lt2)**2 #Radiation resistance (ohm)\n",
+ "\n",
+ "wave_lt3 = c/f3 #Wavelength (m)\n",
+ "L = wave_lt3/4 #Effective length (m)\n",
+ "R_r3 = 400*(L/wave_lt3)**2 #Radiation resistance (ohm)\n",
+ "\n",
+ "#Result\n",
+ "print \"The radiation resistance for f1 is\", R_r1, \"ohms\"\n",
+ "print \"The radiation resistance for f2 is\", round(R_r2), \"ohms\"\n",
+ "print \"The radiation resistance for f3 is\", round(R_r3), \"ohms\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The radiation resistance for f1 is 0.02 ohms\n",
+ "The radiation resistance for f2 is 50.0 ohms\n",
+ "The radiation resistance for f3 is 25.0 ohms\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 4-6.1, Page number: 82<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "Im = 5 #Maximum current (A)\n",
+ "r = 1e3 #Distance (km)\n",
+ "eta = 120*math.pi #Intrinsic impedence (ohm)\n",
+ "theta = 60*math.pi/180 #Angle of radiation (radians)\n",
+ "\n",
+ "#Calculation\n",
+ "sin2 = math.sin(theta)**2 #Sine squared theta (unitless)\n",
+ "P_av = (eta*(Im**2))/(8*(math.pi**2)*(r**2))\n",
+ "P_av = P_av*(math.cos(math.pi/2*math.cos(theta))**2)/(sin2)\n",
+ " #Average power (W)\n",
+ " \n",
+ "#Result\n",
+ "print \"The average power available at 1km distance is\", round(P_av,9), \"W\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The average power available at 1km distance is 7.9577e-05 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter5.ipynb b/Antennas_and_Wave_Propagation/chapter5.ipynb
new file mode 100644
index 00000000..a658e618
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter5.ipynb
@@ -0,0 +1,312 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 5: Point Source and Their Arrays<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 5-6.1, Page number: 90<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import scipy.integrate\n",
+ "\n",
+ "#Variable declaration\n",
+ "def integrand(theta, phi):\n",
+ " return (math.cos(theta)*math.sin(theta))\n",
+ " #Integrand (unitless)\n",
+ "Um = 1 #Maximum radiation intensity (unitless)\n",
+ "\n",
+ "#Calculation\n",
+ "P = scipy.integrate.dblquad(integrand, 0, 2*math.pi,\n",
+ " lambda x: 0, lambda x: math.pi/2)\n",
+ " #Total power radiated (relative to Um)\n",
+ "D = (4*math.pi)/P[0] #Directivity (unitless)\n",
+ "\n",
+ "#Result\n",
+ "print \"The directivity is \", round(D)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The directivity is 4.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 5-6.2, Page number: 91<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import scipy.integrate\n",
+ "\n",
+ "#Variable declaration\n",
+ "def integrand(theta, phi):\n",
+ " return (math.cos(theta)*math.sin(theta))\n",
+ " #Integrand (unitless)\n",
+ "Um = 1 #Maximum radiation intensity (unitless)\n",
+ "\n",
+ "#Calculation\n",
+ "P = scipy.integrate.dblquad(integrand, 0, 2*math.pi,\n",
+ " lambda x: 0, lambda x: math.pi/2)\n",
+ " #Total power radiated (relative to Um)\n",
+ "D = (4*math.pi)/(2*P[0]) #Directivity (unitless)\n",
+ "\n",
+ "#Result\n",
+ "print \"The directivity is \", round(D)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The directivity is 2.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 5-6.3, Page number: 91<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math, scipy.integrate\n",
+ "\n",
+ "#Variable declaration\n",
+ "def integrand(theta, phi):\n",
+ " return (math.sin(theta)**2)\n",
+ " #Integrand (unitless)\n",
+ "Um = 1 #Maximum radiation intensity (unitless)\n",
+ "\n",
+ "#Calculation\n",
+ "P = scipy.integrate.dblquad(integrand, 0, 2*math.pi,\n",
+ " lambda x: 0, lambda x: math.pi)\n",
+ " #Total radiated power (relative to Um)\n",
+ "D = 4*math.pi/P[0] #Directivity (unitless)\n",
+ "\n",
+ "#Result \n",
+ "print \"The directivity is\", round(D,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The directivity is 1.27\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 5-6.4, Page number: 91<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math, scipy.integrate\n",
+ "\n",
+ "#Variable declaration\n",
+ "def integrand(theta, phi):\n",
+ " return (math.sin(theta)**3)\n",
+ " #Integrand (unitless)\n",
+ "Um = 1 #Maximum radiation intensity (unitless)\n",
+ "\n",
+ "#Calculation\n",
+ "P = scipy.integrate.dblquad(integrand, 0, 2*math.pi,\n",
+ " lambda x: 0, lambda x: math.pi)\n",
+ " #Total radiated power (relative to Um)\n",
+ "D = 4*math.pi/P[0] #Directivity (unitless)\n",
+ "\n",
+ "#Result \n",
+ "print \"The directivity is\", round(D,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The directivity is 1.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 5-6.5, Page number: 92<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math, scipy.integrate\n",
+ "\n",
+ "#Variable declaration\n",
+ "def integrand(theta, phi):\n",
+ " return (math.sin(theta)*math.cos(theta)**2)\n",
+ " #Integrand (unitless)\n",
+ "Um = 1 #Maximum radiation intensity (unitless)\n",
+ "\n",
+ "#Calculation\n",
+ "P = scipy.integrate.dblquad(integrand, 0, 2*math.pi,\n",
+ " lambda x: 0, lambda x: math.pi/2)\n",
+ " #Total radiated power (relative to Um)\n",
+ "D = 4*math.pi/P[0] #Directivity (unitless)\n",
+ "\n",
+ "#Result \n",
+ "print \"The directivity is\", round(D,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The directivity is 6.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 5-6.6, Page number:93<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "lobes = [0.25,0.37,0.46,0.12,0.07] #Normalized power of lobes (unitless)\n",
+ "\n",
+ "#Calculation\n",
+ "ohm_a = 0 #Beam area (sr)\n",
+ "sum_lobes = 0 #Sum of all lobes (unitless)\n",
+ "for i in lobes:\n",
+ " ohm_a += 2*math.pi*(math.pi/36)*(i)\n",
+ " sum_lobes += i\n",
+ "\n",
+ "D = 4*math.pi/ohm_a #Directivity (unitless)\n",
+ "D_db = 10*math.log10(D) #Directivity (in dBi)\n",
+ "e_m = lobes[0]/sum_lobes #Beam efficiency (unitless)\n",
+ "\n",
+ "#Result\n",
+ "print \"The directivity is\", round(D), \"or\", round(D_db,1), \"dBi\"\n",
+ "print \"The beam efficiency is\", round(e_m, 2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The directivity is 18.0 or 12.6 dBi\n",
+ "The beam efficiency is 0.2\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 5-21.1, Page number: 146<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "a = 25 #Height of vertical conducting wall (m)\n",
+ "r = 100 #Distance to the receiver (m)\n",
+ "wave_lt = 10e-2 #Transmitter dimension (m)\n",
+ "\n",
+ "#Calculation\n",
+ "k = math.sqrt(2/(r*wave_lt)) #contant (unitless)\n",
+ "S_av = (r*wave_lt)/(4*(math.pi**2)*(a**2)) #Relative signal level (unitless)\n",
+ "S_av_db = 10*math.log10(S_av) #Signal level (in db)\n",
+ "\n",
+ "#Result\n",
+ "print \"The signal level at the receiver is\", round(S_av,5), \"or\", round(S_av_db), \"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The signal level at the receiver is 0.00041 or -34.0 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter6.ipynb b/Antennas_and_Wave_Propagation/chapter6.ipynb
new file mode 100644
index 00000000..040ba097
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter6.ipynb
@@ -0,0 +1,182 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 6: Electric Dipoles, Thin Linear Antennas \n",
+ " and Arrays of Dipoles and Apertures<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 6-8.1, Page number: 174"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "z = 333.0 #Driving point impedence (ohm)\n",
+ "r = 300.0 #twin-line impedence (ohm)\n",
+ "z1 = 73.0 #Self impedence of lambda/2 dipole (ohm)\n",
+ "z2 = 13.0 #Mutual impedence with lambda/2 spacing (ohm)\n",
+ "\n",
+ "#Calculation\n",
+ "pv = (z-r)/(z+r) #Reflection coefficient (unitless)\n",
+ "vswr = (1+pv)/(1-pv) #Voltage Standing Wave Ratio (unitless)\n",
+ "gain_l2 =math.sqrt((2*z1)/(z1-z2)) #Field gain over lambda/2 dipole (unitless)\n",
+ "gain_l2_db = 20*math.log10(gain_l2) #Field gain (in dB)\n",
+ "gain_iso = (gain_l2**2)*1.64 #Gain over isotropic source (unitless)\n",
+ "gain_iso_db = 10*math.log10(gain_iso) #Gain over isotropic source (in dB)\n",
+ "\n",
+ "#Result\n",
+ "print \"The VSWR is\", vswr\n",
+ "print \"The field gain over lambda/2 dipole is\", round(gain_l2,2), \"or\", round(gain_l2_db,1), \"dB\"\n",
+ "print \"\"\"The gain over isotropic source is %.1f or %.1f dB\n",
+ " \"\"\" % (round(gain_iso),gain_iso_db)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The VSWR is 1.11\n",
+ "The field gain over lambda/2 dipole is 1.56 or 3.9 dB\n",
+ "The gain over isotropic source is 4.0 or 6.0 dB\n",
+ " \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 6-8.2, Page number:175<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "z = 73.0 #Self impedence of lambda/2 dipole (ohm)\n",
+ "zm = 64.4 #Mutual impedence with lambda/8 spacing (ohm)\n",
+ "\n",
+ "#Calculation\n",
+ "D = math.sqrt((2*z)/(z-zm))*math.sin(math.pi/8) #Field gain over lambda/2 dipole (unitless)\n",
+ "D_db = 20*math.log10(D) #Field gain over lambda/2 dipole (in dB)\n",
+ "\n",
+ "gain_iso = (D**2)*1.64 #gain over isotropic source (unitless)\n",
+ "gain_iso_db = 10*math.log10(gain_iso) #gain over isotropic source (in dB)\n",
+ "\n",
+ "#Result\n",
+ "print \"The field gain over lambda/2 dipole is\", round(D,2), \"or\", round(D_db,2), \"dB\"\n",
+ "print \"The gain over isotropic source is\", round(gain_iso,2), \"or\", round(gain_iso_db,1), \"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The field gain over lambda/2 dipole is 1.58 or 3.96 dB\n",
+ "The gain over isotropic source is 4.08 or 6.1 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 6-12.1, Page number: 196<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt, log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "s1 = 0.4 #Spacing 1(lambda)\n",
+ "s2 = 0.5 #Spacing 2(lambda)\n",
+ "s3 = 0.6 #Spacing 3(lambda)\n",
+ "R_21_1 = 6.3 #Mutual resistance for s1 (ohm)\n",
+ "R_21_2 = -12.691 #Murual resistance for s2 (ohm)\n",
+ "R_21_3 = -23.381 #Mutual resistance for s3 (ohm) \n",
+ "Z = 73.13 #Self impedence of lambda/2 dipole (ohm)\n",
+ "\n",
+ "#Calculation\n",
+ "gain_1 = sqrt(2*(Z/(Z+R_21_1))) #Gain in fieldfor s1 (unitless)\n",
+ "gain_iso1 = 1.64*(gain_1**2) #Power gain over isotropic (unitless)\n",
+ "gain_iso_db1 = 10*log10(gain_iso1) #Power gain (in dBi)\n",
+ "\n",
+ "gain_2 = sqrt(2*(Z/(Z+R_21_2))) #Gain in fieldfor s2 (unitless)\n",
+ "gain_iso2 = 1.64*(gain_2**2) #Power gain over isotropic (unitless)\n",
+ "gain_iso_db2 = 10*log10(gain_iso2) #Power gain (in dBi)\n",
+ "\n",
+ "gain_3 = sqrt(2*(Z/(Z+R_21_3))) #Gain in fieldfor s3 (unitless)\n",
+ "gain_iso3 = 1.64*(gain_3**2) #Power gain over isotropic (unitless)\n",
+ "gain_iso_db3 = 10*log10(gain_iso3) #Power gain (in dBi)\n",
+ "\n",
+ "#Result\n",
+ "print \"The gain in field over half wave antenna for s1 is\", round(gain_1,2)\n",
+ "print \"\"\"The power gain over isotropic for s1 is %.2f or %.1f dBi\n",
+ " \"\"\" % (gain_iso1,gain_iso_db1)\n",
+ " \n",
+ "print \"The gain in field over half wave antenna for s2 is\", round(gain_2,2)\n",
+ "print \"\"\"The power gain over isotropic for s2 is %.2f or %.2f dBi\n",
+ " \"\"\" % (gain_iso2,gain_iso_db2)\n",
+ " \n",
+ "print \"The gain in field over half wave antenna for s3 is\", round(gain_3,2)\n",
+ "print \"\"\"The power gain over isotropic for s3 is %.2f or %.2f dBi\n",
+ " \"\"\" % (gain_iso3,gain_iso_db3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The gain in field over half wave antenna for s1 is 1.36\n",
+ "The power gain over isotropic for s1 is 3.02 or 4.8 dBi\n",
+ " \n",
+ "The gain in field over half wave antenna for s2 is 1.56\n",
+ "The power gain over isotropic for s2 is 3.97 or 5.99 dBi\n",
+ " \n",
+ "The gain in field over half wave antenna for s3 is 1.71\n",
+ "The power gain over isotropic for s3 is 4.82 or 6.83 dBi\n",
+ " \n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter7.ipynb b/Antennas_and_Wave_Propagation/chapter7.ipynb
new file mode 100644
index 00000000..6481c2bd
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter7.ipynb
@@ -0,0 +1,386 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 7: Loop, Slot and Horn Antennas<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 7-8.1, Page number: 256<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt,pi,sin,log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "C_lambda = 0.1*pi #Circumference (lambda)\n",
+ "R_m = 1.6 #Mutual resistance of two loops (ohm)\n",
+ "theta1 = 90*pi/180 #Angle of radiation (radians)\n",
+ "theta2 = 2*pi/10 #Angle of radiation (radians)\n",
+ "\n",
+ "#Calculation\n",
+ "Rr = 197*(C_lambda)**4 #Self resistance of loop (ohm)\n",
+ "D1 = (1.5)*(sin(theta1))**2 #Direcivity of loop alone (unitless)\n",
+ "D1_db = 10*log10(D1) #Directivity of loop alone (dBi)\n",
+ "D2 = 1.5*(2*sqrt(Rr/(Rr-R_m))*sin(theta2))**2\n",
+ " #Directivity of loop with ground plane (unitless)\n",
+ "D2_db = 10*log10(D2) #Direcitivy of loop with ground plane (dBi)\n",
+ "\n",
+ "#Result\n",
+ "print \"The directivity of loop alone is %.2f or %.2f dBi\" % (D1,D1_db)\n",
+ "print \"\"\"The direcitivy of loop with ground plane is %.2f or %.0f dBi\n",
+ " \"\"\" %(D2,D2_db)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The directivity of loop alone is 1.50 or 1.76 dBi\n",
+ "The direcitivy of loop with ground plane is 12.47 or 11 dBi\n",
+ " \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 7-8.2, Page number:257<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt, sin, pi, log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "Rr = 197.0 #self resistance of loop (ohm)\n",
+ "Rm = 157.0 #mutual resistance of two loops (ohm)\n",
+ "theta = 2*pi/10 #Angle of radiation (radians)\n",
+ "\n",
+ "#Calculation\n",
+ "D = 1.5*(2*sqrt(Rr/(Rr-Rm))*sin(theta))**2 #Directivity (unitless)\n",
+ "D_db = 10*log10(D) #Directivity (dBi)\n",
+ "\n",
+ "#Result\n",
+ "print \"The direcitivy is %.1f or %.1f dBi\" % (D,D_db)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The direcitivy is 10.2 or 10.1 dBi\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 7-11.1, Page number: 261<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi, log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "c = pi #Circumference (m)\n",
+ "f1 = 1 #Frequency (MHz)\n",
+ "f2 = 10 #Frequency (MHz)\n",
+ "d = 10e-3 #Diameter of copper wire (m)\n",
+ "\n",
+ "#Calcalation\n",
+ "RL_Rr1 = 3430/((c**3)*(f1**3.5)*d) \n",
+ "RL_Rr2 = 3430/((c**3)*(f2**3.5)*d)\n",
+ " #Ratio of Loss resistance and radiation resistance (unitless\n",
+ " \n",
+ "k1 = 1/(1+RL_Rr1) #Radiation efficiency (unitless)\n",
+ "k_db1 = 10*log10(k1) #Radiation efficiency (in dB)\n",
+ "k2 = 1/(1+RL_Rr2) #Radiation efficiency (unitless)\n",
+ "k_db2 = 10*log10(k2) #Radiation efficiency (in dB)\n",
+ "\n",
+ "#Result\n",
+ "print \"The radiation effiency for 1 MHz is %.1ef or %.1f dB\" % (k1, k_db1)\n",
+ "print \"The radiation effiency for 10 MHz is %.2f or %.1f dB\" % (k2, k_db2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The radiation effiency for 1 MHz is 9.0e-05f or -40.4 dB\n",
+ "The radiation effiency for 10 MHz is 0.22 or -6.5 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 7-11.2, Page number: 264</h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi,sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "n = 10 #Number of turns (unitless)\n",
+ "dia = 1e-3 #Diameter of copper wire (m)\n",
+ "dia_rod = 1e-2 #Diameter of ferrite rod (m)\n",
+ "len_rod = 10e-2 #Length of ferrite rod (m)\n",
+ "mu_r = 250 - 2.5j #Relative permeability (unitless)\n",
+ "mu_er = 50 #Efeective relative permeability (unitless)\n",
+ "f = 1e6 #Frequency (Hz)\n",
+ "c = 3e8 #Speed of light (m/s)\n",
+ "mu_0 = pi*4e-7 #Absolute permeability (H/m)\n",
+ "\n",
+ "#Calculations\n",
+ "wave_lt = c/f #Wavelength (m)\n",
+ "radius = dia_rod/2\n",
+ "C_l = (2*pi*radius)/(wave_lt) #Circumference of loop (m)\n",
+ "Rr = 197*(mu_er**2)*(n**2)*(C_l**4) #Radiation resistance (ohm)\n",
+ "Rf = 2*pi*f*mu_er*(mu_r.imag/mu_r.real)*mu_0*(n**2)*(pi*radius**2)/len_rod #Loss resistance(ohm)\n",
+ "cond = 1/((7e-5**2)*f*pi*mu_er) #Conductivity (S/m)\n",
+ "delta = 1/(sqrt(f*pi*mu_er*cond)) #Depth of penetration(m)\n",
+ "\n",
+ "RL = n*(C_l/dia)*sqrt((f*mu_0)/(pi*cond)) #Ohmic resistance (ohm)\n",
+ "k = Rr/(RL+abs(Rf)) #Radiation efficiency (unitless)\n",
+ "\n",
+ "L = mu_er*(n**2)*(radius**2)*mu_0/len_rod #Inductance (H)\n",
+ "Q = 2*pi*f*L/(abs(Rf) + Rr + RL) #Ratio of energy stored to energy lost per cycle (unitless)\n",
+ "\n",
+ "fHP = f/Q #Bandwidth at half power (Hz)\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print \"The radiation efficiency is \", round(k,11)\n",
+ "print \"The value of Q is \", round(Q,3)\n",
+ "print \"The half-power bandwidth is\", round(fHP), \"Hz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The radiation efficiency is 6.65e-09\n",
+ "The value of Q is 11.076\n",
+ "The half-power bandwidth is 90289.0 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 7-17.1, Page number: 280<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "Z0 = 376.7 #Intrinsic impdence of free space (ohm)\n",
+ "Zd = 73 + 42.5j #Impedence of infinitesimally thin lambda/2 antenna (ohm)\n",
+ "\n",
+ "#Calculation\n",
+ "Z1 = (Z0**2)/(4*Zd) #Terminal impedence of the lambda/2 slot antenna (ohm)\n",
+ "\n",
+ "#Result\n",
+ "print \"The terminal impedence of the thin lambda/2 slot antenna is\", np.around(Z1), \"ohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The terminal impedence of the thin lambda/2 slot antenna is "
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(363-211j) ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 7-17.2, Page number: 280<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "Zd = 67 #Terminal impedence of cylindrical antenna (ohm)\n",
+ "Z0 = 376.7 #Intrinsic impedence of free space (ohm)\n",
+ "L = 0.475 #Length of complementary slot (lambda)\n",
+ "\n",
+ "#Calculation\n",
+ "Z1 = Z0**2/(4*Zd) #Terminal resistance of complementary slot (ohm)\n",
+ "w = 2*L/100 #Width of complementary slot (lambda)\n",
+ "\n",
+ "#Result\n",
+ "print \"The terminal resistance of the complementary slot is\", round(Z1), \"ohm\"\n",
+ "print \"The width of the complementary slot is\", w, \"lambda\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The terminal resistance of the complementary slot is 529.0 ohm\n",
+ "The width of the complementary slot is 0.0095 lambda\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 7-17.3, Page number: 281<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "Zd = 710 #Terminal impdence of cylindrical dipole\n",
+ "Z0 = 376.7 #Intrinsic impedence of free space (ohm)\n",
+ "\n",
+ "#Calculation\n",
+ "Z1 = Z0**2/(4*Zd) #Terminal resistance of complementary slot (ohm)\n",
+ "\n",
+ "#Result\n",
+ "print \"The terminal resistance of the complementary slot is\", round(Z1),\"ohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The terminal resistance of the complementary slot is 50.0 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 7-20.1, Page number 288<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "delta_e = 0.2 #path length difference in E-plane (lambda)\n",
+ "delta_h = 0.375 #path length difference in H-plane (lambda)\n",
+ "a_e = 10 #E-plane aperture (lambda)\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "L = a_e**2/(8*delta_e) #Horn length(lambda)\n",
+ "theta_e = 2*math.atan2(a_e,2*L)*180/math.pi #Flare angle in E-plane (degrees)\n",
+ "theta_h = 2*math.acos(L/(L+delta_h))*180/math.pi\n",
+ " #Flare angle in the H-plane (degrees)\n",
+ "a_h = 2*L*math.tan(theta_h/2*math.pi/180) #H-plane aperture (lambda)\n",
+ "\n",
+ "hpbw_e = 56/a_e #Half power beamwidth in E-plane (degrees)\n",
+ "hpbw_h = 67/a_h #Half power beamwidth in H-plane (degrees)\n",
+ "\n",
+ "D = 10*math.log10(7.5*a_e*a_h) #Directivity (dB)\n",
+ "\n",
+ "#Result\n",
+ "print \"The length of the pyramidal horn is\", L,\"lambda\"\n",
+ "print \"The flare angles in E-plane and H-plane are\", round(theta_e,1),\"and\", round(theta_h,2), \"degrees\"\n",
+ "print \"The H-plane aperture is\", round(a_h,1), \"lambda\"\n",
+ "print \"The Half power beamwidths in E-plane and H-plane are\", hpbw_e,\"&\",round(hpbw_h,1),\\\n",
+ "\"degrees\"\n",
+ "print \"The direcivity is\", round(D,1),\"dBi\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The length of the pyramidal horn is 62.5 lambda\n",
+ "The flare angles in E-plane and H-plane are 9.1 and 12.52 degrees\n",
+ "The H-plane aperture is 13.7 lambda\n",
+ "The Half power beamwidths in E-plane and H-plane are 5 & 4.9 degrees\n",
+ "The direcivity is 30.1 dBi\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter8.ipynb b/Antennas_and_Wave_Propagation/chapter8.ipynb
new file mode 100644
index 00000000..3c5e8930
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter8.ipynb
@@ -0,0 +1,192 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 8: Helical Antennas<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 8-5.1, Page number: 309<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "w = 5 #Width of flattened tubing at termination (mm)\n",
+ "Er = 2.7 #Relative permittivity of the sheet\n",
+ "Z0 = 50 #Characteristic impdence of the sheet\n",
+ "\n",
+ "#Calculation\n",
+ "h = w/((377/(sqrt(Er)*Z0))-2)\n",
+ "\n",
+ "#Result\n",
+ "print \"The required thickness of the polystyrene sheet is\", round(h,1),\"mm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The required thickness of the polystyrene sheet is 1.9 mm\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 8-5.2, Page number:315<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt, log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "n = 16.0 #Number of turns (unitless)\n",
+ "C = 1 #Circumference (lambda)\n",
+ "S = 0.25 #Turn Spacing (lambda)\n",
+ "\n",
+ "#Calculation\n",
+ "hpbw = 52/(C*sqrt(n*S)) #Half power beamwidth (degrees)\n",
+ "ax_rat = (2*n + 1)/(2*n) #Axial ratio (unitless)\n",
+ "gain = 12*(C**2)*n*S #Gain of antenna (unitless)\n",
+ "gain_db = 10*log10(gain) #Gain of antenna (in dBi)\n",
+ "\n",
+ "print \"The half power beam width is\", hpbw, \"degrees\"\n",
+ "print \"The axial ratio is\", round(ax_rat,2)\n",
+ "print \"The gain is\", gain,\"or\",round(gain_db,1),\"dBi\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The half power beam width is 26.0 degrees\n",
+ "The axial ratio is 1.03\n",
+ "The gain is 48.0 or 16.8 dBi\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 8-5.3, Page number:316<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi, sqrt, log10\n",
+ "\n",
+ "#Variable declaration\n",
+ "n = 10.0 #Number of turns (unitless)\n",
+ "S = 0.236 #Spacing between turns (lambda)\n",
+ "n_a = 4.0 #Number of helical antennas in the array (unitless)\n",
+ "\n",
+ "#Calculation\n",
+ "D = 12*n*S #Directivity of a single antenna(unitless)\n",
+ "Ae = D/(4*pi) #Effective aperture (lambda^2)\n",
+ "\n",
+ "A = sqrt(Ae) #Area of square/spacing between helixes (lambda)\n",
+ "Ae_total = Ae*n_a #Total effective aperture (lambda^2)\n",
+ "D_array = (4*pi*Ae_total) #Directivity of the array (unitless)\n",
+ "D_array_db = 10*log10(D_array) #Direcitivity of the array (dBi)\n",
+ "\n",
+ "#Result\n",
+ "print \"The best spacing between the helixes is\", round(A,1), \"lambda\"\n",
+ "print \"The directivity of the array is\", round(D_array),\"or\",round(D_array_db,1),\"dBi\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The best spacing between the helixes is 1.5 lambda\n",
+ "The directivity of the array is 113.0 or 20.5 dBi\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 8-16.1, Page number:347<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi\n",
+ "\n",
+ "#Variable declaration\n",
+ "gain = 24.0 #Gain (dB)\n",
+ "alpha = 12.7 #Pitch angle (degrees)\n",
+ "c_lambda = 1.05 #Circumference (lambda)\n",
+ "s_lambda = 0.236 #Spacing between turns (lambda)\n",
+ "\n",
+ "#Calculation\n",
+ "D = 10**(gain/10) #Directivity (unitless)\n",
+ "L = D/(12*(c_lambda**2)) #Helix length (lambda)\n",
+ "n = L/s_lambda #Number of turns (unitless)\n",
+ "D = D/4 #Directivity for four 20-turn helixes(unitless)\n",
+ "Ae = D/(4*pi) #Effective aperture of each helix (lambda^2)\n",
+ "\n",
+ "#Result\n",
+ "print \"The Axial length is\", round(L),\"lambda\"\n",
+ "print \"The number of turns for the axial length is\",round(n)\n",
+ "print \"The effective aperture for 20 turns is\",round(Ae),\"lambda^2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Axial length is 19.0 lambda\n",
+ "The number of turns for the axial length is 80.0\n",
+ "The effective aperture for 20 turns is 5.0 lambda^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/chapter9.ipynb b/Antennas_and_Wave_Propagation/chapter9.ipynb
new file mode 100644
index 00000000..72d11c5d
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/chapter9.ipynb
@@ -0,0 +1,65 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 9: Reflector Antennas<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 9-2.1, Page number: 372<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import pi,sqrt\n",
+ "\n",
+ "#Variable declaration\n",
+ "P_transmit = 25000.0 #Power transmitted by station transmitter (W)\n",
+ "gain_dbi = 29.0 #Gain of array (dBi)\n",
+ "r = 7500e3 #Distance (m)\n",
+ "h = 250e3 #Height (m)\n",
+ "z = 377.0 #Intrinsic impedence of free space (ohm)\n",
+ "\n",
+ "#Calculation\n",
+ "gain = 10**(gain_dbi/10) #Gain of array (unitless)\n",
+ "erp = gain*P_transmit #Effective radiated power (W)\n",
+ "p_area = erp/(2*pi*r*h) #power per unit area at distance r (W/m^2)\n",
+ "field_str = sqrt(p_area*z) #Field strength (mV/m)\n",
+ "\n",
+ "#Result\n",
+ "print \"The effective radiated power is\", round(erp,-5),\"W\"\n",
+ "print \"The field strength at the distance r is \",round(field_str,3), \"V/m^2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The effective radiated power is 19900000.0 W\n",
+ "The field strength at the distance r is 0.025 V/m^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Antennas_and_Wave_Propagation/screenshots/snapshot1.png b/Antennas_and_Wave_Propagation/screenshots/snapshot1.png
new file mode 100644
index 00000000..b06c2235
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/screenshots/snapshot1.png
Binary files differ
diff --git a/Antennas_and_Wave_Propagation/screenshots/snapshot2.png b/Antennas_and_Wave_Propagation/screenshots/snapshot2.png
new file mode 100644
index 00000000..79b38b7b
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/screenshots/snapshot2.png
Binary files differ
diff --git a/Antennas_and_Wave_Propagation/screenshots/snapshot3.png b/Antennas_and_Wave_Propagation/screenshots/snapshot3.png
new file mode 100644
index 00000000..f88bcebb
--- /dev/null
+++ b/Antennas_and_Wave_Propagation/screenshots/snapshot3.png
Binary files differ
diff --git a/Fluid_Mechanics_With_Engineering_Applications/README.txt b/Fluid_Mechanics_With_Engineering_Applications/README.txt
new file mode 100644
index 00000000..9c04be12
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Saurabh Barot
+Course: mtech
+College/Institute/Organization: Nirma University
+Department/Designation: Electrical Power System
+Book Title: Fluid Mechanics With Engineering Applications
+Author: R. L. A. Daugherty And J. B. A. Franzini
+Publisher: McGraw - Hill
+Year of publication: 1985
+Isbn: 0076662673
+Edition: 8 \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch1.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch1.ipynb
new file mode 100644
index 00000000..f2d43060
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch1.ipynb
@@ -0,0 +1,184 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:927dbb23c2c4eb2bcfe9867be6353aeb4f4fc6596109258987a73bb6dbc2e748"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1 : Properties Of Fluids"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.1 Page No : 4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "sw = 62.4 \t#specific weight of water at ordinary pressure - lb/ft**3\n",
+ "sw2 = 9.81 \t#specific weight of water at temperature - kN/m**3\n",
+ "sg = 13.55 \t#specific weight of mercury \n",
+ "g = 32.2 \t#ft/s**2\n",
+ "\t\n",
+ "#calculations\n",
+ "dwater = sw/g\n",
+ "dwater2 = sw2/(9.81)\n",
+ "Gmercury = sg*sw\n",
+ "Gmercury2 = sg*sw2\n",
+ "dmercury = sg*dwater\n",
+ "dmercury2 = sg*dwater2\n",
+ "\t\n",
+ "#Results\n",
+ "print 'Density of water = %.2f slugs/ft**3'%(dwater)\n",
+ "print ' Density of water = %.2f g/ml'%(dwater2)\n",
+ "print ' Density of mercury = %.1f slugs/ft**3'%(dmercury)\n",
+ "print ' Density of mercury = %.2f kN/m**3'%(dmercury2)\n",
+ "print ' Specific weight of mercury = %d lb/ft**3'%(Gmercury+1)\n",
+ "print ' Specific weight of mercury = %d kN/m**3'%(Gmercury2+1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Density of water = 1.94 slugs/ft**3\n",
+ " Density of water = 1.00 g/ml\n",
+ " Density of mercury = 26.3 slugs/ft**3\n",
+ " Density of mercury = 13.55 kN/m**3\n",
+ " Specific weight of mercury = 846 lb/ft**3\n",
+ " Specific weight of mercury = 133 kN/m**3\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.2 Page No : 9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "T = 460.+100 \t#R\n",
+ "P = 15. \t#psia\n",
+ "MW = 32. \t#lb\n",
+ "g = 32.2\t #ft/s**2\n",
+ "ratio = 0.4\n",
+ "\t\n",
+ "#calculations\n",
+ "R = 49710./32\n",
+ "d = P*144/(R*T)\n",
+ "Gamma = d*g\n",
+ "volume = 1/d\n",
+ "P2 = P*(1/ratio)**1.4\n",
+ "P2f = P2*144\n",
+ "T2 = P2f*ratio/(d*R) -460\n",
+ "P3 = P/ratio\n",
+ "\t\n",
+ "#Results\n",
+ "print ' part a'\n",
+ "print ' Density of oxygen = %.5f slug/ft**3'%(d)\n",
+ "print ' Specific weight of oxygen = %.2f lb/ft**3'%(Gamma)\n",
+ "print ' Specific volume of oxygen = %d ft**3/slug'%(volume+1)\n",
+ "print ' part b'\n",
+ "print ' Final pressure of oxygen = %.1f psia '%(P2)\n",
+ "print ' Final Temperature of oxygen = %d F '%(T2+2)\n",
+ "print ' part 3'\n",
+ "print ' Final pressure of oxygen = %.1f psia '%(P3)\n",
+ "print ' Final Temperature of oxygen = %d F '%(T-460)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " part a\n",
+ " Density of oxygen = 0.00248 slug/ft**3\n",
+ " Specific weight of oxygen = 0.08 lb/ft**3\n",
+ " Specific volume of oxygen = 403 ft**3/slug\n",
+ " part b\n",
+ " Final pressure of oxygen = 54.1 psia \n",
+ " Final Temperature of oxygen = 349 F \n",
+ " part 3\n",
+ " Final pressure of oxygen = 37.5 psia \n",
+ " Final Temperature of oxygen = 100 F \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.3 Page No : 10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "P = 600.*1000 \t#N/m**2\n",
+ "T = 25. \t#C\n",
+ "M = 71. \t #Kg\n",
+ "\t\n",
+ "#calculations\n",
+ "R = 8312/M\n",
+ "d = P/(R*(273+T))\n",
+ "Gamma = d*9.81\n",
+ "v = 1/d\n",
+ "\n",
+ "# results\n",
+ "print 'Density of chlorine = %.1f kg/m**3'%(d)\n",
+ "print ' Specific weight of chlorine = %d N/m**3'%(Gamma+1)\n",
+ "print ' Specific volume of chlorine = %.3f m**3/Kg'%(v)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Density of chlorine = 17.2 kg/m**3\n",
+ " Specific weight of chlorine = 169 N/m**3\n",
+ " Specific volume of chlorine = 0.058 m**3/Kg\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch10.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch10.ipynb
new file mode 100644
index 00000000..87e81c80
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch10.ipynb
@@ -0,0 +1,455 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d2599cf416e0a07710e4c3d128cbc7fa43fd432b07cfc1f586c709ffa82e3638"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10 : Forces on Immersed Bodies"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.1 Page No : 301"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "nu = 0.001 \t#ft**2 /s\n",
+ "L = 1.5 \t#ft\n",
+ "U = 2. \t#ft/s\n",
+ "s = 0.925\n",
+ "ro = 1.94\n",
+ "b = 6.\n",
+ "\t\n",
+ "#calculations\n",
+ "R = L*U/nu\n",
+ "Cf = 1.328/math.sqrt(R)\n",
+ "Ff = Cf*s*ro*U*b/12 *L\n",
+ "delta = 4.91 *L/math.sqrt(R)\n",
+ "T0 = 0.332*nu*s*ro*U/L *math.sqrt(R)\n",
+ "print R\n",
+ "#Results\n",
+ "print \"Friction drag = %.3f lb\"%(Ff)\n",
+ "print \" Thickness of boundary layer = %.4f ft\"%(delta)\n",
+ "print \" Shear stress = %.4f lb/ft**2\"%(T0)\n",
+ "\n",
+ "#Similar calculations are done for SI units case"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3000.0\n",
+ "Friction drag = 0.065 lb\n",
+ " Thickness of boundary layer = 0.1345 ft\n",
+ " Shear stress = 0.0435 lb/ft**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.2 Page No : 305"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "nu = 0.00015 \t#ft**2/s\n",
+ "L = 35. \t#ft\n",
+ "U = 88. \t#fps\n",
+ "g = 32.2 \t#ft/s**2\n",
+ "b = 10. \t #ft\n",
+ "w = 8. \t#ft\n",
+ "rho = 0.0725\n",
+ "\t\n",
+ "#calculations\n",
+ "R = L*U/nu\n",
+ "Cf = 0.455 /(math.log10(R))**2.58\n",
+ "B = 2*b + w\n",
+ "Ff = Cf*rho/g *U**2 /2 *L*B\n",
+ "Rx = R/10**5\n",
+ "delta = L*0.377 /(b* Rx**(0.2))\n",
+ "T0 = 0.0587 *rho/g *U**2 /2 *(nu/(L*U))**(0.2)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Frictional drag = %.1f lb\"%(Ff)\n",
+ "print \" Thickness of boundary layer = %.3f ft\"%(delta)\n",
+ "print \" Shear stress = %.4f lb/ft**2\"%(T0)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frictional drag = 22.9 lb\n",
+ " Thickness of boundary layer = 0.455 ft\n",
+ " Shear stress = 0.0176 lb/ft**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.3 Page No : 308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "nu = 0.0000166 \t#ft**2 /s\n",
+ "U = 5.06 \t#fps\n",
+ "L = 50. \t#ft\n",
+ "g = 32.2\n",
+ "dia = 10. \t#ft\n",
+ "\t\n",
+ "#calculations\n",
+ "R = L*U/nu\n",
+ "Cf = 0.0028\n",
+ "Ff = Cf*64/g *U**2 /2 *math.pi*dia*L\n",
+ "Rx = R/L\n",
+ "ec = 26*nu/U *Rx**(0.25)\n",
+ "Rx2 = Rx*L/2\n",
+ "T02 = 0.0587*U**2 /2 /(Rx2)**(0.2)\n",
+ "delta2 = 60*nu/math.sqrt(T02)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Friction drag = %.f lb\"%(Ff)\n",
+ "print \" Critical roughness = %.4f ft\"%(ec)\n",
+ "print \" height of roughness = %.4f ft\"%(delta2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Friction drag = 112 lb\n",
+ " Critical roughness = 0.0020 ft\n",
+ " height of roughness = 0.0056 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.4 Page No : 314"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "Cd = 0.45\n",
+ "rho = 0.0725/32.2\n",
+ "V = 88. \t#fps\n",
+ "A = 8*10.\n",
+ "\t\n",
+ "#calculations\n",
+ "Fd = Cd*rho*V**2 /2 *A\n",
+ "Drag2 = 23\n",
+ "D = Fd-Drag2\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Pressure drag = %.f lb\"%(D)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pressure drag = 291 lb\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.5 Page No : 315"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import Symbol,solve\n",
+ "import math\n",
+ "\n",
+ "#Initialization of variables\n",
+ "Cd = 0.2\n",
+ "D = 8.5/12 \t#in\n",
+ "v = 1.57*10**-4\n",
+ "rho = 0.00238\n",
+ "\t\n",
+ "#calculations\n",
+ "A = (math.pi*D**2)/4\n",
+ "#From trail and error method,\n",
+ "V = 412 \t#fps\n",
+ "R = (D*V)/v\n",
+ "\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Free fall velocity = %.2e fps\"%(R)\n",
+ "print \"Since the values of R and Cd check with the figure, V = 412 fps\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Free fall velocity = 1.86e+06 fps\n",
+ "Since the values of R and Cd check with the figure, V = 412 fps\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.6 Page No : 319"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "nu = 1.15*10**-5 \t#m**2/s\n",
+ "D = 2.*10**-3 \t #m\n",
+ "V = 15. \t#m/s\n",
+ "T = -20. \t #C\n",
+ "\t\n",
+ "#calculations\n",
+ "R = D*V/nu\n",
+ "f = 0.2 *V/D *(1+T/R)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Frequency of oscillation = %d Hz\"%(round(f,-2))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frequency of oscillation = 1500 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.7 Page No : 324"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "n = 90. \t#rpm\n",
+ "R = 2. \n",
+ "rho = 0.0765/32.2\n",
+ "B = 25.\n",
+ "U = 120. \t#fps\n",
+ "\t\n",
+ "#calculations\n",
+ "vt = 2*math.pi*R*n/60\n",
+ "T = 2*math.pi*R*vt\n",
+ "Fl = rho*B*U*T\n",
+ "theta = math.degrees(math.asin(-T/(4*math.pi*R*U)))\n",
+ "\n",
+ "#Results\n",
+ "print \"Peripheral velocity = %.2f fpx\"%vt\n",
+ "print \"Value of circulation = %.f ft62/s\"%(T)\n",
+ "print \" Transverse or lift force = %d lb\"%(round(Fl,-1))\n",
+ "print \" Position of stagnation points = %.1f degrees\"%(180-theta)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Peripheral velocity = 18.85 fpx\n",
+ "Value of circulation = 237 ft62/s\n",
+ " Transverse or lift force = 1690 lb\n",
+ " Position of stagnation points = 184.5 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.8 Page No : 331"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "B = 36. \t#ft\n",
+ "c = 6. \t#ft\n",
+ "Cl = 0.8\n",
+ "tau = 0.175 \n",
+ "rho = 0.001756\n",
+ "V = 300. \t#fps\n",
+ "\t\n",
+ "#calculations\n",
+ "alphai = Cl/(math.pi*B/c) *(1+tau) *180/math.pi\n",
+ "alpha = 5.4 \n",
+ "lift = -5.6 \t#degrees\n",
+ "alphao = alpha-alphai\n",
+ "alphaod = alphao-lift\n",
+ "alphaor = alphaod*math.pi/180\n",
+ "eta = Cl/(2*math.pi*alphaor)\n",
+ "Fl = Cl*rho*V**2 /2 *B*c\n",
+ "Fd = 0.047/Cl *13680\n",
+ "HP = Fd*V/550\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Friction coefficient = %.3f \"%(eta)\n",
+ "print \" weight of the wing = %d lb\"%(round(Fl,-1))\n",
+ "print \" Horsepower required = %d hp\"%(HP)\n",
+ "\n",
+ "# rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Friction coefficient = 0.896 \n",
+ " weight of the wing = 13650 lb\n",
+ " Horsepower required = 438 hp\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.9 Page No : 334"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "k = 1.4\n",
+ "R = 287.\n",
+ "T = 249. \t#K\n",
+ "v = 600. \t#velocity - m/s\n",
+ "d = 0.2 \t#diameter - m\n",
+ "\t\n",
+ "#calculations\n",
+ "c = math.sqrt(k*R*T)\n",
+ "M = v/c\n",
+ "Cd = 0.62\n",
+ "rho = 47.22*10**3 /(R*T)\n",
+ "Fd = Cd*rho*v**2 /2 *math.pi*d**2 /4\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Drag = %d N\"%(Fd)\n",
+ "\n",
+ "# note : answer is accurate"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Drag = 2316 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch11.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch11.ipynb
new file mode 100644
index 00000000..f9ba8a6b
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch11.ipynb
@@ -0,0 +1,256 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:0a4301c920a86f7888d81f22a80d24105313c5ae1dd42947a9f33bfe49dcea1b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11 : Steady Flow in Open Channels"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.1 Page No : 348"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "y = 3.4 \t#ft\n",
+ "n = 0.016\n",
+ "\t\n",
+ "#calculations\n",
+ "A = (10+2*y)*y\n",
+ "P = 10+ 2*math.sqrt(5) *y\n",
+ "Rh = A/P\n",
+ "f = 116*n**2 /Rh**(1./3)\n",
+ "e = 14.8*Rh/ 10**(1./2/math.sqrt(f))\n",
+ "\t\n",
+ "#Results\n",
+ "print \"absolute roughness of pipe = %.4f ft\"%(e)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "absolute roughness of pipe = 0.0159 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.2 Page No : 362"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "y = 1.495 \t#ft\n",
+ "Q = 14. \t#cfs\n",
+ "g = 32.2\n",
+ "\t\n",
+ "#calculations\n",
+ "yc = (Q**2 /g *2)**(1./5)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"yc = %.2f ft is greater than uniform flow depth. Hence flow is supercritical\"%(yc)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "yc = 1.65 ft is greater than uniform flow depth. Hence flow is supercritical\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.3 Page No : 366"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "q = 27./4\n",
+ "g = 32.2\n",
+ "Q = 27. \t#cfs\n",
+ "d = 2. \t#ft\n",
+ "dz1 = 0.3 \t#ft\n",
+ "\t\n",
+ "#calculations\n",
+ "yc = (q**2 /g)**(1./3)\n",
+ "V2 = Q/(4*yc)\n",
+ "V1 = Q/(4*d)\n",
+ "dz = d+ V1**2 /(2*g) - V2**2/(2*g) - yc\n",
+ "y2 = 1.6 \t#ft\n",
+ "drop = d-(y2+dz1)\n",
+ "dz2 = 0.6 \t#ft\n",
+ "up = 2.12 \t#ft\n",
+ "down = 0.66 \t#ft\n",
+ "\t\n",
+ "#Results\n",
+ "print \"yc = %.2f ft. Since, depth is greater than critical depth, the flow is subcritical\"%(yc)\n",
+ "print \" Drop in water height = %.2f ft\"%(drop)\n",
+ "print \" Drop upstream = %.2f ft and Downstream = %.2f ft\"%(up,down)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "yc = 1.12 ft. Since, depth is greater than critical depth, the flow is subcritical\n",
+ " Drop in water height = 0.10 ft\n",
+ " Drop upstream = 2.12 ft and Downstream = 0.66 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.5 Page No : 381"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "y0 = 2.17 \t#ft\n",
+ "q = 400./10 #flow rate\n",
+ "g = 32.2\n",
+ "d = 4.8 \t#ft\n",
+ "S0 = 0.0016\n",
+ "\t\n",
+ "#calculations\n",
+ "yc = round((q**2 /g)**(1./3),2)\n",
+ "y2 = round(y0/2 *(-1 + math.sqrt(1+ 8*q**2 /(g*y0**3))),2)\n",
+ "y1 = round(d/2 *(-1 + math.sqrt(1+ 8*q**2/(g*d**3))),2)\n",
+ "E1 = round(y0 + (q/y0)**2 /(2*g),2)\n",
+ "E2 = round(y1+ (q/y1)**2 /(2*g),2)\n",
+ "Vm = 0.5*(q/y0 + q/y1)\n",
+ "Rm = 0.5*(y0/1.434 + y1/1.552)\n",
+ "S = (0.013*Vm/(1.49*Rm**(2./3)))**2\n",
+ "dx = (E1-E2)/(S-S0)\n",
+ "E1d = E2\n",
+ "E2d = d+ (q/4.8)**2 /(2*g)\n",
+ "HPl = 62.4*q*10*(E1d-E2d)/550\n",
+ "\n",
+ "#Results\n",
+ "print \"Power loss = %.2f \"%(HPl)\n",
+ "#The answer is a bit different from the textbook due to rounding off error\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Power loss = 7.79 \n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.6 Page No : 386"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import *\n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "y1 = array([1.5, 1.48])\n",
+ "V1 = array([2.22, 2.29])\n",
+ "d = 1.2\n",
+ "\t\n",
+ "#calculations\n",
+ "q = y1*V1\n",
+ "V2 = q/d\n",
+ "Vm = array([2.5, 2.56])\n",
+ "Rh1 = array([0.9, 0.89])\n",
+ "Rh2 = array([0.88, 0.78])\n",
+ "Rhm = (Rh1+Rh2)/2\n",
+ "S = (q*Vm/ Rhm**(2./3))**2\n",
+ "dx = [358 ,226]\n",
+ "yavg = (y1[0] + y1[1])/2\n",
+ "qavg = (q[0] + q[1])/2\n",
+ "B = 4.5\n",
+ "Q = qavg*B\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Flow rate = %.1f m**3/s\"%(Q)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Flow rate = 15.1 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch12.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch12.ipynb
new file mode 100644
index 00000000..6e1ff052
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch12.ipynb
@@ -0,0 +1,210 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:8b08667e1cca98a07d013ad939243dc9add7485e8e9e19c3e7221c1a62e2d3d1"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12 : Fluid Measurements"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.1 Page No : 417"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "P1 = 10. \t#psia\n",
+ "Q = 0.6 \t#cfs\n",
+ "A1 = 0.0491 #ft**2\n",
+ "g = 32.2\n",
+ "V = 39.2\t#fps\n",
+ "A0 = 0.0218 #ft**2\n",
+ "d1 = 2. \t#in\n",
+ "d2 = 3. \t#in\n",
+ "\t\n",
+ "#calculations\n",
+ "Phead = P1*144/62.4\n",
+ "V1 = Q/A1\n",
+ "V2i = math.sqrt(2*g*(Phead + V1**2 /(2*g)))\n",
+ "Cv = V/V2i\n",
+ "A2 = Q/V\n",
+ "Cc = A2/A0\n",
+ "Cd = Cc*Cv\n",
+ "hL = (1/Cv**2 -1)*(1- (d1/d2)**4)*V**2 /(2*g)\n",
+ "\t\n",
+ "#Results\n",
+ "print \" Cc = %.2f \"%(Cc)\n",
+ "print \" Cd = %.2f\"%(Cd)\n",
+ "print \" Cv = %.2f\"%(Cv)\n",
+ "print \" Head loss = %.2f ft\"%(hL)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Cc = 0.70 \n",
+ " Cd = 0.68\n",
+ " Cv = 0.97\n",
+ " Head loss = 1.23 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.2 Page No : 425"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "d = 2. \t#in\n",
+ "g = 32.2\n",
+ "d1 = 3. \t#in\n",
+ "k = 1.06\n",
+ "\t\n",
+ "#calculations\n",
+ "A2 = math.pi/4 *d**2 /144\n",
+ "dp = d/12\n",
+ "Q = k*A2*math.sqrt(2*g*dp)\n",
+ "A = math.pi/4 *(d1/12)**2\n",
+ "V1 = Q/A\n",
+ "K2 = 1.04\n",
+ "Q2 = K2/k *Q\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Flow rate = %.4f cfs\"%(Q2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Flow rate = 0.0743 cfs\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.3 Page No : 428"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "P1 = 700. \t#kN/m**2\n",
+ "P2 = 400. \t#kN/m**2\n",
+ "D2 = 12.5 \t#cm\n",
+ "D1 = 25. \t#cm\n",
+ "C = 0.985\n",
+ "g = 9.81\n",
+ "R = 287. \t#m**2/s**2 K\n",
+ "T = 273.+20 \t#K\n",
+ "\t\n",
+ "#calculations\n",
+ "Pr = P2/P1\n",
+ "Dr = D2/D1\n",
+ "Y = 0.72\n",
+ "gam1 = P1*g/(R*T)\n",
+ "G = C*Y*math.pi/4 *(D2/100)**2 *math.sqrt(2*g*gam1*(P1-P2)/(1- Dr**4))\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Weight flow rate = %.4f kN/s\"%(G)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Weight flow rate = 0.1971 kN/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.4 Page No : 432"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "V = 3. \t#fps\n",
+ "y = 1. \t#ft\n",
+ "L = 4. \t#ft\n",
+ "\t\n",
+ "#calculations\n",
+ "H = (V*y/3.33)**(2./3)\n",
+ "P = L-H\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Height of weir = %.2f ft\"%(P)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Height of weir = 3.07 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch13.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch13.ipynb
new file mode 100644
index 00000000..c094073c
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch13.ipynb
@@ -0,0 +1,223 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:57afc22e72f8124575cf49b21448070d3e8a0ab91ff492996411fc02ec3e922d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13 : Unsteady-Flow Problems"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.1 Page No : 449"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "ken = 0.5\n",
+ "kex = 0.2\n",
+ "f = 0.0018\n",
+ "l = 10. \t#ft\n",
+ "dia = 3. \t#in\n",
+ "z1 = 8.\n",
+ "z2 = 5.\n",
+ "\t\n",
+ "#calculations\n",
+ "x1 = ken+kex+f*l*12/dia\n",
+ "t = 35.5*2/3 *(z1**(3./2) - z2**(3./2))\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Time reqired = %.f s\"%(t)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time reqired = 271 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.2 Page No : 451"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "print (\"For steady state, dV/dt = 0\")\n",
+ "Q = 1600./449 #steady flow rate\n",
+ "A2 = 0.1963\n",
+ "g = 32.2\n",
+ "rp2 = 2000. #speed of rotation - rpm\n",
+ "\t\n",
+ "#calculations\n",
+ "V2 = Q/A2\n",
+ "hp1 = 32*V2**2 /(2*g) -50\n",
+ "hp2 = hp1*(rp2/1650)**2\n",
+ "hpf = 169. \t#ft\n",
+ "Q = 4.1 \t#cfs\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Steady state flow rate = %.2f cfs\"%(Q)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For steady state, dV/dt = 0\n",
+ "Steady state flow rate = 4.10 cfs\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.3 Page No : 455"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from numpy import *\n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "kl = 0.5\n",
+ "f = 0.02\n",
+ "L = 15. \t#length - m\n",
+ "D = 0.1 \t#ft\n",
+ "k = 3.5\n",
+ "g = 9.81\n",
+ "H = 2.\t#ft\n",
+ "\t\n",
+ "#calculations\n",
+ "k = kl+f*L/D\n",
+ "V0 = math.sqrt(2*g*H/(1+k))\n",
+ "Q = array([0.25, 0.5, 0.75])\n",
+ "V = V0*Q\n",
+ "Vfun = (2.95+V)/(2.95-V)\n",
+ "lnVfun = log(Vfun)\n",
+ "t = 1.129*lnVfun\n",
+ "\n",
+ "print \"ln t,s\"\n",
+ "#Results\n",
+ "for i in range(len(t)):\n",
+ " print \"%.3f %.3f\"%(lnVfun[i],t[i])\n",
+ "\n",
+ "print (\"Similarly, it can be calculated for L = 150,1500 ft\")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ln t,s\n",
+ "0.511 0.577\n",
+ "1.100 1.242\n",
+ "1.949 2.201\n",
+ "Similarly, it can be calculated for L = 150,1500 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.4 Page No : 462"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "Q = 30. \t#cfs\n",
+ "r = 2. \t#ft\n",
+ "cp = 3200.\n",
+ "rho = 1.94\n",
+ "Q2 = 10. \t#cfs\n",
+ "z = 300. \t#ft\n",
+ "\t\n",
+ "#calculations\n",
+ "V = Q/(math.pi*r**2)\n",
+ "ph = rho*cp*V/144\n",
+ "phd = 4000/cp /(2*r) *ph\n",
+ "dV = (Q2-Q)/(math.pi*r**2)\n",
+ "dph = -rho*cp*dV/144\n",
+ "ph3 = rho*cp*V/3 /144\n",
+ "ph4 = ph3*z*2/cp\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Water hammer pressure = %.1f psi\"%(ph)\n",
+ "print \" Water hammer pressure in case 2 = %.1f psi\"%(phd)\n",
+ "print \" Water hammer pressure in case 3 = %.1f psi\"%(dph)\n",
+ "print \" Pressure at valve in case 4 = %.1f psi\"%(ph3)\n",
+ "print \" Pressure at 300 ft from reservoir = %.2f psi\"%(ph4)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Water hammer pressure = 102.9 psi\n",
+ " Water hammer pressure in case 2 = 32.2 psi\n",
+ " Water hammer pressure in case 3 = 68.6 psi\n",
+ " Pressure at valve in case 4 = 34.3 psi\n",
+ " Pressure at 300 ft from reservoir = 6.43 psi\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch14.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch14.ipynb
new file mode 100644
index 00000000..12f3ef2c
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch14.ipynb
@@ -0,0 +1,90 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:bc0bdd3f42808393903a7a119b866f7bd775b8d70fdd54776d6bd686bc44038d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 14 : Similarity Laws and Factors for Turbomachines"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.1 Page No : 479"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t#kN/m**3\n",
+ "Q = 3.2 \t#m**3/s\n",
+ "h = 25 \t#m\n",
+ "eta = 0.82\n",
+ "\t\n",
+ "#calculations\n",
+ "bp = g*Q*h/eta\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Brake power = %d kW\"%(bp)\n",
+ "\n",
+ "#Initialization of variables\n",
+ "D1 = 50.\n",
+ "n1 = 1450.\n",
+ "n2 = 1200.\n",
+ "D2 = 80.\n",
+ "Q1 = 3.2 \t#cfs\n",
+ "h1 = 25. \t#m\n",
+ "g = 9.81 \t#kN/m**3\n",
+ "eta = 0.82\n",
+ "\t\n",
+ "#calculations\n",
+ "h2 = h1*(D2/D1)**2 *(n2/n1)**2\n",
+ "Q2 = Q1*(D2/D1)**3 *(n2/n1)\n",
+ "bp = g*Q2*h2/eta\n",
+ "h1 = 82. \t #ft\n",
+ "Q1 = 50700. \t#gpm\n",
+ "h2 = 143.8 \t#ft\n",
+ "Q2 = 171800 \t#gpm\n",
+ "Ns1 = n1*math.sqrt(Q1) /h1**(3/4.) \n",
+ "Ns2 = n2*math.sqrt(Q2) /h2**(3/4.) \n",
+ "\t\n",
+ "#Results\n",
+ "print \"Brake power = %d kW\"%(round(bp,-1))\n",
+ "print \"Pumps are homologous. We expect them to have same specific speed and their speeds are %.1f and \\\n",
+ "%.1f\"%(round(Ns1,-1),round(Ns2,-1))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Brake power = 957 kW\n",
+ "Brake power = 5690 kW\n",
+ "Pumps are homologous. We expect them to have same specific speed and their speeds are 11980.0 and 11980.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch15.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch15.ipynb
new file mode 100644
index 00000000..8510f9f5
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch15.ipynb
@@ -0,0 +1,240 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5a87247e3e7d335ec3f93a6763434ef47db612054d0c0f12922c9d7638e3f184"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 15 : Impulse Turbines"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.1 Page No : 486"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from numpy import *\n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "z2 = 500.\t#ft\n",
+ "z1 = 300.\t#ft\n",
+ "D = array([1, 1.5, 2 ,2.5, 3, 4, 6])\n",
+ "g = 32.2\n",
+ "gam = 62.4\n",
+ "\t\n",
+ "#calculations\n",
+ "Dj = D/12\n",
+ "Vj = sqrt((z2-z1)*2*g/(1.04 + 640.*Dj**4))\n",
+ "Aj = math.pi/4 *Dj**2\n",
+ "Q = Aj*Vj\n",
+ "Pjet = gam*Q*Vj**2 /(2*g) /550\n",
+ "Pj = max(Pjet)\n",
+ "for i in range(0,len(Pjet)):\n",
+ " if(Pjet[i] == Pj):\n",
+ " break\n",
+ " \n",
+ "diameter = D[i]\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Dj,in Dj,ft Vj,fps Aj,ft**2 Q=AjVj,cfs Pjet,hp\"\n",
+ "for i in range(len(D)):\n",
+ " print \"%5.1f %5.3f %5.f %7.4f %5.2f %5.1f\"%(D[i],Dj[i],Vj[i],Aj[i],Q[i],Pjet[i])\n",
+ "print \"Thus a pipe of %d in will be the optimum\"%(diameter)\n",
+ "\n",
+ "# answer are slightly different because of rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Dj,in Dj,ft Vj,fps Aj,ft**2 Q=AjVj,cfs Pjet,hp\n",
+ " 1.0 0.083 110 0.0055 0.60 12.7\n",
+ " 1.5 0.125 104 0.0123 1.27 24.2\n",
+ " 2.0 0.167 92 0.0218 2.00 29.6\n",
+ " 2.5 0.208 76 0.0341 2.58 26.1\n",
+ " 3.0 0.250 60 0.0491 2.96 19.0\n",
+ " 4.0 0.333 38 0.0873 3.31 8.4\n",
+ " 6.0 0.500 18 0.1963 3.48 1.9\n",
+ "Thus a pipe of 2 in will be the optimum\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.2 Page No : 498"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from sympy.functions.elementary.trigonometric import acot\n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "phi = 0.46\n",
+ "g = 32.2\n",
+ "k = 0.44\n",
+ "cv = 0.98\n",
+ "d = 10. \t#in\n",
+ "A = 0.545 \t #ft**2\n",
+ "beta = 160. \t#degrees\n",
+ "\t\n",
+ "#calculations\n",
+ "u = phi*math.sqrt(2*g)\n",
+ "V1 = cv*math.sqrt(2*g)\n",
+ "gQ = 62.4*A*V1\n",
+ "T = d/2 *gQ/g *(1 - math.cos(math.radians(beta)) /math.sqrt(1+k) )*math.sqrt(2*g)*(cv-phi)\n",
+ "Power = T*2*u/d\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Torque required = %d ft lb\"%(T)\n",
+ "print \" Power transferred = %d ft lb/s\"%(Power)\n",
+ "Pi = gQ\n",
+ "He = Power/Pi\n",
+ "print \" Hydraulic efficiency = %.2f\"%(He)\n",
+ "v1 = V1-u\n",
+ "v2 = v1/(math.sqrt(1+k))\n",
+ "hl = k*v2**2 /(2*g)\n",
+ "print \"Head loss in bucket friction = %.1f %%\"%(hl*100)\n",
+ "Hn = (1/cv**2 -1)*V1**2 /(2*g)\n",
+ "print \" Head loss in nozzle = %.4f\"%(Hn*100)\n",
+ "V2cos = u+v2*math.cos(math.radians(beta))\n",
+ "V2sin = v2*math.sin(math.radians(beta))\n",
+ "#alpha = math.degrees(1/math.atan(V2cos/V2sin))\n",
+ "alpha = math.degrees(acot(V2cos/V2sin))\n",
+ "V2 = V2sin/math.sin(math.radians(alpha))\n",
+ "Hd = V2**2/(2*g)\n",
+ "print \" Head loss at discharge = %.1f %%\"%(Hd*100)\n",
+ "Htotal = Hd+Hn+hl\n",
+ "print \" Total head loss = %.2f %%\"%(Htotal*100)\n",
+ "\n",
+ "# rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Torque required = 309 ft lb\n",
+ " Power transferred = 228 ft lb/s\n",
+ " Hydraulic efficiency = 0.85\n",
+ "Head loss in bucket friction = 8.3 %\n",
+ " Head loss in nozzle = 3.9600\n",
+ " Head loss at discharge = 2.5 %\n",
+ " Total head loss = 14.70 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.3 Page No : 501"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "cv = 0.98\n",
+ "g = 32.2\n",
+ "h = 1320. \t#ft\n",
+ "A = 0.196 \t#ft**2\n",
+ "eta = 0.85\n",
+ "ne = 400.\n",
+ "phi = 0.45\n",
+ "\t\n",
+ "#calculations\n",
+ "V = cv*math.sqrt(2*g*h)\n",
+ "Q = A*V\n",
+ "bhp = eta*62.4*Q*h/550\n",
+ "ns = ne*math.sqrt(bhp) /h**(5./4)\n",
+ "u = phi*math.sqrt(2*g*h)\n",
+ "D = u*60/math.pi/ne\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Pitch diameter = %.2f ft\"%(D)\n",
+ "\n",
+ "\n",
+ "# part b\n",
+ "#Initialization of variables\n",
+ "cv = 0.98\n",
+ "g = 32.2\n",
+ "h = 1320. \t#ft\n",
+ "A = 0.196 \t#ft**2\n",
+ "eta = 0.85\n",
+ "ne = 400.\n",
+ "phi = 0.45\n",
+ "\t\n",
+ "#calculations\n",
+ "V = cv*math.sqrt(2*g*h)\n",
+ "Q = A*V/3\n",
+ "bhp = eta*62.4*Q*h/550\n",
+ "ne2 = 600.\n",
+ "ns1 = ne2*math.sqrt(bhp) /h**(5./4)\n",
+ "D = 2500./ne2\n",
+ "Dj = math.sqrt(Q*4/V/math.pi)\n",
+ "\t\n",
+ "#Results\n",
+ "print \" Jet diameter = %.3f ft\"%(Dj)\n",
+ "print \" Specific speed = %.2f \"%(ns1)\n",
+ "print \" Pitch Diameter = %.2f ft\"%(D)\n",
+ "print \" Operating speed = %d rpm\"%(ne2)\n",
+ "\n",
+ "# rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pitch diameter = 6.26 ft\n",
+ " Jet diameter = 0.288 ft\n",
+ " Specific speed = 3.68 \n",
+ " Pitch Diameter = 4.17 ft\n",
+ " Operating speed = 600 rpm\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch16.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch16.ipynb
new file mode 100644
index 00000000..95cacefd
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch16.ipynb
@@ -0,0 +1,185 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:97054b18dca6dd35f36356f17f04ac0dbb81bc69e4ec9c5130f6bdf970d306a2"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 16 : Reaction Turbines"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.2 Page No : 525"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from sympy.functions.elementary.trigonometric import acot\n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "ns = 20. \n",
+ "eta = 0.925\n",
+ "etah = 0.94\n",
+ "BD = 0.1\n",
+ "phie = 0.72\n",
+ "g = 32.2\n",
+ "alpha2 = 90. \t#degrees\n",
+ "\t\n",
+ "#calculations\n",
+ "Cr = ns**2 /(67100*phie**2 *BD*eta)\n",
+ "c1cos = etah/(2*phie)\n",
+ "alpha = math.degrees(math.atan(Cr/c1cos))\n",
+ "C1 = Cr/math.sin(alpha)\n",
+ "#beta1 = 1/math.tan(math.radians((C1*math.cos(alpha) -phie)/(C1*math.sin(alpha))))\n",
+ "cotb1 = (0.653 - phie)/0.1243\n",
+ "beta1 = math.degrees(1./math.atan(cotb1))\n",
+ "\n",
+ "#Results\n",
+ "print \"Alpha = %.2f degrees\"%(alpha)\n",
+ "print \" Beta = %.2f degrees\"%(beta1)\n",
+ "print (\"part b\")\n",
+ "h = 402.\n",
+ "n = 600. \t#rpm\n",
+ "bhp = 3600.\n",
+ "ns = n*math.sqrt(bhp) /h**(5./4)\n",
+ "D = 153.2*phie*math.sqrt(h) /n\n",
+ "B = BD*D\n",
+ "Dt = D*0.735\n",
+ "Ac = 0.95*math.pi*D*B\n",
+ "Vr = Cr*math.sqrt(2*g*h)\n",
+ "Q = Ac*Vr\n",
+ "\t\n",
+ "#Results\n",
+ "print \" Breadth = %.3f ft\"%(B)\n",
+ "print \" depth D = %.2f ft\"%(D)\n",
+ "print \" velocity Vr = %d ft/s\"%(Vr)\n",
+ "print \" Flow rate Q = %.1f cfs\"%(Q)\n",
+ "\n",
+ "# note : answers are slightly different because of rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Alpha = 10.78 degrees\n",
+ " Beta = -115.90 degrees\n",
+ "part b\n",
+ " Breadth = 0.369 ft\n",
+ " depth D = 3.69 ft\n",
+ " velocity Vr = 20 ft/s\n",
+ " Flow rate Q = 81.1 cfs\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.3 Page No : 527"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "ns = 70. \n",
+ "z1 = 10. \t#ft\n",
+ "z2 = 5000. \t#ft\n",
+ "\t\n",
+ "#calculations\n",
+ "P1 = 12.2*144/62.4\n",
+ "P2 = 0.26*144/62.4\n",
+ "sigmac = 0.31\n",
+ "h = (P1-P2-z1)/sigmac\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Max permissible head to assure against cavitation = %.f ft\"%(h)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Max permissible head to assure against cavitation = 57 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.4 Page No : 529"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "Q = 600. \t#cfs\n",
+ "z = 350. \t#ft\n",
+ "eta = 0.9\n",
+ "\t\n",
+ "#calculations\n",
+ "power = 62.4*Q*z*eta/550\n",
+ "rpm = 75.\n",
+ "n = 2.\n",
+ "ns = rpm*math.sqrt(power/n) /z**(5./4)\n",
+ "phi = 0.45\n",
+ "D = 153.3*math.sqrt(z) *phi/rpm\n",
+ "rpm2 = 600.\n",
+ "ns2 = rpm2*math.sqrt(power/n) /z**(5./4)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"For two turbines, ns = %.2f\"%(ns)\n",
+ "print \"For Francis turbines, ns = %d \"%(ns2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For two turbines, ns = 5.13\n",
+ "For Francis turbines, ns = 41 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch17.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch17.ipynb
new file mode 100644
index 00000000..b8eb3f65
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch17.ipynb
@@ -0,0 +1,225 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:8c6f5ddedf44ae20de67fc03890769a1dfcd2f9b5b396e3c44b963afe6559e1b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 17 : Centrifugal and Axial-Flow Pumps"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17.1 Page No : 543"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "Ns = 500. #minimum practical specific speed\n",
+ "h = 900. \t#ft\n",
+ "Q = 1600. \t#gpm\n",
+ "\t\n",
+ "#calculations\n",
+ "ne = Ns*h**(3./4) /math.sqrt(Q)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Minimum rotative speed = %d rpm\"%(round(ne,-1))\n",
+ "\n",
+ "#Initialization of variables\n",
+ "ne = 600. \n",
+ "gpm = 1600.\n",
+ "Ns = 500.\n",
+ "Head = 900. \t#ft\n",
+ "\t\n",
+ "#calculations\n",
+ "h = (ne*math.sqrt(gpm) /Ns)**(4./3)\n",
+ "n = Head/h\n",
+ "\t\n",
+ "#Results\n",
+ "print \"No. of stages = \",round(n,3)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Minimum rotative speed = 2050 rpm\n",
+ "No. of stages = 5.159\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17.2 Page No : 543"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "ne = 600. \n",
+ "gpm = 2000.\n",
+ "h = 150.\n",
+ "num = 2.\n",
+ "\t\n",
+ "#calculations\n",
+ "ns = ne*math.sqrt(gpm) /h**(3./4)\n",
+ "gpm2 = num*gpm\n",
+ "h2 = num**2 *h\n",
+ "Ns = 2*ne*math.sqrt(gpm2) /h2**(3./4)\n",
+ "Ne2 = Ns*(h/2)**(3./4) /math.sqrt(gpm)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Specific speed in case1 = %d \"%(ns)\n",
+ "print \"Flow rate in case 2 = %d gpm\"%(gpm2)\n",
+ "print \" Head in case 2 = %d ft\"%(h2)\n",
+ "print \" Specific speed in case 2 = %d \"%(Ns)\n",
+ "print \" required operating speed in case 2 = %.f rpm\"%(Ne2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Specific speed in case1 = 626 \n",
+ "Flow rate in case 2 = 4000 gpm\n",
+ " Head in case 2 = 600 ft\n",
+ " Specific speed in case 2 = 626 \n",
+ " required operating speed in case 2 = 357 rpm\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17.3 Page No : 552"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "ne = 600./2 \n",
+ "gpm = 1450.\n",
+ "h = 140.\n",
+ "NPSH = 10.4\n",
+ "\t\n",
+ "#calculations\n",
+ "Ns = gpm*math.sqrt(ne) /h**(3./4)\n",
+ "sigmac = NPSH/h\n",
+ "zsmax = -3 \t#ft\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Sigma C for the pump = %.4f\"%(sigmac)\n",
+ "print \" Position of pump = %d ft\"%(zsmax)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sigma C for the pump = 0.0743\n",
+ " Position of pump = -3 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17.4 Page No : 557"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "ne = 600.\n",
+ "gpm = 84500.\n",
+ "h = 225.\n",
+ "f = 0.95\n",
+ "phie = 1.1\n",
+ "g = 32.2\n",
+ "\t\n",
+ "#calculations\n",
+ "Ns = ne*math.sqrt(gpm) /h**(3./4)\n",
+ "u2 = phie*math.sqrt(2*g*h)\n",
+ "D = 153.2*phie*math.sqrt(h) /ne\n",
+ "D0 = 1.06*D*12 \t#in\n",
+ "B = 0.155*D0*12 \t#in\n",
+ "De = 0.6*D0\n",
+ "u0 = 1.06*u2\n",
+ "Vm2 = 0.15*u0\n",
+ "Area = 0.95*math.pi*D/144 *B\n",
+ "Q = Area*Vm2\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Specific speed = %d \"%(round(Ns,-1))\n",
+ "print \" Flow rate = %d cfs\"%(Q)\n",
+ "print \" Eye diameter = %.1f in\"%(De)\n",
+ "\n",
+ "# rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Specific speed = 3000 \n",
+ " Flow rate = 183 cfs\n",
+ " Eye diameter = 32.2 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch2.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch2.ipynb
new file mode 100644
index 00000000..6c605e78
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch2.ipynb
@@ -0,0 +1,398 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:dcc8f42948d54861c1b3938fe3127fa1812368cca6f5d25f547cacd56a9fddb2"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2 : Fluid Statics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1 Page No : 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "z = 20000. \t#ft\n",
+ "rate = -0.00356 \t#F/ft\n",
+ "T = 59. \t#F\n",
+ "P = 14.7 \t#psia\n",
+ "gamma = 0.076 \t#lb/ft**3\n",
+ "\t\n",
+ "#calculations\n",
+ "P2 = P*144 - gamma*(z)\n",
+ "P2f = P2/144\n",
+ "P3 = P*math.exp(-gamma*z/(P*144))\n",
+ "P4 = ((P*144)**0.285 -0.285*gamma*z*(P*144)**(-0.715))**(1/0.285)\n",
+ "P4f = P4/144.\n",
+ "P5 = P*((460+T)/(460+T+rate*z))**(gamma*(T+460)/(P*144*rate))\n",
+ "\t\n",
+ "#Results\n",
+ "print ' Constant density'\n",
+ "print ' Final pressure = %.2f psia'%(P2f)\n",
+ "print ' \\nIsothermal'\n",
+ "print ' Final pressure = %.2f psia'%(P3)\n",
+ "print ' \\nIsentropic'\n",
+ "print ' Final pressure = %.1f psia'%(P4f)\n",
+ "print ' \\nLinear decrease'\n",
+ "print ' Final pressure = %.1f psia'%(P5)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Constant density\n",
+ " Final pressure = 4.14 psia\n",
+ " \n",
+ "Isothermal\n",
+ " Final pressure = 7.17 psia\n",
+ " \n",
+ "Isentropic\n",
+ " Final pressure = 6.6 psia\n",
+ " \n",
+ "Linear decrease\n",
+ " Final pressure = 6.8 psia\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2 Page No : 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "wA = 53.5 \t#weight of A - lb/ft**3\n",
+ "wA2 = 8.4 \t#kN/m**3\n",
+ "wB = 78.8 \t#weight of B - lb/ft**3\n",
+ "wB2 = 12.3 \t#kN/m**3\n",
+ "PB = 30. \t#pressure at B - psi\n",
+ "PB2 = 200. \t#kN/m**2\n",
+ "AB = 1.3 \t#ft\n",
+ "AB2 = 40./100 \t#m\n",
+ "BC = 6.5 \t#ft\n",
+ "BC2 = 2. \t#m\n",
+ "CD = 10. \t#ft\n",
+ "CD2 = 3. \t#m\n",
+ "\t\n",
+ "#calculations\n",
+ "PAbyGB = PB*144/wB - AB*13.55*62.4/wB - (BC+CD) + (AB+BC)*wA/wB\n",
+ "PA = PAbyGB*wB/144.\n",
+ "PAbyGB2 = PB2/wB2 - AB2*13.55*9.81/wB2 - (BC2+CD2) + (AB2+BC2)*wA2/wB2\n",
+ "PA2 = PAbyGB2*wB2\n",
+ "\t\n",
+ "#Results\n",
+ "print ' English units'\n",
+ "print \" Final pressure = %.1f psi\"%(PA)\n",
+ "print ' \\n SI Units'\n",
+ "print \" Final pressure = %d kPa\"%(PA2+1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " English units\n",
+ " Final pressure = 16.2 psi\n",
+ " \n",
+ " SI Units\n",
+ " Final pressure = 106 kPa\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3 Page No : 41"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from numpy import *\n",
+ "\n",
+ "#Initialization of variables\n",
+ "W = 500. \t#weight of gate - lb\n",
+ "width = 2. \t#ft\n",
+ "len1 = 4. \t#ft\n",
+ "CGx = 1.2 \t#ft\n",
+ "CGy = 0.9 \t#ft\n",
+ "theta = 30. \t#degrees\n",
+ "gam = 62.4 \t#lb/ft**3\n",
+ "\n",
+ "#calculations\n",
+ "Fv = width*len1 \t#multiply by gam*x\n",
+ "F = width/(2*math.cos(math.radians(theta))) \t#multiply by gam*x*x\n",
+ "vector = roots([F*gam*0.770/2,0, - Fv*gam*width,W*CGx])\n",
+ "\n",
+ "#Result\n",
+ "print 'The gate will remain closed between %.2f ft and %.2f ft'%(vector[2],vector[1])\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The gate will remain closed between 0.61 ft and 5.67 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4 Page No : 43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "z1 = 1. \t#in\n",
+ "z2 = 2. \t#in\n",
+ "z3 = 2. \t#in\n",
+ "sOil = 0.8 \n",
+ "sWater = 1.\n",
+ "Pa = 3. \t#psi\n",
+ "\t\n",
+ "#calculations\n",
+ "Pd = (Pa) + (z2+z1)*sOil*62.4/144 + 62.4*z3/144\n",
+ "Fa = Pa*144*math.pi*z3**2\n",
+ "Fb = sOil*62.4*(z2+z1-(z2+z3)*z2/((z2+z1)*math.pi))*(math.pi*z3**2 /2)\n",
+ "Fc = sOil*62.4*(z2+z1)*(math.pi*z3**2 /2)\n",
+ "Fd = 62.4*(z2+z3)*z2/((z2+z1)*math.pi)*(math.pi*z3**2 /2)\n",
+ "F = Fa+Fb+Fc+Fd\n",
+ "yPa = z2+z1\n",
+ "yCb = z2+z1-(z2+z3)*z2/((z2+z1)*math.pi) \n",
+ "ICb = math.pi*(z2+z3)**4 /128 -0.5*math.pi*z2**2 *((z2+z3)*z2/((z2+z1)*math.pi))**2\n",
+ "yPb = yCb+ICb/(yCb*0.5*math.pi*z2**2)\n",
+ "yPc = z2+z1+ (z2+z3)*z2/((z2+z1)*math.pi) \n",
+ "ICd = ICb\n",
+ "yPd = z2+z1 + (z2+z3)*z2/((z2+z1)*math.pi) + ICb/((z2+z3)*z2/((z2+z1)*math.pi)*0.5*math.pi*z3**2 )\n",
+ "yP = (Fa*yPa+Fb*yPb+Fc*yPc+Fd*yPd)/F\n",
+ "\t\n",
+ "#Results\n",
+ "print ' case 1'\n",
+ "print ' Pressure at the bottom = %.1f psi'%(Pd)\n",
+ "print ' \\n case 2'\n",
+ "print ' Net force = %d lb'%( F+3)\n",
+ "print ' Location of net force = %.2f ft'%( yP)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " case 1\n",
+ " Pressure at the bottom = 4.9 psi\n",
+ " \n",
+ " case 2\n",
+ " Net force = 7380 lb\n",
+ " Location of net force = 3.10 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5 Page No : 46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "dia = 4. \t#m\n",
+ "P = 35. \t#kN/m**2\n",
+ "theta = 30. #degrees\n",
+ "\t\n",
+ "#calculations\n",
+ "Fx = P*(dia-dia*(1-math.cos(math.radians(theta)))/2.)\n",
+ "Fz = P*dia*math.sin(math.radians(theta))/2\n",
+ "dist = (dia-dia*(1-math.cos(math.radians(theta)))/2.)\n",
+ "Fxb = 9.81*dist*dist/2 \n",
+ "Fzb = 9.81*((180+theta)*math.pi*(dia/2)**2/360 + math.sqrt(3) /2 + dia/2)\n",
+ "\t\n",
+ "#Results\n",
+ "print ' part a'\n",
+ "print ' Horizontal force = %.1f kN/m to the right'%( Fx)\n",
+ "print ' Vertical force = %.1f kN/m upward' %( Fz)\n",
+ "print ' \\n part b'\n",
+ "print ' force by the fluid = %.1f kN/m to the right'%(Fxb)\n",
+ "print ' weight of the cross-hatched volume of liquid = %.1f kN/m Upward'%(Fzb )\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " part a\n",
+ " Horizontal force = 130.6 kN/m to the right\n",
+ " Vertical force = 35.0 kN/m upward\n",
+ " \n",
+ " part b\n",
+ " force by the fluid = 68.3 kN/m to the right\n",
+ " weight of the cross-hatched volume of liquid = 100.0 kN/m Upward\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.6 Page No : 49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from numpy.linalg import solve\n",
+ "from numpy import *\n",
+ "\n",
+ "#Initialization of variables\n",
+ "d1 = 4. \t#diameter - in\n",
+ "h1 = 3.75 \t#in\n",
+ "w1 = 0.85 \t#weight of cylinder - lb\n",
+ "gamma = 52. #lb/ft**3\n",
+ "d2 = 5. \t#in\n",
+ "depth = 3. \t#in\n",
+ "\t\n",
+ "#calculations\n",
+ "A = array([[(d1/2)*(d1/2), -(d2/2)*(d2/2)+(d1/2)*(d1/2)],[ 1,1]])\n",
+ "b = array([[0],[w1*12*(12*2/d1)**2 /(gamma*math.pi)]])\n",
+ "C = solve(A,b)\n",
+ "x = C[0]\n",
+ "y = C[1]\n",
+ "height = depth-x\n",
+ "\t\n",
+ "#Results\n",
+ "print 'Bottom of the cylinder will be %.2f in above the bottom of hollow cylinder'%(height)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bottom of the cylinder will be 2.19 in above the bottom of hollow cylinder\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.7 Page No : 52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "v = 180. \t#velocity - m/s\n",
+ "angle = 40. #degrees\n",
+ "a = 4. \t#m/s**2\n",
+ "r = 2600. \t#radius - m\n",
+ "g = 9.81 \t#m/s**2\n",
+ "\t\n",
+ "#calculations\n",
+ "#Assume outward and right as positive\n",
+ "an = round(-v*v/r,1)\n",
+ "at = -a\n",
+ "ax = at*math.cos(math.radians(angle)) +an*math.sin(math.radians(angle))\n",
+ "az = at*math.sin(math.radians(angle)) -an*math.cos(math.radians(angle))\n",
+ "tangent = ax/(az+g)\n",
+ "theta = math.degrees(math.atan(tangent))\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print 'Angle made by the free liquid = %.1f degrees'%(-theta)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Angle made by the free liquid = 33.4 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch3.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch3.ipynb
new file mode 100644
index 00000000..5b3a116e
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch3.ipynb
@@ -0,0 +1,123 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:3a66fd8d35a6b920ec6df68f36f6af53b925b694b7b276b4adb69f10c536acff"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3 : Kinematics of Fluid Flow"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.1 Page No : 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "Q = 0.5 \t#cfs\n",
+ "d1 = 8. \t#in\n",
+ "d2 = 4. \t#in\n",
+ "R = 2. \t#in\n",
+ "h = 0.59 \t#in\n",
+ "\t\n",
+ "#calculations\n",
+ "Aa = math.pi*(d1/12)**2 /4\n",
+ "Va = Q/Aa\n",
+ "Ab = 2*math.pi*R*h/144\n",
+ "Vb = Q/Ab\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Average velocity at section A = %.2f fps \"%(Va)\n",
+ "print \" Average velocity at section B = %.2f fps \"%(Vb)\n",
+ "\n",
+ "# rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average velocity at section A = 1.43 fps \n",
+ " Average velocity at section B = 9.71 fps \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.2 Page No : 81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "Q = 0.5 \t#cfs\n",
+ "d1 = 8. \t#in\n",
+ "d2 = 4. \t#in\n",
+ "R = 2. \t#in\n",
+ "theta = 45.\t#degrees\n",
+ "\t\n",
+ "#calculations\n",
+ "h = (1-math.cos(math.radians(theta))) \t#Multiply by r\n",
+ "Aa = round(2*math.pi*h,2) \t#Multiply by r**2\n",
+ "V = Q/Aa \t#divide by r**2\n",
+ "aA = 0\n",
+ "r = 0.167 \t#ft\n",
+ "V1 = V/r**2\n",
+ "dvbydx = round(V*2/r**3)\n",
+ "aB = V1*dvbydx\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "#The answer varies a bit from the text due to rounding off error\n",
+ "print \"Acceleration at A = %d since flow is steady\"%(aA)\n",
+ "print \"Acceleration at B = %d ft/s**2\"%(aB)\n",
+ "\n",
+ "# rounding off error. please check."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Acceleration at A = 0 since flow is steady\n",
+ "Acceleration at B = 1140 ft/s**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch4.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch4.ipynb
new file mode 100644
index 00000000..1aeaf24f
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch4.ipynb
@@ -0,0 +1,456 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:204da51ebf9aa715601d60f6e1aaa3c9734a35c1b9cad7274440a88878e8202c"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4 : Energy Considerations in Steady Flow"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.1 Page No : 93"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "d = 1.26 #specific gravity\n",
+ "d = 24. \t#in\n",
+ "d2 = 60. #cm\n",
+ "Q = 25. \t#cfs\n",
+ "Q2 = 700. \t#L/s\n",
+ "dout = 12. \t#in\n",
+ "dout2 = 30./100 \t#m\n",
+ "z = 3. \t #ft\n",
+ "z2 = 1. \t#m\n",
+ "P1 = 45. \t#psi\n",
+ "P2 = 300. \t#kN/m**2\n",
+ "gamma = 9.81 \t#kN/m**3\n",
+ "\t\n",
+ "#calculations\n",
+ "V1 = d/math.pi\n",
+ "V2 = d*4/math.pi\n",
+ "pf = (P1*144/(1.26*62.4) + (V1**2)/64.4 - V2**2 /64.4 +z)*1.26*62.4/144\n",
+ "V1 = Q2/1000/(math.pi*dout2**2)\n",
+ "V2 = 4*V1\n",
+ "p2f = ((P2/(1.26*gamma)) + V1**2 /(2*gamma) -V2**2 /(2*gamma) +z2)*1.26*gamma\n",
+ "\n",
+ "#Results\n",
+ "print \" English units\"\n",
+ "print \" Pressure at point 2 = %.1f psi \"%(pf)\n",
+ "print \" \\n SI Units\"\n",
+ "print \" Pressure at point 2 = %.d kN/m**2 \"%(p2f)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " English units\n",
+ " Pressure at point 2 = 39.2 psi \n",
+ " \n",
+ " SI Units\n",
+ " Pressure at point 2 = 254 kN/m**2 \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.2 Page No : 94"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "h = 20. \t#m\n",
+ "c = 4187. \t#N m /(kg K)\n",
+ "g = 9.81\n",
+ "\t\n",
+ "#calculations\n",
+ "dT = g*h/c\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Increase in temperature of water = %.3f K\"%(dT)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Increase in temperature of water = 0.047 K\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3 Page No : 96"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "sg = 1.26 #specific gravity of liquid\n",
+ "sg2 = 1.26 #\n",
+ "HP = 22.\n",
+ "HP2 = 16.\n",
+ "\t\n",
+ "#calculations\n",
+ "hp = HP*550/(sg*62.4) \t#divide by Q\n",
+ "Q = 14.2 \t#cfs\n",
+ "print \"In English units, By trial Q = %.1f cfs\"%(Q)\n",
+ "hp2 = HP2*1000/(sg2*9.81)\n",
+ "Q2 = 0.42 \t#m**3/s\n",
+ "print \" In SI units, By trial Q = %.2f m**3/s\"%(Q2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In English units, By trial Q = 14.2 cfs\n",
+ " In SI units, By trial Q = 0.42 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4 Page No : 96"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "g = 9810. \t#N/m**3\n",
+ "Q = 10 \t #m**3/s\n",
+ "H = 20 \t #m\n",
+ "\t\n",
+ "#calculations\n",
+ "Rate = g*Q*H/1000\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Rate of energy loss = %d kW\"%(Rate-2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rate of energy loss = 1960 kW\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.5 Page No : 98"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "s = 0.86\n",
+ "P2 = 3.8 \t#pressure - psia\n",
+ "Patm = 26.8 \t#atmospheric pressure - Hg\n",
+ "SPatm = 29.9 \t#in of Hg\n",
+ "psi = 14.7 \t#psia\n",
+ "\t\n",
+ "#calculations\n",
+ "Pa = Patm*psi/SPatm\n",
+ "Pcrit = -(Pa-P2)*144/(s*62.4)\n",
+ "Q = math.sqrt((-Pcrit+ 10*144/(s*62.4))*64.4*math.pi**2 /(-1/2.25**2 + 1/0.25**2 ))\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Max. theoretical flow = %.1f cfs\"%(Q)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Max. theoretical flow = 45.7 cfs\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6 Page No : 104"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "z = 3. \t#ft\n",
+ "s = 0.82\n",
+ "\t\n",
+ "#calculations\n",
+ "ua = math.sqrt(z*2*32.2)\n",
+ "ub = math.sqrt(2*32.2*(-2*(1-s) +ua**2 /(2*32.2)))\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Velocity at B = %.1f fps\"%(ub)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Velocity at B = 13.0 fps\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7 Page No : 108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "d = 3. \t#in\n",
+ "x1 = 0.5**2\n",
+ "x2 = 0.75**2\n",
+ "z = 80. \t#ft\n",
+ "z3 = 10. \t#ft\n",
+ "\t\n",
+ "#calculations\n",
+ "print (\"Using Bernoullis theorem\")\n",
+ "v3 = 29.7 \t#fps\n",
+ "Q = math.pi /4 *(d/12)**2 *v3\n",
+ "hls = 5*(x1*v3)**2 /(2*32.2)\n",
+ "hld = 12*(x2*v3)**2 /(2*32.2)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Head loss in suction pipe = %.1f ft\"%(hls)\n",
+ "print \" Head loss in discharge pipe = %.1f ft\"%(hld)\n",
+ "print \" Flow rate = %.2f cfs\"%(Q)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Using Bernoullis theorem\n",
+ "Head loss in suction pipe = 4.3 ft\n",
+ " Head loss in discharge pipe = 52.0 ft\n",
+ " Flow rate = 1.46 cfs\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8 Page No : 109"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "z1 = 2.\n",
+ "z2 = 0.8\n",
+ "\t\n",
+ "#calculations\n",
+ "print (\"From equation of continuity, z1*v1 = z2*v2\")\n",
+ "V1 = math.sqrt((z2-z1)*2*9.81/(1-z1**2 /z2**2))\n",
+ "V2 = z1*V1/z2\n",
+ "Q = z1*1*V1\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Flow rate = %.2f m**3/s\"%(Q)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "From equation of continuity, z1*v1 = z2*v2\n",
+ "Flow rate = 4.24 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.9 Page No : 113"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "theta = 30. \t#degrees\n",
+ "z = 10. \t#ft\n",
+ "x = 60. \t #ft\n",
+ "\t\n",
+ "#calculations\n",
+ "V = math.sqrt((0.5*32.2*69.3**2)/((x-math.sin(math.radians(theta)) *69.3)))\n",
+ "\t\n",
+ "#Results\n",
+ "print \"velocity = %.0f fps\"%(V)\n",
+ "\n",
+ "# rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "velocity = 55 fps\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.10 Page No : 119"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "V = 60. \t#fps\n",
+ "theta = 15. #degrees\n",
+ "ra = 6/12. \t#ft\n",
+ "rb = 8/12. \t#ft\n",
+ "B = 1.5/12 \t#ft\n",
+ "\t\n",
+ "#calculations\n",
+ "Vra = V*math.sin(math.radians(theta))\n",
+ "Q = 2* math.pi*ra*B*Vra\n",
+ "Vratio = ra/rb\n",
+ "Vb = Vratio*V\n",
+ "flow = (V**2 - Vb**2)/(2*32.2)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Flow rate = %.2f cfs\"%(Q)\n",
+ "print \" Velocity at b = %d fps\"%(Vb)\n",
+ "print \" Pressure head = %.1f ft\"%(flow)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Flow rate = 6.10 cfs\n",
+ " Velocity at b = 45 fps\n",
+ " Pressure head = 24.5 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch6.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch6.ipynb
new file mode 100644
index 00000000..6137e1dc
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch6.ipynb
@@ -0,0 +1,406 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7a16c4d96ee700a37dba4a242e55bbbe161eeaa4c40448cf9c981c1c38399b2e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6 : Momentum and Forces in Fluid Flow"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.1 Page No : 153"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t#kN/m**3\n",
+ "V2 = 12. \t#velocity - m/s\n",
+ "V3 = 12. \t#m/s\n",
+ "A2 = 10.**2\n",
+ "A1 = 15.**2\n",
+ "A3 = 7.5**2\n",
+ "t1 = 15. \n",
+ "t2 = 30.\n",
+ "\t\n",
+ "#calculations\n",
+ "V1 = (A2*V2 + A3*V3)/A1\n",
+ "Q1 = round(math.pi /4 *A1*10**-4 *V1,3)\n",
+ "Q2 = round(math.pi /4 *A2*10**-4 *V2,3)\n",
+ "Q3 = round(math.pi /4 *A3*10**-4 *V3,3)\n",
+ "P1g = round(V3**2 /(2*g) - V1**2 /(2*g),2)\n",
+ "P1 = round(P1g*g,1)\n",
+ "rho = 10**3 \n",
+ "V2x = V2*math.cos(math.radians(t1))\n",
+ "V3x = V3*math.cos(math.radians(t2))\n",
+ "V1x = V1\n",
+ "Fx = -P1*A1*10**-4 + (rho*Q2*V2x + rho*Q3*V3x - rho*Q1*V1x)\n",
+ "Fx = Fx*10**-3 \n",
+ "V2y = V2*math.sin(math.radians(t1))\n",
+ "V3y = -V3*math.sin(math.radians(t2))\n",
+ "V1y = 0\n",
+ "Fy = rho*Q2*V2y +rho*Q3*V3y -rho*Q1*V1y\n",
+ "Fy = Fy*10**-3\n",
+ "Fnlx = 0.659 - Fx\n",
+ "\n",
+ "#Results\n",
+ "print \"Force in x directio = %.3f kN\"%(Fx)\n",
+ "print \" Force in y direction = %.3f kN\"%(Fy)\n",
+ "print \"(Fl/n)x = %.3f kN\"%Fnlx\n",
+ "print \"(Fl/n)y = %.3f kN\"%-Fy\n",
+ "\n",
+ "# rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Force in x directio = 0.415 kN\n",
+ " Force in y direction = -0.026 kN\n",
+ "(Fl/n)x = 0.244 kN\n",
+ "(Fl/n)y = 0.026 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.2 Page No : 155"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "V1x = 100. \t#ft/sec\n",
+ "V2x = 0.866*95\n",
+ "V1y = 0.\n",
+ "V2y = .5*95\n",
+ "A1 = 0.0218 \t#ft**2\n",
+ "\t\n",
+ "#calculations\n",
+ "Q = A1*V1x\n",
+ "rho = 1.94\n",
+ "Fx = rho*Q*(V2x-V1x)\n",
+ "Fxr = -Fx\n",
+ "Fy = rho*Q*(V2y-V1y)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Horizontal force on the blade = %.1f lb\"%(Fxr)\n",
+ "print \" Vertical force on the blade = %.f lb\"%(Fy)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Horizontal force on the blade = 75.0 lb\n",
+ " Vertical force on the blade = 201 lb\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3 Page No : 159"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "v2 = 36. \t#fps\n",
+ "beta = 150. \t#degrees\n",
+ "u = 60. \t#velocity - fps\n",
+ "rho = 1.94\n",
+ "Qd = 0.0218\n",
+ "V1 = 100. \t#fps\n",
+ "gam = 62.4\n",
+ "g = 32.2\n",
+ "\t\n",
+ "#calculations\n",
+ "v2s = v2*math.sin(math.radians(beta))\n",
+ "v2c = u+v2*math.cos(math.radians(beta))\n",
+ "V2 = 34. \t#fps\n",
+ "alpha = 32 \t #degrees\n",
+ "Fx = rho*Qd*(v2c-V1)*(V1-u)\n",
+ "Fy = -rho*Qd*(V1-u)*v2s\n",
+ "Fx2 = rho*Qd*V1*(v2c-V1)\n",
+ "HPin = gam*Qd*V1*(V1**2 /(2*g))/550\n",
+ "HPout = gam*Qd*V1*(V2**2 /(2*g))/550\n",
+ "HPtransfer = -Fx2*u/550\n",
+ "HPfl = HPin-HPout-HPtransfer\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Force exerted by water on the vane = %d lb\"%(Fx2)\n",
+ "print \" Friction loss = %.1f hp \"%(HPfl)\n",
+ "\n",
+ "# rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Force exerted by water on the vane = -301 lb\n",
+ " Friction loss = 1.1 hp \n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.4 Page No : 162"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "z1 = 35. \t#ft\n",
+ "z3 = 20. \t#ft\n",
+ "P1 = 30. \t#psi\n",
+ "g = 32.2\n",
+ "z2 = 10. \t#ft\n",
+ "d2 = 4. \t#in\n",
+ "rho = 1.94\n",
+ "be = 20. \t#degrees\n",
+ "W = 150. \t#lb\n",
+ "\t\n",
+ "#calculations\n",
+ "V3 = math.sqrt(2*g*(P1*144/55 + z1-z3))\n",
+ "Q = 3.81 \t#cfs\n",
+ "V2 = 43.6 \t#fps\n",
+ "P2 = round(55*(z3+ V3**2/(2*g) - z2 - V2**2/(2*g))/144,1)\n",
+ "Fx = round(P2*math.pi/4 *d2**2 - rho*55/62.4 *Q*(V3*math.cos(math.radians(be)) - V2) )\n",
+ "Fy = rho*55/62.4 *Q*(V3*math.sin(math.radians(be)) ) + W\n",
+ "Fres = math.sqrt(Fx**2 + Fy**2)\n",
+ "Fsx = rho*Q*55/62.4*(V3*math.cos(math.radians(be)) )\n",
+ "\n",
+ "#calculations\n",
+ "print \" resultant force = %.f lb\"%(Fy)\n",
+ "print \" horizontal component of force = %d lb\"%(Fsx)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " resultant force = 323 lb\n",
+ " horizontal component of force = 475 lb\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.5 Page No : 168"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "omega = 300. \t#rpm\n",
+ "r1 = 1.6 \t #ft\n",
+ "Q = 120. \t #cfs\n",
+ "z = 0.8 \t#ft\n",
+ "beta1 = 80. \t#degrees\n",
+ "r2 = 1. \t#ft\n",
+ "rho = 1.94\n",
+ "g = 32.2\n",
+ "gam = 62.4\n",
+ "\t\n",
+ "#calculations\n",
+ "print (\"part a\")\n",
+ "u1 = round((2*math.pi/60)*omega*r1,1)\n",
+ "Vr1 = round(Q/(2*math.pi*r1*z),2)\n",
+ "v1 = round(Vr1/math.sin(math.radians(beta1)),2)\n",
+ "v2c = round(v1*math.cos(math.radians(beta1)),1)\n",
+ "V1c = round(u1+v2c,1)\n",
+ "u2 = round((2*math.pi/60)*omega*r2,1)\n",
+ "Vr2 = round(Vr1*(r1/r2),1)\n",
+ "beta2 = Vr2/u2 \n",
+ "beta = 37.2\n",
+ "print \"required Blade angle = %.1f degrees\"%(180-beta)\n",
+ "print (\"part b\")\n",
+ "T = round(rho*Q*(r1*V1c),-2)\n",
+ "power = round(T*u2,-3)\n",
+ "print \"Torque exerted = %d ft lb/s\"%(power)\n",
+ "print (\"part c\")\n",
+ "h2 = round(u1*V1c/g,1)\n",
+ "Power = round(gam*Q*h2,-3)\n",
+ "print \"Torque exerted = %d ft lb/s\"%(Power)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part a\n",
+ "required Blade angle = 142.8 degrees\n",
+ "part b\n",
+ "Torque exerted = 619000 ft lb/s\n",
+ "part c\n",
+ "Torque exerted = 619000 ft lb/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6 Page No : 174"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "V1 = 150.*44/30\n",
+ "Q = 20000./2\n",
+ "d = 6.5 \t #diameter - ft\n",
+ "rho = 0.072\n",
+ "\t\n",
+ "#calculations\n",
+ "A = math.pi/4 *(d)**2\n",
+ "V = int(Q/A)\n",
+ "dV = 2*(V-V1)\n",
+ "Ft = round(rho/32.2 *Q*2*dV,-1)\n",
+ "eta = round(1/(1+ dV/(2*V1)),2)\n",
+ "dP = Ft/2 /(math.pi/4) /d**2\n",
+ "hpp = Q*dP/550\n",
+ "\n",
+ "#Results\n",
+ "print \"pressure rise = %d psf\"%(dP)\n",
+ "print \" horsepower input = %d hp \"%(round(hpp,-1))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pressure rise = 109 psf\n",
+ " horsepower input = 1980 hp \n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7 Page No : 175"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "V1 = 8.02 \t#fps\n",
+ "V2 = 16.04 \t#fps\n",
+ "Q = 481. \t#cfs\n",
+ "rho = 1.94\n",
+ "A = 10*6\n",
+ "d = 3.\n",
+ "\t\n",
+ "#calculations\n",
+ "Fx = 62.4*d*A - 62.4*d/2 *A/2 - rho*Q*(V2-V1)\n",
+ "V1m = 2.56 \t#m/s\n",
+ "V2m = 5.12 \t#m/s\n",
+ "Qm = 15.4 \t#m**2/s\n",
+ "dm = 1\n",
+ "Am = 2*3\n",
+ "rhom = 1\n",
+ "Fxm = 9.81*dm*Am - 9.81*dm/2 *Am/2 - rhom*Qm*(V2m-V1m)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Force in x- direction = %d lb\"%(Fx)\n",
+ "print \"Force in x- direction = %.1f kN\"%(Fxm)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Force in x- direction = 940 lb\n",
+ "Force in x- direction = 4.7 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch7.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch7.ipynb
new file mode 100644
index 00000000..7716aa43
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch7.ipynb
@@ -0,0 +1,112 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:cffb7499e644cbe142eb25461633ec2cdaafe8ff11e84d4c7e11093fb9322221"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Chapter 7 : Similitude and Dimensional Analysis"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2 Page No : 192"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "Dratio = 8.\n",
+ "mu = 0.0006\n",
+ "rho = 52/32.2\n",
+ "vm = 1.22*10**-5 \t# lbs/ft**2\n",
+ "V = 45. # velocity - fps\n",
+ "Fm = 0.8\n",
+ "\t\n",
+ "#calculations\n",
+ "vp = round(mu/rho,7)\n",
+ "Vm = vm*V/(Dratio*vp)\n",
+ "Fratio = rho*V**2 /(1.94*Vm**2 *Dratio**2)\n",
+ "Fp = Fratio*Fm\n",
+ "\n",
+ "#Results\n",
+ "print \"velocity = %.2f fps\"%(Vm)\n",
+ "print \" Drag force = %d lb\"%(Fp)\n",
+ "\n",
+ "# note : The answer given in textbook for vp is wrong. Hence, the difference in answers\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "velocity = 0.18 fps\n",
+ " Drag force = 617 lb\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3 Page No : 195"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "L = 50.\n",
+ "Fm = 0.02 \t#N\n",
+ "Vm = 1. \t#m/s\n",
+ "\t\n",
+ "#calculations\n",
+ "Fp = L**3 *Fm \n",
+ "Fp = Fp*0.2248\n",
+ "Vp = math.sqrt(L) *Vm\n",
+ "Vp = Vp*3.28\n",
+ "Hp = Fp*Vp/550\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Required horsepower = %.1f hp\"%(Hp)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Required horsepower = 23.7 hp\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch8.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch8.ipynb
new file mode 100644
index 00000000..03491869
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch8.ipynb
@@ -0,0 +1,466 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:b340580fbd227dce130b380a32e6ef916d9ee3613549fbd41c895ab6ef6ec7e3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8 : Steady Incompressible Flow in Pressure Conduits"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.1 Page No : 205"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "s = 0.85\n",
+ "v = 1.8*10**-5 \t#m**2 /s\n",
+ "d = 10. \t#cm\n",
+ "flow = 0.5 \t #L/s\n",
+ "\t\n",
+ "#calculations\n",
+ "Q = flow*10**3\n",
+ "A = math.pi*d**2 /4\n",
+ "V = Q/A\n",
+ "V = V/10**2\n",
+ "R = d*10**-2 *V/v\n",
+ "\t\n",
+ "#Results\n",
+ "print \"reynolds number = %.f. Hence the flow is laminar\"%(R)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "reynolds number = 354. Hence the flow is laminar\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2 Page No : 212"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "Vc = 12.7 \t#cm/s\n",
+ "r = 2. \t#cm\n",
+ "r2 = 5. \t#cm\n",
+ "R = 354.\n",
+ "rho = 0.85\n",
+ "V = 6.37 \t#cm/s\n",
+ "D = 0.1 \t#m\n",
+ "\t\n",
+ "#calculations\n",
+ "k = Vc/r2**2\n",
+ "f = 64/R\n",
+ "T0 = f/4 *rho*V**2 /2\n",
+ "T02 = T0/10\n",
+ "hr = f*(V*10**-2)**2 /(2*9.81*D)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Friction factor = %.2f\"%(f)\n",
+ "print \" Shear stress at the pipe wall = %.3f N/m**2\"%(T02)\n",
+ "print \" Head loss per pipe length = %.5f m/m\"%(hr)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Friction factor = 0.18\n",
+ " Shear stress at the pipe wall = 0.078 N/m**2\n",
+ " Head loss per pipe length = 0.00037 m/m\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3 Page No : 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "Q = 2. \n",
+ "A = 0.196 \t#cm**2\n",
+ "D = 0.5 \t #ft\n",
+ "rho = 0.9*1.94\n",
+ "mu = 0.0008 \t#viscosity - lb s/ft**2\n",
+ "hl = 25.\n",
+ "g = 32.2 \t #ft/sec**2\n",
+ "L = 200. \t #ft\n",
+ "r = 2. \t #in\n",
+ "\t\n",
+ "#calculations\n",
+ "V = Q/A\n",
+ "R = D*V*rho/mu\n",
+ "f = hl*D*2*g/(L*V**2)\n",
+ "umax = V*(1+1.33*math.sqrt(f))\n",
+ "T0 = f*rho*V**2 /8\n",
+ "u2 = umax - 5.75* math.sqrt(T0/rho) *math.log10(D*12/r)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Center line velocity = %.1f fps\"%(umax)\n",
+ "print \" Shear stress = %.2f lb/ft**2\"%(T0)\n",
+ "print \" Velcoity at 2 in from center line = %.2f fps\"%(u2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Center line velocity = 12.9 fps\n",
+ " Shear stress = 0.88 lb/ft**2\n",
+ " Velcoity at 2 in from center line = 10.93 fps\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4 Page No : 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "f = 0.0131\n",
+ "d = 0.5 \t#m\n",
+ "\t\n",
+ "#calculations\n",
+ "V = 2.12 \t#m/s\n",
+ "R = 10**6\n",
+ "Q = math.pi*d**2 /4 *V \n",
+ "d1 = 32.8*10**-6 /(V* math.sqrt(f))\n",
+ "\n",
+ "#Results\n",
+ "print \"flow rate = %.3f m**3/s\"%(Q)\n",
+ "print \" nominal thickness = %.3e m\"%(d1)\n",
+ "\n",
+ "# note : rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "flow rate = 0.416 m**3/s\n",
+ " nominal thickness = 1.352e-04 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.5 Page No : 241"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "dz = 260. \t#ft\n",
+ "ke = 0.5\n",
+ "f = 0.02\n",
+ "l = 5000. \t#length of pipe - ft\n",
+ "D = 10. \t#in\n",
+ "A2 = 0.545\n",
+ "\t\n",
+ "#calculations\n",
+ "V2by2g = dz/(1 + ke + f*l/(D/12))\n",
+ "V2 = V2by2g*2*32.2\n",
+ "V = math.sqrt(V2)\n",
+ "DV = D*V\n",
+ "Q = math.pi/4 *(D/12)**2 *V\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Flow rate = %.2f cfs\"%(Q)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Flow rate = 6.40 cfs\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.6 Page No : 242"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "z = 260. \t#ft\n",
+ "f = 0.02\n",
+ "\t\n",
+ "#calculations\n",
+ "V2by2g = z/(1.11*256 + 6000*f)\n",
+ "V2 = V2by2g*2*32.2\n",
+ "V = math.sqrt(V2)\n",
+ "Q = 0.545*V\n",
+ "V3 = 16*V\n",
+ "H = z-f*6000*V2by2g\n",
+ "V3 = 16*V\n",
+ "\n",
+ "#Results\n",
+ "print \"rate of discharge = %.2f cfs\"%(Q)\n",
+ "print \"V3 = %.1f fps\"%V3\n",
+ "\n",
+ "# rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rate of discharge = 3.51 cfs\n",
+ "V3 = 103.0 fps\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.7 Page No : 246"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "g = 52.\n",
+ "Hp = 2.\n",
+ "\t\n",
+ "#calculations\n",
+ "Q = 3.48 \t#cfs\n",
+ "V6 = 3.48/0.196\n",
+ "P = -20.9 \t#ft\n",
+ "P2 = P*(g/144)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Flow rate = %.2f cfs\"%(Q)\n",
+ "print \" Pressure in the pipe = %.2f psi\"%(P2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Flow rate = 3.48 cfs\n",
+ " Pressure in the pipe = -7.55 psi\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.8 Page No : 250"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\n",
+ "#Initialization of variables\n",
+ "h = 10. \t#m\n",
+ "g = 9.81 \t#m/s**2\n",
+ "f1 = 0.019\n",
+ "f2 = 0.021\n",
+ "f3 = 0.020\n",
+ "z1 = 300. \t#m\n",
+ "z2 = 150. \t#m\n",
+ "z3 = 250. \t#m\n",
+ "d1 = 0.3 \t#m\n",
+ "d2 = 0.2 \t#m\n",
+ "d3 = 0.25 \t#m\n",
+ "\t\n",
+ "#calculations\n",
+ "print (\"part(a)\")\n",
+ "Vbyg = h/(f1*z1/d1 +f2*z2/d2 *(d1/d2)**4 + f3*z3/d3 *(d1/d3)**4)\n",
+ "V1 = math.sqrt(2*g*Vbyg)\n",
+ "Q = math.pi/4 *d1**2 *V1\n",
+ "print \" Flow rate = %.3f m**3/s\"%(Q)\n",
+ "print ('Part(b)')\n",
+ "Le2 = z2*f2/f1 *(d1/d2)**5\n",
+ "Le3 = z3*f3/f1 *(d1/d3)**5\n",
+ "Le1 = z1\n",
+ "Le = Le1+Le2+Le3\n",
+ "V1byg = h*d1/Le/f1\n",
+ "V2 = math.sqrt(2*g*V1byg)\n",
+ "Q1 = math.pi/4 *d1**2 *V2\n",
+ "print \" Flow rate = %.3f m**3/s\"%(Q1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part(a)\n",
+ " Flow rate = 0.084 m**3/s\n",
+ "Part(b)\n",
+ " Flow rate = 0.084 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.9 Page No : 252"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "d1 = 6./12 \t#ft\n",
+ "d2 = 4./12 \t#ft\n",
+ "d3 = 8./12 \t#ft\n",
+ "l1 = 2000. \t#ft\n",
+ "l2 = 1600. \t#ft\n",
+ "l3 = 4000. \t#ft\n",
+ "f1 = 0.020\n",
+ "f2 = 0.032\n",
+ "f3 = 0.024\n",
+ "El1 = 200.\n",
+ "El2 = 50.\n",
+ "El3 = 120.\n",
+ "g = 32.2\n",
+ "\t\n",
+ "#calculations\n",
+ "Vc = math.sqrt(2*g*(El1-El2)/288.9)\n",
+ "Qc = math.pi/4 *d3**2 *Vc\n",
+ "Va = 1.346*Vc\n",
+ "Qa = math.pi/4 *d1**2 *Va\n",
+ "Vb = (d3**2 *Vc - d1**2 *Va)/d2**2\n",
+ "Qb = math.pi/4 *d2**2 *Vb\n",
+ "P = 62.4/144 *(El1 - El3 - f1*l1/d1 *Va**2 /(2*g))\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Flowrate at A = %.3f cfs\"%(Qa)\n",
+ "print \"Flowrate at B = %.3f cfs\"%(Qb)\n",
+ "print \"Flowrate at C = %.3f cfs\"%(Qc)\n",
+ "print \"Pressure at P = %.2f psi\"%(P)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Flowrate at A = 1.528 cfs\n",
+ "Flowrate at B = 0.490 cfs\n",
+ "Flowrate at C = 2.018 cfs\n",
+ "Pressure at P = 2.06 psi\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/ch9.ipynb b/Fluid_Mechanics_With_Engineering_Applications/ch9.ipynb
new file mode 100644
index 00000000..569ffde1
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/ch9.ipynb
@@ -0,0 +1,494 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e6f28e03dfd837b5aed00ee85654c1040a3b0c8129a67f41e8f2e4ba487b8f35"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9 : Steady Flow of Compressible Fluids"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.1 Page No : 268"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "T2 = 30. \t#C\n",
+ "T1 = 20. \t#C\n",
+ "cv = 716.\n",
+ "m = 15. \t#kg\n",
+ "cp = 1003.\n",
+ "\t\n",
+ "#calculations\n",
+ "di = cv*(T2-T1)\n",
+ "dU = di*m\n",
+ "dh = cp*(T2-T1)\n",
+ "dH = dh*m\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Change in Internal energy = %d N m\"%(dU)\n",
+ "print \" Change in Enthalpy = %d Nm\"%(round(dH,-3))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Change in Internal energy = 107400 N m\n",
+ " Change in Enthalpy = 150000 Nm\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.2 Page No : 268"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "cv = 716.\n",
+ "m = 15. \t#kg\n",
+ "cp = 1003.\n",
+ "T1 = 20.+273 \t#K\n",
+ "k = 1.4\n",
+ "ratio = 0.4\n",
+ "\t\n",
+ "#calculations\n",
+ "T2 = int((T1)*(1/ratio)**(k-1))\n",
+ "P1 = 95. \t#kN/m**2\n",
+ "P2 = int(P1*T2/(T1)/ratio)\n",
+ "di = round(cv*(T2-T1),-2)\n",
+ "dU = di*m\n",
+ "dh = round(cp*(T2-T1),-2)\n",
+ "dH = dh*m\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print \"Final temperature = %d K\"%(T2)\n",
+ "print \" Final pressure = %d kN/m**2\"%(P2)\n",
+ "print \" Change in Internal energy = %d N m\"%(dU)\n",
+ "print \" Change in Enthalpy = %d Nm\"%(dH)\n",
+ "\n",
+ "#The answers are a bit different due to rounding off error.please check.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Final temperature = 422 K\n",
+ " Final pressure = 342 kN/m**2\n",
+ " Change in Internal energy = 1386000 N m\n",
+ " Change in Enthalpy = 1941000 Nm\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.3 Page No : 271"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "k = 1.4\n",
+ "R = 1773.\n",
+ "v = 600. \t#fps\n",
+ "T = 660. \t#K\n",
+ "P = 100. \t#psia\n",
+ "cp = 6210.\n",
+ "g = 32.2\n",
+ "\t\n",
+ "#calculations\n",
+ "c = math.sqrt(k*R*T)\n",
+ "M = v/c\n",
+ "rho = k*P*144/c**2\n",
+ "Ps = P*144 + 0.5*(rho)*v**2 *(1+ 0.25*M**2)\n",
+ "Ts = (cp/g *T + v**2 /(2*g))*g/cp\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Stagnation pressure = %d lb/ft**2\"%(Ps)\n",
+ "print \" Stagnation temperature = %.f R\"%(Ts)\n",
+ "\n",
+ "\n",
+ "# note :Please check the units of the answer.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Stagnation pressure = 16736 lb/ft**2\n",
+ " Stagnation temperature = 689 R\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4 Page No : 275"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "g = 32.2\n",
+ "A = 0.0218 \t#ft**2\n",
+ "P1 = 25.6 \t#psia\n",
+ "T1 = 540. \t#K\n",
+ "k = 1.4\n",
+ "R = 1715.\n",
+ "\t\n",
+ "#calculations\n",
+ "G = g*A*P1*144/math.sqrt(T1) *math.sqrt(k/R *(2/(k+1))**((k+1)/(k-1)))\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Flow rate = %.2f lb/s\"%(G)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Flow rate = 1.84 lb/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.5 Page No : 278"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "P1 = 50. \t#psia\n",
+ "T1 = 540. \t#K\n",
+ "g = 32.2\n",
+ "R = 1715.\n",
+ "k = 1.4\n",
+ "P3 = 13.5 \t #psia\n",
+ "A2 = 0.0218 \t#ft**2\n",
+ "cp = 6000.\n",
+ "\t\n",
+ "#calculations\n",
+ "Pc = 0.528*P1\n",
+ "V32 = round(R*T1/g *k/(k-1) *(1- (P3/P1)**((k-1)/k)),-2)\n",
+ "V3 = round(math.sqrt(V32*2*g),-1)\n",
+ "G3 = g*A2*P1*144/math.sqrt(T1) *math.sqrt(k/R *(2/(k+1))**((k+1)/(k-1)))\n",
+ "T3 = T1 - V3**2 /(2*cp) \n",
+ "gam3 = g*P3*144/(R*T3)\n",
+ "gam2 = (Pc/P3 *gam3**k )**(1/k)\n",
+ "V2 = G3/gam2/A2\n",
+ "T2 = (V3**2 -V2**2)/(2*cp) + T3\n",
+ "A3 = G3/gam3/V3\n",
+ "D3 = math.sqrt(4/math.pi *A3)\n",
+ "G2 = G3\n",
+ "\n",
+ "#Results\n",
+ "print \" velocity at section 3 = %d fps\"%(V3)\n",
+ "print \" Flow rate at section 3 = %.3f lb/s\"%(G3)\n",
+ "print \" temperature at section 3 = %d R\"%(T3)\n",
+ "print \" velocity at section 2 = %d fps\"%(V2)\n",
+ "print \" Flow rate at section 2 = %.3f lb/s\"%(G2)\n",
+ "print \" temperature at section 2 = %d R\"%(T2)\n",
+ "print \" Required Diameter = %.2f in\"%(D3*12)\n",
+ "\n",
+ "# book anwers are wrong. please check."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " velocity at section 3 = 1420 fps\n",
+ " Flow rate at section 3 = 3.596 lb/s\n",
+ " temperature at section 3 = 371 R\n",
+ " velocity at section 2 = 1041 fps\n",
+ " Flow rate at section 2 = 3.596 lb/s\n",
+ " temperature at section 2 = 449 R\n",
+ " Required Diameter = 2.18 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6 Page No : 281"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "P1 = 10. \t#psia\n",
+ "T1 = 460+40. \t#R\n",
+ "R = 1715.\n",
+ "k = 1.4\n",
+ "V1 = 1400. \t#fps\n",
+ "\t\n",
+ "#calculations\n",
+ "rho1 = P1/(R*T1)\n",
+ "c1 = math.sqrt(k*R*T1)\n",
+ "M1 = V1/c1\n",
+ "P2 = P1 * (2*k*M1**2 - (k-1))/(k+1)\n",
+ "V2 = V1*((k-1)*M1**2 +2)/((k+1)*M1**2) \n",
+ "rho2 = rho1*V1/V2\n",
+ "T2 = P2/rho2/R\n",
+ "P22 = 122.5\n",
+ "V22 = 286\n",
+ "T22 = 328\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Pressure at point 2 = %.1f psia and %.1f N/m**2\"%(P2,P22)\n",
+ "print \" Velocity at point 2 = %d fps and %d m/s\"%(V2,V22)\n",
+ "print \" Temperature at point 2 = %d R and %d K\"%(T2,T22)\n",
+ "print (\"Similarly it can be done for SI units\")\n",
+ "\n",
+ "# note : ronding off error. please check."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pressure at point 2 = 17.4 psia and 122.5 N/m**2\n",
+ " Velocity at point 2 = 947 fps and 286 m/s\n",
+ " Temperature at point 2 = 588 R and 328 K\n",
+ "Similarly it can be done for SI units\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.7 Page No : 286"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "A = 140. \t#in**2\n",
+ "P = 48. \t#lb/in**2\n",
+ "mu = 3.78*10**-7\n",
+ "g = 32.2\n",
+ "G = 100. \t#lb/s\n",
+ "p = 80. \t#lb/in**2\n",
+ "T = 65.+460 \t#R\n",
+ "k = 1.4\n",
+ "R = 1715.\n",
+ "\t\n",
+ "#calculations\n",
+ "Rh = A/P /12\n",
+ "R1 = G*4*Rh/ (mu*g*A/144)\n",
+ "R2 = R1\n",
+ "f = 0.0083\n",
+ "gam1 = p*g*144/(R*T)\n",
+ "V1 = G*144/gam1/A\n",
+ "c = math.sqrt(k*R*T)\n",
+ "M1 = V1/c\n",
+ "M2 = 1/math.sqrt(k)\n",
+ "D = 4*Rh\n",
+ "L = ((1-M1**2 /M2**2)/(k*M1**2) - 2*math.log(M2/M1) )*D/f\n",
+ "Ln = 500 \t#ft\n",
+ "P2 = math.sqrt((p*144)**2 - G**2 *R*T/(g**2 *(A/144)**2 *f*Ln/D))\n",
+ "Pa = 12.2\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Max. length = %d ft\"%(round(L,-1))\n",
+ "print \" Pressure required = %.1f psia\"%(P2/144 -Pa)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Max. length = 1260 ft\n",
+ " Pressure required = 67.1 psia\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.8 Page No : 287"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#Initialization of variables\n",
+ "G = 100. \t#lb/s\n",
+ "g = 32.2\n",
+ "V2 = 300. \t#fps\n",
+ "V1 = 250. \t#fps\n",
+ "\t\n",
+ "#calculations\n",
+ "Qh = (V2**2 -V1**2)/(2*g)\n",
+ "Q = Qh*G\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Thermal energy added = %.2f ft lb/s\"%(Q)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Thermal energy added = 42701.86 ft lb/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9 Page No : 290"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#Initialization of variables\n",
+ "gam1 = 0.41\n",
+ "g = 32.2\n",
+ "V1 = 250. \t#fps\n",
+ "R1 = 8.2*10**6\n",
+ "f = 0.0083\n",
+ "A = 0.97 \t#ft**2\n",
+ "G = 100. \t#lb/s\n",
+ "k = 1.4\n",
+ "P = 80. \t#pressure - psia\n",
+ "ratio = 0.8\n",
+ "R = 1715\n",
+ "\t\n",
+ "#calculations\n",
+ "rho1 = gam1/g\n",
+ "X = G**2 /(gam1*A)**2 + 2*k/(k-1) *(P*144/rho1)\n",
+ "P2 = (k-1)/2/k *(X*ratio*rho1 - G**2 /(g**2 *A**2 *ratio*rho1))\n",
+ "L = 563 \t#ft\n",
+ "rho2 = ratio*rho1\n",
+ "V2 = G/(rho2*g*A)\n",
+ "T2 = P2/(rho2*R)\n",
+ "\t\n",
+ "#Results\n",
+ "print \"Length = %d ft\"%(L)\n",
+ "print \" velocity = %.f fps\"%(V2)\n",
+ "print \" Temperature = %d R\"%(T2)\n",
+ "\n",
+ "# note : rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Length = 563 ft\n",
+ " velocity = 314 fps\n",
+ " Temperature = 524 R\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fluid_Mechanics_With_Engineering_Applications/screenshots/15ImpulseTurbines.png b/Fluid_Mechanics_With_Engineering_Applications/screenshots/15ImpulseTurbines.png
new file mode 100644
index 00000000..bf44e2d4
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/screenshots/15ImpulseTurbines.png
Binary files differ
diff --git a/Fluid_Mechanics_With_Engineering_Applications/screenshots/1PropertiesOfFluids.png b/Fluid_Mechanics_With_Engineering_Applications/screenshots/1PropertiesOfFluids.png
new file mode 100644
index 00000000..da69b6c0
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/screenshots/1PropertiesOfFluids.png
Binary files differ
diff --git a/Fluid_Mechanics_With_Engineering_Applications/screenshots/8.png b/Fluid_Mechanics_With_Engineering_Applications/screenshots/8.png
new file mode 100644
index 00000000..21921d45
--- /dev/null
+++ b/Fluid_Mechanics_With_Engineering_Applications/screenshots/8.png
Binary files differ
diff --git a/Mastering_C/chapter1.ipynb b/Mastering_C/chapter1.ipynb
new file mode 100644
index 00000000..b1a0ed0e
--- /dev/null
+++ b/Mastering_C/chapter1.ipynb
@@ -0,0 +1,170 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:f3ff9d889b7b7951c347d942d053d9fde4d57e52c21d53b779e2930b738a9f69"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1: Introduction"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, page no. 18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Hello World\"\n",
+ "print \"Bye.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello World\n",
+ "Bye\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, page no. 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Print \"Hello World\"\n",
+ "#This program will give error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "SyntaxError",
+ "evalue": "invalid syntax (<ipython-input-2-9028d474ee90>, line 1)",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;36m File \u001b[1;32m\"<ipython-input-2-9028d474ee90>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m Print \"Hello World\"\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, page no. 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Hello World\"\n",
+ "print \"Bye.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello World\n",
+ "Bye.\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, page no. 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Hello World\";print \"Bye.\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello World\n",
+ "Bye.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, page no. 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"\\\n",
+ " Hello World\"\n",
+ "\n",
+ "print \"\\\n",
+ " Bye.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Hello World\n",
+ " Bye.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/chapter10.ipynb b/Mastering_C/chapter10.ipynb
new file mode 100644
index 00000000..f65d8afa
--- /dev/null
+++ b/Mastering_C/chapter10.ipynb
@@ -0,0 +1,913 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:32b969a4e6c7c3e26cae81dfc07a38f907135ecba42af43e2cfc7a389c8e7205"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10: Files"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, page no. 372"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fp = open(\"outfile1.txt\", \"w\")\n",
+ "i = int(raw_input(\"Input an integer: \"))\n",
+ "fp.write(str(i))\n",
+ "fp.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input an integer: 22\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, page no. 372"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fp = open(\"outfile2.txt\", \"w\")\n",
+ "fp.write(\"string written to file\\n\")\n",
+ "fp.write(\"c\\n\")\n",
+ "fp.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, page no. 372"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fp = open(\"outfile1.txt\", \"r\")\n",
+ "l = fp.readline()\n",
+ "print \"The integer in outfile1.txt is \", l"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The integer in outfile1.txt is 22\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.1, page no. 374"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fp = open(\"sturec\", \"w\")\n",
+ "print \"Enter student's name and mark: \"\n",
+ "print \"Use 'q' to stop entry\"\n",
+ "while True:\n",
+ " name = raw_input()\n",
+ " if name == 'q':\n",
+ " break\n",
+ " marks = raw_input()\n",
+ " fp.write(name+','+marks+'\\n')\n",
+ "fp.close()\n",
+ "fp = open(\"sturec\", \"r\")\n",
+ "print \"Name\\tMark\"\n",
+ "print \"------------\"\n",
+ "lines = fp.readlines()\n",
+ "for line in lines:\n",
+ " line = line.split(',')\n",
+ " print line[0], '\\t', line[1]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student's name and mark: \n",
+ "Use 'q' to stop entry\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "vivek\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "87\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "98\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "anand\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "67\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "babu\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "45\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "teja\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "90\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "q\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name\tMark\n",
+ "------------\n",
+ "vivek \t87\n",
+ "\n",
+ "rajkumar \t98\n",
+ "\n",
+ "anand \t67\n",
+ "\n",
+ "babu \t45\n",
+ "\n",
+ "teja \t90\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.2, page no. 376"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fp = open(\"str.txt\", \"w\")\n",
+ "print \"Enter characters \"\n",
+ "print \"Use 'q' to stop entry\"\n",
+ "while True:\n",
+ " char = raw_input()\n",
+ " if char == 'q':\n",
+ " break\n",
+ " fp.write(char)\n",
+ "fp.close()\n",
+ "fp = open(\"str.txt\", \"r\")\n",
+ "lines = fp.readlines()\n",
+ "count = 1\n",
+ "string = ''\n",
+ "for line in lines:\n",
+ " print line,\n",
+ " string += line\n",
+ "print \"\\nNumber of characters in the file: \", len(string)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter characters \n",
+ "Use 'q' to stop entry\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "w\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "t\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "h\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "e\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "t\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "l\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "k\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "t\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "h\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "e\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "m\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "o\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "u\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "e\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ ".\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "q\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I saw the cat click the mouse. \n",
+ "Number of characters in the file: 30\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.3, page no. 378"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fp = open(\"class.rec\", \"w\")\n",
+ "print \"Enter the register number, name and mark: \"\n",
+ "print \"Use 'q' to stop entry\"\n",
+ "while True:\n",
+ " reg_no = raw_input()\n",
+ " if reg_no == 'q':\n",
+ " break\n",
+ " name = raw_input()\n",
+ " marks = raw_input()\n",
+ " fp.write(reg_no+','+name+','+marks+'\\n')\n",
+ "fp.close()\n",
+ "fp = open(\"class.rec\", \"r\")\n",
+ "lines = fp.readlines()\n",
+ "for line in lines:\n",
+ " line = line.split(',')\n",
+ " print line[0], '\\t', line[1], '\\t\\t', line[2]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the register number, name and mark: \n",
+ "Use 'q' to stop entry\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4005\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "babu\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "85\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4007\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "98\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4012\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "raju\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "77\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4028\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "teja\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "93\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4029\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "vivek\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "87\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "q\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4005 \tbabu \t\t85\n",
+ "\n",
+ "4007 \trajkumar \t\t98\n",
+ "\n",
+ "4012 \traju \t\t77\n",
+ "\n",
+ "4028 \tteja \t\t93\n",
+ "\n",
+ "4029 \tvivek \t\t87\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.4, page no. 381"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import os\n",
+ "import sys\n",
+ "fp = open(\"class.rec\", \"r\")\n",
+ "fp.seek(0, os.SEEK_END)\n",
+ "size = fp.tell()\n",
+ "print \"The file class.rec is of \", size, \" bytes\"\n",
+ "fp.seek(0)\n",
+ "lines = fp.readlines()\n",
+ "while True:\n",
+ " i = int(raw_input(\"Enter the record no. to read(0 to stop): \"))\n",
+ " if i == 0:\n",
+ " break\n",
+ " fp.seek(0)\n",
+ " counter = 0\n",
+ " for line in lines:\n",
+ " counter += 1\n",
+ " if counter == i:\n",
+ " print line.split(\",\")[0], line.split(\",\")[1], line.split(\",\")[2]\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The file class.rec is of 70 bytes\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the record no. to read(0 to stop): 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4005 babu 85\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the record no. to read(0 to stop): 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4007 rajkumar 98\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the record no. to read(0 to stop): 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4012 raju 77\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the record no. to read(0 to stop): 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4028 teja 93\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the record no. to read(0 to stop): 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8, page no. 384"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#The example will remain same as above"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example fwrite.c, page no. 390"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#there is no concept of buffered write. We will do it normally\n",
+ "\n",
+ "fp = open(\"testbuf.txt\", \"w\")\n",
+ "fp.write(\"1. This is fwrite\\n\")\n",
+ "fp.write(\"2. this is write\\n\")\n",
+ "fp.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#rest of the examples in the chapters deal with command line arguments which is not possible in IPython Notebook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 24
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/chapter11.ipynb b/Mastering_C/chapter11.ipynb
new file mode 100644
index 00000000..9b5d4e2e
--- /dev/null
+++ b/Mastering_C/chapter11.ipynb
@@ -0,0 +1,1993 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e3b54ab088a42a68b5666c432cb7bb7b24f6ac5896dfbd8ae6cf469e8bea26f9"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Dynamic Memory Allocation\n"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, page no. 407"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "g = 50\n",
+ "def func(p):\n",
+ " s = 200\n",
+ " i = 10\n",
+ " print i, s\n",
+ "a = 1\n",
+ "print a\n",
+ "print g\n",
+ "func(-16)\n",
+ "print \"over!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n",
+ "50\n",
+ "10 200\n",
+ "over!\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, page no. 409"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#there is no concept of malloc & free in Python\n",
+ "\n",
+ "print \"How many elements?: \",\n",
+ "n = int(raw_input())\n",
+ "ary = []\n",
+ "print \"Enter the elements: \"\n",
+ "for i in range(n):\n",
+ " ary.append(int(raw_input()))\n",
+ "print \"The entered array is: \"\n",
+ "for ele in ary:\n",
+ " print ele,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many elements?: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the elements: \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": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The entered array is: \n",
+ "1 2 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.1, page no. 412"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "marks = []\n",
+ "size = 3\n",
+ "n = 0\n",
+ "print \"Enter marks (-1 to stop: )\"\n",
+ "mark = int(raw_input())\n",
+ "while mark != -1:\n",
+ " if n >= size:\n",
+ " print \"realloc 3 more integers...\"\n",
+ " size += 3\n",
+ " marks.append(mark)\n",
+ " mark = int(raw_input())\n",
+ " n += 1\n",
+ "\n",
+ "for mark in marks:\n",
+ " print mark,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter marks (-1 to stop: )\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "50\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "60\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "70\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "realloc 3 more integers...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "80\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "90\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "realloc 3 more integers...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12 50 60 70 80 90 100\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.2, page no. 413"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy\n",
+ "n = int(raw_input(\"Rows: \"))\n",
+ "m = int(raw_input(\"Columns: \"))\n",
+ "mat = numpy.zeros((n, m))\n",
+ "print \"Input the elements: \"\n",
+ "for i in range(n):\n",
+ " for j in range(m):\n",
+ " mat[i][j] = int(raw_input())\n",
+ "print \"Input two rows to swap: \"\n",
+ "i = int(raw_input())\n",
+ "j = int(raw_input())\n",
+ "mat[i], mat[j] = mat[j], mat[i]\n",
+ "for i in range(n):\n",
+ " for j in range(m):\n",
+ " print mat[i][j],\n",
+ " print \"\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rows: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Columns: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the elements: \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": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\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": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input two rows to swap: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2.0 4.0 6.0 8.0 10.0 \n",
+ "6.0 7.0 8.0 9.0 0.0 \n",
+ "2.0 4.0 6.0 8.0 10.0 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.3, page no. 415"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def get(x, r, c):\n",
+ " for i in range(r):\n",
+ " for j in range(c):\n",
+ " x[i][j] = int(raw_input())\n",
+ " return x\n",
+ "def display(x, r, c):\n",
+ " for i in range(r):\n",
+ " for j in range(c):\n",
+ " print x[i][j],\n",
+ " print \"\"\n",
+ "def mul(a, b, c, row, m, col):\n",
+ " for i in range(row):\n",
+ " for j in range(col):\n",
+ " c[i][j] = 0\n",
+ " for k in range(m):\n",
+ " c[i][j] = c[i][j] + a[i][k] * b[k][j]\n",
+ " return c\n",
+ "a = numpy.zeros((30, 30)) \n",
+ "b = numpy.zeros((30, 30)) \n",
+ "c = numpy.zeros((30, 30)) \n",
+ "print \"Size of matrix A: \"\n",
+ "r1 = int(raw_input(\"row: \"))\n",
+ "c1 = int(raw_input(\"col: \"))\n",
+ "print \"Size of matrix B: \"\n",
+ "r2 = int(raw_input(\"row: \"))\n",
+ "c2 = int(raw_input(\"col: \"))\n",
+ "if c1 != r2:\n",
+ " print \"Multiplication not possible.\"\n",
+ " print \"columns of matrix A are not equal\"\n",
+ " print \"to rows of Matrix B\"\n",
+ "else:\n",
+ " print \"Multiplication possible\"\n",
+ " print \"Matrix A(%d X %d) elements?\" %(r1, c1)\n",
+ " a = get(a, r1, c1)\n",
+ " print \"Matrix B(%d X %d) elements?\" %(r2, c2)\n",
+ " b = get(a, r1, c1)\n",
+ " c = mul(a, b, c, r1, c1, c2)\n",
+ " print \"Product matrix C(%d X %d): \" %(r1, c2)\n",
+ " display (c, r1, c2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size of matrix A: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "row: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "col: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size of matrix B: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "row: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "col: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication possible\n",
+ "Matrix A(3 X 4) elements?\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": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrix B(4 X 3) elements?\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": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Product matrix C(3 X 3): \n",
+ "38.0 44.0 50.0 \n",
+ "98.0 116.0 134.0 \n",
+ "158.0 188.0 218.0 \n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exmaple 11.4, page no. 419"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class node:\n",
+ " def __init__(self, data=0, link=None):\n",
+ " self.data = data\n",
+ " self.link = link\n",
+ "\n",
+ "start = None\n",
+ " \n",
+ "def add_front(data):\n",
+ " global start\n",
+ " tmp = node(data)\n",
+ " if(start == None):\n",
+ " start = tmp\n",
+ " else:\n",
+ " tmp.link = start\n",
+ " start = tmp\n",
+ "\n",
+ "def del_pos(pos):\n",
+ " global start\n",
+ " if (pos == 0):\n",
+ " tmp = start\n",
+ " start = start.link\n",
+ " return\n",
+ " q = start\n",
+ " count = 1\n",
+ " while(q.link != None):\n",
+ " if(count == pos):\n",
+ " tmp = q.link\n",
+ " q.link = tmp.link\n",
+ " return\n",
+ " count += 1\n",
+ " q = q.link\n",
+ " print \"\\n\\nThere is no element at %d position\" %pos\n",
+ " \n",
+ "def del_elem(data):\n",
+ " global start\n",
+ " if (start.data == data):\n",
+ " tmp = start\n",
+ " start = start.link\n",
+ " return\n",
+ " q = start\n",
+ " while(q.link.link != None):\n",
+ " if(q.link.data == data):\n",
+ " tmp = q.link\n",
+ " q.link = tmp.link\n",
+ " return\n",
+ " q = q.link\n",
+ " if(q.link.data == data):\n",
+ " tmp = q.link;\n",
+ " q.link = None\n",
+ " return\n",
+ " print \"\\n\\nThere is no element whose value is %d\" %data\n",
+ "\n",
+ "def display_list():\n",
+ " global start\n",
+ " if(start == None):\n",
+ " print \"\\n\\nList empty\"\n",
+ " return\n",
+ " q=start\n",
+ " print \"\\nThe List is...\"\n",
+ " while(q != None):\n",
+ " print q.data,\n",
+ " q = q.link\n",
+ " print \"\\n\"\n",
+ "\n",
+ "def get_data():\n",
+ " data = int(raw_input(\"Enter the data: \"))\n",
+ " return data\n",
+ "\n",
+ "while(1):\n",
+ " print \"\\n1.Insert at the beginning of the list\"\n",
+ " print \"2.Delete an element at a give position\"\n",
+ " print \"3.Delete an element with a give value\"\n",
+ " print \"4.Quit\"\n",
+ " print \"Choice: \",\n",
+ " choice =int(raw_input())\n",
+ " if choice == 1:\n",
+ " data = get_data()\n",
+ " add_front(data)\n",
+ " elif choice == 2:\n",
+ " if (start == None):\n",
+ " print \"\\nList empty\"\n",
+ " continue\n",
+ " print \"\\n\\nEnter the position:\"\n",
+ " pos = int(raw_input())\n",
+ " del_pos(pos)\n",
+ " elif choice == 3:\n",
+ " if (start == None):\n",
+ " print \"\\nList empty\"\n",
+ " continue\n",
+ " data = get_data()\n",
+ " del_elem(data)\n",
+ " elif choice == 4:\n",
+ " break\n",
+ " display_list()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "1 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "2 1 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "3 2 1 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter the position:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The List is...\n",
+ "3 1 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "2 3 1 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "1 2 3 1 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "5 1 2 3 1 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter the position:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The List is...\n",
+ "5 1 2 3 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.5, page no. 424"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def bubble(x, upbound):\n",
+ " pas = upbound\n",
+ " while pas >= 0:\n",
+ " for i in range(pas):\n",
+ " if x[i] > x[i+1]:\n",
+ " x[i], x[i+1] = x[i+1], x[i]\n",
+ " pas -= 1\n",
+ " return x\n",
+ "vector = []\n",
+ "n = int(raw_input(\"Size of array? \"))\n",
+ "for i in range(n):\n",
+ " vector.append(int(raw_input()))\n",
+ "vector = bubble(vector, n-1)\n",
+ "print \"Sorted array \"\n",
+ "for ele in vector:\n",
+ " print ele,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size of array? 8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "98\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "34\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "62\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "88\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sorted array \n",
+ "0 1 5 12 34 62 88 98\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.6, page no. 425"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s1 = raw_input(\"Enter string one \")\n",
+ "s2 = raw_input(\"Enter string two \")\n",
+ "print \"Concatenated string is: \", s1+s2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter string one Tejaswi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter string two .V.\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Concatenated string is: Tejaswi.V.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.7, page no. 425"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def sort_strings(strarr):\n",
+ " return sorted(strarr)\n",
+ "\n",
+ "n = int(raw_input(\"Number of strings: \"))\n",
+ "str_array = []\n",
+ "print \"Enter the strings: \"\n",
+ "for i in range(n):\n",
+ " str_array.append(raw_input())\n",
+ "\n",
+ "strarr = sort_strings(str_array)\n",
+ "print \"The sorted array is\"\n",
+ "for string in strarr:\n",
+ " print string"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of strings: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the strings: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tejaswi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Anand\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maya\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sudeep\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The sorted array is\n",
+ "Anand\n",
+ "Maya\n",
+ "Rajkumar\n",
+ "Sudeep\n",
+ "Tejaswi\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.8, page no. 427"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class node:\n",
+ " def __init__(self, data=0, link=None):\n",
+ " self.data = data\n",
+ " self.link = link\n",
+ "\n",
+ "start = None\n",
+ " \n",
+ "def add_front(data):\n",
+ " global start\n",
+ " tmp = node(data)\n",
+ " if(start == None):\n",
+ " start = tmp\n",
+ " else:\n",
+ " tmp.link = start\n",
+ " start = tmp\n",
+ "\n",
+ "def del_pos(pos):\n",
+ " global start\n",
+ " if (pos == 0):\n",
+ " tmp = start\n",
+ " start = start.link\n",
+ " return\n",
+ " q = start\n",
+ " count = 1\n",
+ " while(q.link != None):\n",
+ " if(count == pos):\n",
+ " tmp = q.link\n",
+ " q.link = tmp.link\n",
+ " return\n",
+ " count += 1\n",
+ " q = q.link\n",
+ " print \"\\n\\nThere is no element at %d position\" %pos\n",
+ " \n",
+ "def del_elem(data):\n",
+ " global start\n",
+ " if (start.data == data):\n",
+ " tmp = start\n",
+ " start = start.link\n",
+ " return\n",
+ " q = start\n",
+ " while(q.link.link != None):\n",
+ " if(q.link.data == data):\n",
+ " tmp = q.link\n",
+ " q.link = tmp.link\n",
+ " return\n",
+ " q = q.link\n",
+ " if(q.link.data == data):\n",
+ " tmp = q.link;\n",
+ " q.link = None\n",
+ " return\n",
+ " print \"\\n\\nThere is no element whose value is %d\" %data\n",
+ "\n",
+ "def display_list():\n",
+ " global start\n",
+ " if(start == None):\n",
+ " print \"\\n\\nList empty\"\n",
+ " return\n",
+ " q=start\n",
+ " print \"\\nThe List is...\"\n",
+ " while(q != None):\n",
+ " print q.data,\n",
+ " q = q.link\n",
+ " print \"\\n\"\n",
+ "\n",
+ "def smallest():\n",
+ " global start\n",
+ " q = start\n",
+ " min = q.data\n",
+ " pos = 0\n",
+ " min_pos = 0\n",
+ " while(q != None):\n",
+ " if q.data < min:\n",
+ " min = q.data\n",
+ " mis_pos = pos\n",
+ " pos += 1\n",
+ " q = q.link\n",
+ " return min, min_pos+1\n",
+ "\n",
+ "def largest():\n",
+ " global start\n",
+ " q = start\n",
+ " max = q.data\n",
+ " pos = 0\n",
+ " max_pos = 0\n",
+ " while(q != None):\n",
+ " if q.data > max:\n",
+ " max = q.data\n",
+ " max_pos = pos\n",
+ " pos += 1\n",
+ " q = q.link\n",
+ " return max, max_pos+1\n",
+ "\n",
+ "def get_data():\n",
+ " data = int(raw_input(\"Enter the data: \"))\n",
+ " return data\n",
+ "\n",
+ "while(1):\n",
+ " print \"\\n1.Insert at the beginning of the list\"\n",
+ " print \"2.Delete an element at a give position\"\n",
+ " print \"3.Delete an element with a give value\"\n",
+ " print \"4.Find smallest in the list\"\n",
+ " print \"5.Find largest in the list\"\n",
+ " print \"6.Quit\"\n",
+ " print \"Choice: \",\n",
+ " choice =int(raw_input())\n",
+ " if choice == 1:\n",
+ " data = get_data()\n",
+ " add_front(data)\n",
+ " elif choice == 2:\n",
+ " if (start == None):\n",
+ " print \"\\nList empty\"\n",
+ " continue\n",
+ " print \"\\n\\nEnter the position:\"\n",
+ " pos = int(raw_input())\n",
+ " del_pos(pos)\n",
+ " elif choice == 3:\n",
+ " if (start == None):\n",
+ " print \"\\nList empty\"\n",
+ " continue\n",
+ " data = get_data()\n",
+ " del_elem(data)\n",
+ " elif choice == 4:\n",
+ " min, pos = smallest()\n",
+ " print \"The smallest element has value \", min\n",
+ " print \"Its position is \", pos\n",
+ " elif choice == 5:\n",
+ " max, pos = largest()\n",
+ " print \"The largest element has value \", max\n",
+ " print \"Its position is \", pos\n",
+ " elif choice == 6:\n",
+ " break\n",
+ " display_list()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Find smallest in the list\n",
+ "5.Find largest in the list\n",
+ "6.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 56\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "56 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Find smallest in the list\n",
+ "5.Find largest in the list\n",
+ "6.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 34\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "34 56 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Find smallest in the list\n",
+ "5.Find largest in the list\n",
+ "6.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "45 34 56 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Find smallest in the list\n",
+ "5.Find largest in the list\n",
+ "6.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The smallest element has value 34\n",
+ "Its position is 1\n",
+ "\n",
+ "The List is...\n",
+ "45 34 56 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Find smallest in the list\n",
+ "5.Find largest in the list\n",
+ "6.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The largest element has value 56\n",
+ "Its position is 3\n",
+ "\n",
+ "The List is...\n",
+ "45 34 56 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Find smallest in the list\n",
+ "5.Find largest in the list\n",
+ "6.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "3 45 34 56 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Find smallest in the list\n",
+ "5.Find largest in the list\n",
+ "6.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 80\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "80 3 45 34 56 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Find smallest in the list\n",
+ "5.Find largest in the list\n",
+ "6.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter the position:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "There is no element at 9 position\n",
+ "\n",
+ "The List is...\n",
+ "80 3 45 34 56 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Find smallest in the list\n",
+ "5.Find largest in the list\n",
+ "6.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter the position:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The List is...\n",
+ "80 3 34 56 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Find smallest in the list\n",
+ "5.Find largest in the list\n",
+ "6.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 80\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "3 34 56 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Find smallest in the list\n",
+ "5.Find largest in the list\n",
+ "6.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/chapter12.ipynb b/Mastering_C/chapter12.ipynb
new file mode 100644
index 00000000..fd18aaec
--- /dev/null
+++ b/Mastering_C/chapter12.ipynb
@@ -0,0 +1,4076 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:0f4233c9bc3c7a3995f155be01ebee4b829ac86b3935e6b7d37705fb0fea5376"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12: Data Structures"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example 12.1, page no. 442"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy\n",
+ "arr = numpy.zeros((2, 2, 2))\n",
+ "\n",
+ "print \"Reading the elements of an array: \"\n",
+ "for i in range(2):\n",
+ " for j in range(2):\n",
+ " for k in range(2):\n",
+ " arr[i][j][k] = int(raw_input())\n",
+ "\n",
+ "print \"Displaying the elements of an array: \"\n",
+ "for i in range(2):\n",
+ " print \"\\n\\t\"\n",
+ " for j in range(2):\n",
+ " for k in range(2):\n",
+ " print \"\\t %3d \" %(arr[i][j][k]),\n",
+ " print \"\\n\\t\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reading the elements of an array: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "25\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "26\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "13\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "71\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Displaying the elements of an array: \n",
+ "\n",
+ "\t\n",
+ "\t 15 \t 25 \n",
+ "\t\n",
+ "\t 26 \t 13 \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\t 71 \t 9 \n",
+ "\t\n",
+ "\t 1 \t 8 \n",
+ "\t\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.2, page no. 442"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "str1 = raw_input(\"Input the first string: \")\n",
+ "str2 = raw_input(\"Input the second string: \")\n",
+ "print \"The concatenated string is ...\"\n",
+ "print str1+str2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the first string: Tejaswi \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the second string: Venugopal\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The concatenated string is ...\n",
+ "Tejaswi Venugopal\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.3, page no. 443"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class record:\n",
+ " name = ''\n",
+ " regno = ''\n",
+ " avg = 0.0\n",
+ " rank = 0\n",
+ "i = 0\n",
+ "students = []\n",
+ "while True:\n",
+ " print \"Processing student %d record...\" %(i+1)\n",
+ " print \"Student name ?(END to terminate): \"\n",
+ " stud = record()\n",
+ " stud.name = raw_input()\n",
+ " if stud.name == 'END':\n",
+ " break\n",
+ " else:\n",
+ " stud.regno = raw_input(\"Reg. no? \")\n",
+ " stud.avg = float(raw_input(\"Average marks? \"))\n",
+ " students.append(stud)\n",
+ " i+=1\n",
+ "n = i\n",
+ "for i in range(n-1):\n",
+ " for j in range(i+1, n):\n",
+ " if students[i].avg < students[j].avg:\n",
+ " students[i], students[j] = students[j], students[i]\n",
+ "for i in range(n):\n",
+ " students[i].rank = i+1\n",
+ "print \"Student records after assigning ranks: \"\n",
+ "print \"%s%20s%20s%20s\" %(\"Name\",\"REGISTER_NUMBER\",\"AVERAGE\",\"RANK\")\n",
+ "print \"------------------------------------------------------------------\"\n",
+ "for i in range(n):\n",
+ " print students[i].name, \"\\t\\t\", students[i].regno, \"\\t\\t\\t\", students[i].avg, \"\\t\\t\\t\", students[i].rank"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing student 1 record...\n",
+ "Student name ?(END to terminate): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Asha\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reg. no? ak001\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average marks? 67.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing student 2 record...\n",
+ "Student name ?(END to terminate): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bina\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reg. no? ak003\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average marks? 34.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing student 3 record...\n",
+ "Student name ?(END to terminate): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Anand\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reg. no? ak004\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average marks? 67.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing student 4 record...\n",
+ "Student name ?(END to terminate): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sudeep\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reg. no? ak005\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average marks? 78.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing student 5 record...\n",
+ "Student name ?(END to terminate): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tejaswi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reg. no? ak006\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average marks? 89.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing student 6 record...\n",
+ "Student name ?(END to terminate): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maya\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reg. no? ak007\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average marks? 89.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing student 7 record...\n",
+ "Student name ?(END to terminate): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Prakash\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reg. no? ak008\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average marks? 89.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing student 8 record...\n",
+ "Student name ?(END to terminate): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Raju\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reg. no? ak009\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average marks? 82.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing student 9 record...\n",
+ "Student name ?(END to terminate): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Geetha\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reg. no? ak010\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average marks? 85.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing student 10 record...\n",
+ "Student name ?(END to terminate): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gopi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reg. no? ak011\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average marks? 45.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing student 11 record...\n",
+ "Student name ?(END to terminate): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ganesh\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reg. no? ak012\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average marks? 89.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing student 12 record...\n",
+ "Student name ?(END to terminate): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "END\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Student records after assigning ranks: \n",
+ "Name REGISTER_NUMBER AVERAGE RANK\n",
+ "------------------------------------------------------------------\n",
+ "Tejaswi \t\tak006 \t\t\t89.0 \t\t\t1\n",
+ "Maya \t\tak007 \t\t\t89.0 \t\t\t2\n",
+ "Prakash \t\tak008 \t\t\t89.0 \t\t\t3\n",
+ "Ganesh \t\tak012 \t\t\t89.0 \t\t\t4\n",
+ "Geetha \t\tak010 \t\t\t85.0 \t\t\t5\n",
+ "Raju \t\tak009 \t\t\t82.0 \t\t\t6\n",
+ "Sudeep \t\tak005 \t\t\t78.0 \t\t\t7\n",
+ "Anand \t\tak004 \t\t\t67.0 \t\t\t8\n",
+ "Asha \t\tak001 \t\t\t67.0 \t\t\t9\n",
+ "Gopi \t\tak011 \t\t\t45.0 \t\t\t10\n",
+ "Bina \t\tak003 \t\t\t34.0 \t\t\t11\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.4, page no. 446"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy\n",
+ "arr = numpy.zeros((3,3))\n",
+ "print \"Reading the elements of 2-D array: \"\n",
+ "for i in range(3):\n",
+ " for j in range(3):\n",
+ " arr[i][j] = int(raw_input())\n",
+ "print \"Displaying the elements of 2-D array: \"\n",
+ "p = arr\n",
+ "for i in range(3):\n",
+ " for j in range(3):\n",
+ " print \"arr[%d][%d] = %d\" %(i, j, p[i][j]),\n",
+ " print \"\\tAddress of arr[%d][%d] = %d\" %(i, j, id(p[i][j]))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reading the elements of 2-D array: \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": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Displaying the elements of 2-D array: \n",
+ "arr[0][0] = 1 \tAddress of arr[0][0] = 52403744\n",
+ "arr[0][1] = 2 \tAddress of arr[0][1] = 57791200\n",
+ "arr[0][2] = 3 \tAddress of arr[0][2] = 55892528\n",
+ "arr[1][0] = 4 \tAddress of arr[1][0] = 55892528\n",
+ "arr[1][1] = 5 \tAddress of arr[1][1] = 55892528\n",
+ "arr[1][2] = 6 \tAddress of arr[1][2] = 51486976\n",
+ "arr[2][0] = 7 \tAddress of arr[2][0] = 58587952\n",
+ "arr[2][1] = 8 \tAddress of arr[2][1] = 50218032\n",
+ "arr[2][2] = 9 \tAddress of arr[2][2] = 50218032\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.5, page no. 449"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class node:\n",
+ " def __init__(self, data=0, link=None):\n",
+ " self.data = data\n",
+ " self.link = link\n",
+ "\n",
+ "start = None\n",
+ " \n",
+ "def add_front(data):\n",
+ " global start\n",
+ " tmp = node(data)\n",
+ " if(start == None):\n",
+ " start = tmp\n",
+ " else:\n",
+ " tmp.link = start\n",
+ " start = tmp\n",
+ "\n",
+ "def del_pos(pos):\n",
+ " global start\n",
+ " if (pos == 0):\n",
+ " tmp = start\n",
+ " start = start.link\n",
+ " return\n",
+ " q = start\n",
+ " count = 1\n",
+ " while(q.link != None):\n",
+ " if(count == pos):\n",
+ " tmp = q.link\n",
+ " q.link = tmp.link\n",
+ " return\n",
+ " count += 1\n",
+ " q = q.link\n",
+ " print \"\\n\\nThere is no element at %d position\" %pos\n",
+ " \n",
+ "def del_elem(data):\n",
+ " global start\n",
+ " if (start.data == data):\n",
+ " tmp = start\n",
+ " start = start.link\n",
+ " return\n",
+ " q = start\n",
+ " while(q.link.link != None):\n",
+ " if(q.link.data == data):\n",
+ " tmp = q.link\n",
+ " q.link = tmp.link\n",
+ " return\n",
+ " q = q.link\n",
+ " if(q.link.data == data):\n",
+ " tmp = q.link;\n",
+ " q.link = None\n",
+ " return\n",
+ " print \"\\n\\nThere is no element whose value is %d\" %data\n",
+ "\n",
+ "def display_list():\n",
+ " global start\n",
+ " if(start == None):\n",
+ " print \"\\n\\nList empty\"\n",
+ " return\n",
+ " q=start\n",
+ " print \"\\nThe List is...\"\n",
+ " while(q != None):\n",
+ " print q.data,\n",
+ " q = q.link\n",
+ " print \"\\n\"\n",
+ "\n",
+ "def get_data():\n",
+ " data = int(raw_input(\"Enter the data: \"))\n",
+ " return data\n",
+ "\n",
+ "while(1):\n",
+ " print \"\\n1.Insert at the beginning of the list\"\n",
+ " print \"2.Delete an element at a give position\"\n",
+ " print \"3.Delete an element with a give value\"\n",
+ " print \"4.Quit\"\n",
+ " print \"Choice: \",\n",
+ " choice =int(raw_input())\n",
+ " if choice == 1:\n",
+ " data = get_data()\n",
+ " add_front(data)\n",
+ " elif choice == 2:\n",
+ " if (start == None):\n",
+ " print \"\\nList empty\"\n",
+ " continue\n",
+ " print \"\\n\\nEnter the position:\"\n",
+ " pos = int(raw_input())\n",
+ " del_pos(pos)\n",
+ " elif choice == 3:\n",
+ " if (start == None):\n",
+ " print \"\\nList empty\"\n",
+ " continue\n",
+ " data = get_data()\n",
+ " del_elem(data)\n",
+ " elif choice == 4:\n",
+ " break\n",
+ " display_list()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "0 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "1 0 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "2 1 0 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "3 2 1 0 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "4 3 2 1 0 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter the position:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The List is...\n",
+ "4 2 1 0 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "The List is...\n",
+ "4 2 0 \n",
+ "\n",
+ "\n",
+ "1.Insert at the beginning of the list\n",
+ "2.Delete an element at a give position\n",
+ "3.Delete an element with a give value\n",
+ "4.Quit\n",
+ "Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.6, page no. 454"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class node:\n",
+ " def __init__(self, info=None, link=None):\n",
+ " self.info = info\n",
+ " self.link = link\n",
+ "\n",
+ "last = None\n",
+ "class Circular_Linked:\n",
+ " def create(self, num):\n",
+ " global last\n",
+ " q = node()\n",
+ " tmp = node()\n",
+ " tmp.info = num\n",
+ " if (last == None):\n",
+ " last = tmp\n",
+ " tmp.link = last\n",
+ " else:\n",
+ " tmp.link = last.link\n",
+ " last.link = tmp\n",
+ " last = tmp\n",
+ "\n",
+ " def insert(self, num, pos):\n",
+ " global last\n",
+ " q = node()\n",
+ " tmp = node()\n",
+ " q = last.link\n",
+ " for i in range(0, pos-1):\n",
+ " q = q.link\n",
+ " if (q == last.link):\n",
+ " print \"There are less than \", pos, \" elements\"\n",
+ " return\n",
+ " tmp.link = q.link\n",
+ " tmp.info = num\n",
+ " q.link = tmp\n",
+ " if(q==last):\n",
+ " last=tmp\n",
+ "\n",
+ " def delete(self):\n",
+ " global last\n",
+ " if(last == None):\n",
+ " print \"LIST EMPTY - CANNOT DELETE\"\n",
+ " return\n",
+ " print \"Data item to be deleted:\"\n",
+ " num = int(raw_input())\n",
+ " q = node()\n",
+ " tmp = node()\n",
+ " if( last.link == last and last.info == num):\n",
+ " tmp = last\n",
+ " last = None\n",
+ " return\n",
+ " q = last.link\n",
+ " if(q.info == num):\n",
+ " tmp = q\n",
+ " last.link = q.link\n",
+ " return\n",
+ " while(q.link != last):\n",
+ " if(q.link.info == num):\n",
+ " tmp = q.link\n",
+ " q.link = tmp.link\n",
+ " print num, \" deleted\"\n",
+ " q = q.link\n",
+ " if(q.link.info == num):\n",
+ " tmp = q.link\n",
+ " q.link = last.link\n",
+ " last = q\n",
+ " return\n",
+ " print \"Element not found\"\n",
+ "\n",
+ " def display(self):\n",
+ " global last\n",
+ " q = node()\n",
+ " if(last == None):\n",
+ " print \"List is empty\"\n",
+ " return\n",
+ " q = last.link\n",
+ " print \"List is:\"\n",
+ " while(q != last):\n",
+ " print q.info,\n",
+ " q = q.link\n",
+ " print last.info\n",
+ " \n",
+ "co = Circular_Linked()\n",
+ "while(1):\n",
+ " print \"\\n1.Create Circular Linked List\"\n",
+ " print \"2.Insert an item\"\n",
+ " print \"3.Delete an item\"\n",
+ " print \"4.STOP\"\n",
+ " print \"Enter your choice:\"\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " print \"How many nodes you want:\",\n",
+ " n = int(raw_input())\n",
+ " for i in range(n):\n",
+ " print \"\\nEnter the element:\",\n",
+ " m = int(raw_input())\n",
+ " co.create(m)\n",
+ " elif choice == 2:\n",
+ " print \"\\nEnter the element:\",\n",
+ " m = int(raw_input())\n",
+ " print \"\\nEnter the position after which this element is inserted:\",\n",
+ " po = int(raw_input())\n",
+ " co.insert(m,po)\n",
+ " elif choice == 3:\n",
+ " co.delete()\n",
+ " elif choice == 4:\n",
+ " break\n",
+ " else:\n",
+ " print \"Error - Try again\"\n",
+ " co.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Create Circular Linked List\n",
+ "2.Insert an item\n",
+ "3.Delete an item\n",
+ "4.STOP\n",
+ "Enter your choice:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many nodes you want:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the element:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the element:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the element:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the element:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " List is:\n",
+ "1 2 3 4\n",
+ "\n",
+ "1.Create Circular Linked List\n",
+ "2.Insert an item\n",
+ "3.Delete an item\n",
+ "4.STOP\n",
+ "Enter your choice:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many nodes you want:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the element:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " List is:\n",
+ "1 2 3 4 5\n",
+ "\n",
+ "1.Create Circular Linked List\n",
+ "2.Insert an item\n",
+ "3.Delete an item\n",
+ "4.STOP\n",
+ "Enter your choice:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the element:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the position after which this element is inserted:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " List is:\n",
+ "1 0 2 3 4 5\n",
+ "\n",
+ "1.Create Circular Linked List\n",
+ "2.Insert an item\n",
+ "3.Delete an item\n",
+ "4.STOP\n",
+ "Enter your choice:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Data item to be deleted:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0 deleted\n",
+ "Element not found\n",
+ "List is:\n",
+ "1 2 3 4 5\n",
+ "\n",
+ "1.Create Circular Linked List\n",
+ "2.Insert an item\n",
+ "3.Delete an item\n",
+ "4.STOP\n",
+ "Enter your choice:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Data item to be deleted:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element not found\n",
+ "List is:\n",
+ "1 2 3 4 5\n",
+ "\n",
+ "1.Create Circular Linked List\n",
+ "2.Insert an item\n",
+ "3.Delete an item\n",
+ "4.STOP\n",
+ "Enter your choice:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.7, page no. 461"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAXSIZE = 100\n",
+ "\n",
+ "class stack:\n",
+ " def __init__(self):\n",
+ " self.stack = []\n",
+ " self.top = -1\n",
+ "\n",
+ "def push(pu):\n",
+ " if(pu.top == MAXSIZE-1):\n",
+ " print \"The stack is full\"\n",
+ " else:\n",
+ " print \"Enter the element to be inserted: \"\n",
+ " item = int(raw_input())\n",
+ " pu.stack.append(item)\n",
+ " pu.top += 1\n",
+ "\n",
+ "def pop(po):\n",
+ " if(po.top == -1):\n",
+ " print \"Stack is empty\"\n",
+ " else:\n",
+ " item = po.stack[po.top]\n",
+ " po.top-=1\n",
+ " print \"The popped element is: %d\" %item\n",
+ "\n",
+ "\n",
+ "def display(pt):\n",
+ " if(pt.top == -1):\n",
+ " print \"Stack is empty\"\n",
+ " else:\n",
+ " print \"The element(s) of the stack are: \"\n",
+ " i = pt.top\n",
+ " while(i>=0):\n",
+ " print \"%d\" %pt.stack[i],\n",
+ " i-=1\n",
+ "\n",
+ "ps = stack()\n",
+ "ch = 'y'\n",
+ "\n",
+ "while(1):\n",
+ " print \"\\n1. Push into the stack\"\n",
+ " print \"2. POP\"\n",
+ " print \"3. View elements of the stack\"\n",
+ " print \"4. Exit\"\n",
+ " print \"Enter your choice: \"\n",
+ " choice = int(raw_input())\n",
+ " if(choice == 1):\n",
+ " push(ps)\n",
+ " elif(choice == 2):\n",
+ " pop(ps)\n",
+ " elif(choice == 3):\n",
+ " display(ps)\n",
+ " elif(choice == 4):\n",
+ " break\n",
+ " else:\n",
+ " print \"Invalid Choice\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Push into the stack\n",
+ "2. POP\n",
+ "3. View elements of the stack\n",
+ "4. Exit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element to be inserted: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Push into the stack\n",
+ "2. POP\n",
+ "3. View elements of the stack\n",
+ "4. Exit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element to be inserted: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Push into the stack\n",
+ "2. POP\n",
+ "3. View elements of the stack\n",
+ "4. Exit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element to be inserted: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "67\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Push into the stack\n",
+ "2. POP\n",
+ "3. View elements of the stack\n",
+ "4. Exit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The popped element is: 67\n",
+ "\n",
+ "1. Push into the stack\n",
+ "2. POP\n",
+ "3. View elements of the stack\n",
+ "4. Exit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element to be inserted: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "88\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Push into the stack\n",
+ "2. POP\n",
+ "3. View elements of the stack\n",
+ "4. Exit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The element(s) of the stack are: \n",
+ "67 23 12 \n",
+ "1. Push into the stack\n",
+ "2. POP\n",
+ "3. View elements of the stack\n",
+ "4. Exit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.8, page no. 463"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class node:\n",
+ " def __init__(self, link=None):\n",
+ " self.data = None\n",
+ " self.link = link\n",
+ " \n",
+ "start = None\n",
+ "\n",
+ "\n",
+ "def push(top):\n",
+ " new = node()\n",
+ " print \"Enter element to be pushed: \",\n",
+ " pushed_item = int(raw_input())\n",
+ " new.data = pushed_item\n",
+ " new.link = top\n",
+ " top = new\n",
+ " return top\n",
+ "\n",
+ "def pop(top):\n",
+ " tmp = node()\n",
+ " if(top == None):\n",
+ " print \"Stack is empty...\" \n",
+ " else:\n",
+ " tmp = top\n",
+ " print \"Popped item is: \", tmp.data\n",
+ " top = top.link\n",
+ " tmp.link = None\n",
+ " return top\n",
+ "\n",
+ "def display(top):\n",
+ " if(top == None):\n",
+ " print \"Stack is empty...\"\n",
+ " else:\n",
+ " while(top.link != None):\n",
+ " print top.data,\n",
+ " top = top.link\n",
+ " \n",
+ "Top = node()\n",
+ "while(1):\n",
+ " print \"\\n1.PUSH\"\n",
+ " print \"2.POP\"\n",
+ " print \"3.END\"\n",
+ " print \"Enter your choice: \",\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " Top = push(Top)\n",
+ " print \"STACK after pushing: \"\n",
+ " display(Top)\n",
+ " elif choice == 2:\n",
+ " Top=pop(Top)\n",
+ " print \"STACK after popping: \"\n",
+ " display(Top)\n",
+ " elif choice == 3:\n",
+ " print \"End of comutation\"\n",
+ " break\n",
+ " else:\n",
+ " print \"Invalid Choice\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.END\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element to be pushed: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " STACK after pushing: \n",
+ "23 \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.END\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element to be pushed: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " STACK after pushing: \n",
+ "12 23 \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.END\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element to be pushed: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "67\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " STACK after pushing: \n",
+ "67 12 23 \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.END\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Popped item is: 67\n",
+ "STACK after popping: \n",
+ "12 23 \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.END\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Popped item is: 12\n",
+ "STACK after popping: \n",
+ "23 \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.END\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element to be pushed: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "88\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " STACK after pushing: \n",
+ "88 23 \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.END\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Popped item is: 88\n",
+ "STACK after popping: \n",
+ "23 \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.END\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Popped item is: 23\n",
+ "STACK after popping: \n",
+ "\n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.END\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Popped item is: None\n",
+ "STACK after popping: \n",
+ "Stack is empty...\n",
+ "\n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.END\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " End of comutation\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.9, page no. 467"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "stck = []\n",
+ "\n",
+ "def push(sp,ch):\n",
+ " if sp==100:\n",
+ " print \"Error : Stack overflow\"\n",
+ " else:\n",
+ " sp += 1\n",
+ " stck.append(ch)\n",
+ "\n",
+ "def pop(sp):\n",
+ " if sp < 0:\n",
+ " print \"Error : Stack underflow\"\n",
+ " return 0\n",
+ " else:\n",
+ " sp -= 1\n",
+ " return stck[sp+1]\n",
+ "\n",
+ "def alpha(ch):\n",
+ " if (ch>='A' and ch<=\"Z\") or (ch>='a' and ch<=\"z\"):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "\n",
+ "def num(ch):\n",
+ " if ch>='0' and ch<=\"9\":\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "\n",
+ "def oper(ch):\n",
+ " oparray = ['+','-','*','/','^']\n",
+ " if ch in oparray:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ "def precedence(ch):\n",
+ " if ch=='(':\n",
+ " i = 0\n",
+ " elif ch=='+' or ch=='-':\n",
+ " i = 1\n",
+ " elif ch=='*' or ch=='/':\n",
+ " i = 2\n",
+ " elif ch=='^':\n",
+ " i = 3\n",
+ " return i\n",
+ "\n",
+ "def printerror(n,ifp):\n",
+ " if n==1:\n",
+ " print \"Error_1_: Missing operator\",\n",
+ " elif n==2:\n",
+ " print \"Error_2_: Missing Operand\",\n",
+ " elif n==3:\n",
+ " print \"Error_3_: Mismatched parentehses\",\n",
+ " elif n==4:\n",
+ " print \"Error_4_: Illegal character in expression\",\n",
+ " elif n==5:\n",
+ " print \"Error_5_: Multiletter variable\",\n",
+ " print \"Column %2d\"%ifp\n",
+ " \n",
+ "\n",
+ "def parse (infix,suffix,error):\n",
+ " ch =''\n",
+ " last = '('\n",
+ " i = 0\n",
+ " sp=-1\n",
+ " bracket = 1\n",
+ " ifp = 0\n",
+ " sfp = 0\n",
+ " \n",
+ " push(sp,'(')\n",
+ " \n",
+ " while True:\n",
+ " while infix[i] == \" \":\n",
+ " i += 1\n",
+ " ifp = i\n",
+ " ch = infix[ifp]\n",
+ " \n",
+ " if ch == \"(\":\n",
+ " if alpha(last) or num(last) or last==')':\n",
+ " error = 1\n",
+ " printerror(1,ifp+1)\n",
+ " bracket +=1 \n",
+ " push(sp,ch)\n",
+ " elif ch==\"+\" or ch==\"-\" or ch==\"*\" or ch==\"/\" or ch==\"^\":\n",
+ " if oper(last) or (not alpha(last) and not num(last) and last!=\")\"):\n",
+ " error=1\n",
+ " printerror(2,ifp+1)\n",
+ " while precedence(stck[sp]) >= precedence(ch):\n",
+ " suffix.append(pop(sp))\n",
+ " sfp+=1\n",
+ " push(sp,ch)\n",
+ " elif ch==\")\":\n",
+ " if oper(last):\n",
+ " error=1\n",
+ " printerror(2,ifp+1)\n",
+ " if last==\"(\":\n",
+ " error=1\n",
+ " printerror(2,ifp+1)\n",
+ " printerror(1,ifp+1)\n",
+ " while stck[sp] != \"(\" and sp > 0:\n",
+ " suffix.append(pop(sp))\n",
+ " sfp += 1\n",
+ " sp -= 1\n",
+ " bracket -= 1\n",
+ " elif ch == ' ':\n",
+ " while infix[ifp+1] == \" \" and not infix[ifp] :\n",
+ " ifp += 1\n",
+ " else:\n",
+ " if alpha(last) or num(last):\n",
+ " error = 1 \n",
+ " printerror(1,ifp+1)\n",
+ " printerror(5,ifp+1)\n",
+ " if alpha(ch):\n",
+ " print ch,\n",
+ " suffix.append(infix[ifp])\n",
+ " sfp += 1\n",
+ " elif num(ch):\n",
+ " while num(infix[ifp]):\n",
+ " suffix.append(infix[ifp])\n",
+ " ifp += 1\n",
+ " sfp += 1\n",
+ " ifp -= 1\n",
+ " else:\n",
+ " printerror(4,ifp+1)\n",
+ " last = infix[ifp]\n",
+ " ifp += 1\n",
+ " i = ifp\n",
+ " print ifp,\n",
+ " try:\n",
+ " if not infix[ifp]:\n",
+ " break;\n",
+ " except:\n",
+ " break\n",
+ " \n",
+ " if bracket:\n",
+ " error = 1\n",
+ " printerror(3,ifp-1)\n",
+ " return infix,suffix,error\n",
+ "def readexpression():\n",
+ " i = 0\n",
+ " print \"The given infix expression is\"\n",
+ " infix = list(raw_input())\n",
+ " infix.append(\")\")\n",
+ " \n",
+ " return infix\n",
+ "\n",
+ "\n",
+ "suffix = [] \n",
+ "error = 0\n",
+ "infix = readexpression()\n",
+ "infix,suffix,error = parse(infix,suffix,error)\n",
+ "if not error:\n",
+ " print \"The suffix form of the given expression is \"\n",
+ " print suffix"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The given infix expression is\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a+b)\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 Error_3_: Mismatched parentehses Column 0\n",
+ "a 2 Error_3_: Mismatched parentehses Column 1\n",
+ "3 Error_3_: Mismatched parentehses Column 2\n",
+ "b 4 Error_3_: Mismatched parentehses Column 3\n",
+ "5 Error_3_: Mismatched parentehses Column 4\n",
+ "6\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.10, page no. 472"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 50\n",
+ "queue_arr = []\n",
+ "rear = [-1]\n",
+ "front = [-1]\n",
+ "\n",
+ "def add_element():\n",
+ " if (rear[0] == MAX-1):\n",
+ " print \"Queue is full...\"\n",
+ " return\n",
+ " else:\n",
+ " if(front[0] == -1):\n",
+ " front[0] = 0\n",
+ " print \"Enter the new element: \"\n",
+ " added_item = int(raw_input())\n",
+ " rear[0] = rear[0]+1\n",
+ " queue_arr.append(added_item)\n",
+ "\n",
+ "def remove_element():\n",
+ " if(front[0] == -1 or front[0]>rear[0]):\n",
+ " print \"Queue is empty...\"\n",
+ " return\n",
+ " else:\n",
+ " dell = front[0]\n",
+ " print queue_arr[dell], \" is removed from the Queue\"\n",
+ " front[0] = front[0]+1\n",
+ "\n",
+ "def display():\n",
+ " if(front[0] == -1 or front[0]>rear[0]):\n",
+ " print \"Queue is empty...\"\n",
+ " return\n",
+ " else:\n",
+ " print \"Queue is: \"\n",
+ " for i in range(front[0],rear[0]+1):\n",
+ " print queue_arr[i],\n",
+ "\n",
+ "while(1):\n",
+ " print \"\\n1. Insert an element\"\n",
+ " print \"2. Display all the elements of the queue\"\n",
+ " print \"3. Remove elements from the queue\"\n",
+ " print \"4. Exit from the program\"\n",
+ " print \"Enter your choice: \"\n",
+ " choice = raw_input()\n",
+ " if choice == '1':\n",
+ " add_element()\n",
+ " elif choice == '2':\n",
+ " display()\n",
+ " elif choice == '3':\n",
+ " remove_element()\n",
+ " elif choice == '4':\n",
+ " break\n",
+ " else:\n",
+ " print \"Reenter the choice\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert an element\n",
+ "2. Display all the elements of the queue\n",
+ "3. Remove elements from the queue\n",
+ "4. Exit from the program\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the new element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert an element\n",
+ "2. Display all the elements of the queue\n",
+ "3. Remove elements from the queue\n",
+ "4. Exit from the program\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the new element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "34\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert an element\n",
+ "2. Display all the elements of the queue\n",
+ "3. Remove elements from the queue\n",
+ "4. Exit from the program\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the new element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert an element\n",
+ "2. Display all the elements of the queue\n",
+ "3. Remove elements from the queue\n",
+ "4. Exit from the program\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23 is removed from the Queue\n",
+ "\n",
+ "1. Insert an element\n",
+ "2. Display all the elements of the queue\n",
+ "3. Remove elements from the queue\n",
+ "4. Exit from the program\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "34 is removed from the Queue\n",
+ "\n",
+ "1. Insert an element\n",
+ "2. Display all the elements of the queue\n",
+ "3. Remove elements from the queue\n",
+ "4. Exit from the program\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the new element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert an element\n",
+ "2. Display all the elements of the queue\n",
+ "3. Remove elements from the queue\n",
+ "4. Exit from the program\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Queue is: \n",
+ "45 45 \n",
+ "1. Insert an element\n",
+ "2. Display all the elements of the queue\n",
+ "3. Remove elements from the queue\n",
+ "4. Exit from the program\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.11, page no. 477"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class node:\n",
+ " def __init__(self, link=None):\n",
+ " self.info = None\n",
+ " self.link = link\n",
+ "\n",
+ "def enqueue(rear):\n",
+ " new_node = node()\n",
+ " print \"Enter the new element: \",\n",
+ " new_node.info = int(raw_input())\n",
+ " new_node.link = None\n",
+ " if (rear != None):\n",
+ " rear.link = new_node\n",
+ " rear = new_node\n",
+ " return rear\n",
+ "\n",
+ "def del_queue(f, r):\n",
+ " if f == None:\n",
+ " print \"The Queue is empty\"\n",
+ " else:\n",
+ " print \"The element removed is: \", f.info\n",
+ " if f != r:\n",
+ " f = f.link\n",
+ " else:\n",
+ " f = None\n",
+ " return f\n",
+ "\n",
+ "def display(fr, re):\n",
+ " if fr == None:\n",
+ " print \"The Queue is empty\"\n",
+ " else:\n",
+ " print \"The queue is: \"\n",
+ " while fr != re:\n",
+ " print fr.info,\n",
+ " fr = fr.link\n",
+ " print fr.info,\n",
+ "\n",
+ "rear = None\n",
+ "front = None\n",
+ "while(1):\n",
+ " print \"\\n1.Insert\"\n",
+ " print \"2.Delete\"\n",
+ " print \"3.Quit\"\n",
+ " print \"Enter choice: \",\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " rear = enqueue(rear)\n",
+ " if front == None:\n",
+ " front = rear\n",
+ " elif choice == 2:\n",
+ " front = del_queue(front, rear)\n",
+ " if front == None:\n",
+ " rear = None\n",
+ " elif choice == 3:\n",
+ " break\n",
+ " display(front, rear)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Quit\n",
+ "Enter choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the new element: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The queue is: \n",
+ "23 \n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Quit\n",
+ "Enter choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the new element: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "34\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The queue is: \n",
+ "23 34 \n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Quit\n",
+ "Enter choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the new element: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The queue is: \n",
+ "23 34 45 \n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Quit\n",
+ "Enter choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The element removed is: 23\n",
+ "The queue is: \n",
+ "34 45 \n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Quit\n",
+ "Enter choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The element removed is: 34\n",
+ "The queue is: \n",
+ "45 \n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Quit\n",
+ "Enter choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The element removed is: 45\n",
+ "The Queue is empty\n",
+ "\n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Quit\n",
+ "Enter choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The Queue is empty\n",
+ "The Queue is empty\n",
+ "\n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Quit\n",
+ "Enter choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.12, page no. 480"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy\n",
+ "\n",
+ "qsize = 50\n",
+ "rear = 0\n",
+ "front = 0\n",
+ "qu = numpy.zeros(50, dtype=numpy.int)\n",
+ "def insert():\n",
+ " global rear\n",
+ " global front\n",
+ " global qsize\n",
+ " if rear == qsize:\n",
+ " rear = 1\n",
+ " else:\n",
+ " rear += 1\n",
+ " if front != rear:\n",
+ " item = int(raw_input(\"Enter item to be inserted: \"))\n",
+ " qu[rear] = item\n",
+ " if front == 0:\n",
+ " front += 1\n",
+ " else:\n",
+ " print \"Overflow\"\n",
+ "def delete():\n",
+ " global front\n",
+ " global rear\n",
+ " global qsize\n",
+ " if front != 0:\n",
+ " item = qu[front]\n",
+ " if front == rear:\n",
+ " front = 0\n",
+ " rear = 0\n",
+ " return item\n",
+ " if front == qsize:\n",
+ " front = 1\n",
+ " else:\n",
+ " front += 1\n",
+ " return item\n",
+ " else:\n",
+ " print \"Underflow\"\n",
+ "def display():\n",
+ " global front\n",
+ " global rear\n",
+ " for i in range(front, rear+1):\n",
+ " print qu[i],\n",
+ "\n",
+ "choice = 0\n",
+ "while(choice != 3):\n",
+ " print \"\\n1 - Insert an element into Cqueue\"\n",
+ " print \"2 - Delete an element into Cqueue\"\n",
+ " print \"3 - Quit\"\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " insert()\n",
+ " print \"\\nCqueue after insertion is: \"\n",
+ " display()\n",
+ " elif choice == 2:\n",
+ " item = delete()\n",
+ " print \"Item deleted id: \", item\n",
+ " print \"\\nCqueue after deletion is: \"\n",
+ " display()\n",
+ " else:\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1 - Insert an element into Cqueue\n",
+ "2 - Delete an element into Cqueue\n",
+ "3 - Quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter item to be inserted: 23\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Cqueue after insertion is: \n",
+ "23 \n",
+ "1 - Insert an element into Cqueue\n",
+ "2 - Delete an element into Cqueue\n",
+ "3 - Quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter item to be inserted: 34\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Cqueue after insertion is: \n",
+ "23 34 \n",
+ "1 - Insert an element into Cqueue\n",
+ "2 - Delete an element into Cqueue\n",
+ "3 - Quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter item to be inserted: 45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Cqueue after insertion is: \n",
+ "23 34 45 \n",
+ "1 - Insert an element into Cqueue\n",
+ "2 - Delete an element into Cqueue\n",
+ "3 - Quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Item deleted id: 23\n",
+ "\n",
+ "Cqueue after deletion is: \n",
+ "34 45 \n",
+ "1 - Insert an element into Cqueue\n",
+ "2 - Delete an element into Cqueue\n",
+ "3 - Quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Item deleted id: 34\n",
+ "\n",
+ "Cqueue after deletion is: \n",
+ "45 \n",
+ "1 - Insert an element into Cqueue\n",
+ "2 - Delete an element into Cqueue\n",
+ "3 - Quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Item deleted id: 45\n",
+ "\n",
+ "Cqueue after deletion is: \n",
+ "0 \n",
+ "1 - Insert an element into Cqueue\n",
+ "2 - Delete an element into Cqueue\n",
+ "3 - Quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Underflow\n",
+ "Item deleted id: None\n",
+ "\n",
+ "Cqueue after deletion is: \n",
+ "0 \n",
+ "1 - Insert an element into Cqueue\n",
+ "2 - Delete an element into Cqueue\n",
+ "3 - Quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exmaple 9.13, page no. 484"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class node:\n",
+ " data = ''\n",
+ " next = None\n",
+ "class queue:\n",
+ " front = None\n",
+ " nremovals = 0\n",
+ "\n",
+ "class prique:\n",
+ " queues = []\n",
+ " nqueues = 0\n",
+ " npromote = 0\n",
+ "\n",
+ "def add(que, new_node):\n",
+ " new_node.next = 0\n",
+ " if not que.front:\n",
+ " que.front = new_node\n",
+ " else:\n",
+ " cur = que.front\n",
+ " while(cur.next):\n",
+ " cur = cur.next\n",
+ " cur.next = new_node\n",
+ " return que\n",
+ "\n",
+ "def remove_node(que):\n",
+ " removed_node = que.front\n",
+ " if que.front:\n",
+ " que.front = que.front.next\n",
+ " return removed_node\n",
+ "\n",
+ "def priq_add(priq, priority, data):\n",
+ " if priority >= priq.nqueues:\n",
+ " print \"Error: priority number given is invalid!\"\n",
+ " return priq\n",
+ " new_node = node()\n",
+ " new_node.data = data\n",
+ " priq.queues[priority] = add(priq.queues[priority], new_node)\n",
+ " return priq\n",
+ "\n",
+ "def priq_remove(priq, priority):\n",
+ " removed_char = ''\n",
+ " if priority >= priq.nqueues:\n",
+ " print \"Error: priority number given is invalid!\"\n",
+ " return\n",
+ " removed = remove_node(priq.queues[priority])\n",
+ " if not removed:\n",
+ " if priority < priq.nqueues-1:\n",
+ " return priq_remove(priq, priority+1)\n",
+ " else:\n",
+ " return priq, 0\n",
+ " else:\n",
+ " lower_elm = ''\n",
+ " priq.queues[priority].nremovals += 1\n",
+ " if priq.queues[priority].nremovals == priq.npromote:\n",
+ " lower_elm = priq_remove(priq, priority+1)\n",
+ " if lower_elm:\n",
+ " priq_add(priq, priority, lower_elm)\n",
+ " priq.queues[priority].nremovals = 0\n",
+ " removed_char = removed.data\n",
+ " return priq, removed_char\n",
+ "\n",
+ " \n",
+ "def create_priq(nqueues, npromote):\n",
+ " priq = prique()\n",
+ " priq.nqueues = nqueues\n",
+ " for i in range(nqueues):\n",
+ " priq.queues.append(queue())\n",
+ " priq.npromote = npromote\n",
+ " return priq\n",
+ "\n",
+ "def get_option():\n",
+ " print \"\\n1: Insert an element\"\n",
+ " print \"2: Remove an element\"\n",
+ " print \"3: Quit\"\n",
+ " print \"Choose: \"\n",
+ " option = int(raw_input())\n",
+ " return option\n",
+ "\n",
+ "def get_data():\n",
+ " data = raw_input(\"Enter the data: \")\n",
+ " return data\n",
+ "\n",
+ "def get_priority():\n",
+ " priority = int(raw_input(\"Enter the priority: \"))\n",
+ " return priority\n",
+ "\n",
+ "def display_prique(priq):\n",
+ " print \"The priority queue is ...\"\n",
+ " for i in range(priq.nqueues):\n",
+ " que = priq.queues[i]\n",
+ " cur = que.front\n",
+ " print i,\n",
+ " while cur:\n",
+ " print cur.data,\n",
+ " if cur.next:\n",
+ " print \"->\",\n",
+ " cur = cur.next\n",
+ " print \"\"\n",
+ " print \"\"\n",
+ "\n",
+ "print \"No of priority levels: \"\n",
+ "nlevels = int(raw_input())\n",
+ "print \"No of consecutive removls for proirity promotion: \"\n",
+ "nremovals = int(raw_input())\n",
+ "priq = create_priq(nlevels, nremovals)\n",
+ "while True:\n",
+ " option = get_option()\n",
+ " if option == 1:\n",
+ " data = get_data()\n",
+ " priority = get_priority()\n",
+ " priq = priq_add(priq, priority, data)\n",
+ " elif option == 2:\n",
+ " priority = get_priority()\n",
+ " priq, data = priq_remove(priq, priority)\n",
+ " if data == 0:\n",
+ " print \"No elements to remove\"\n",
+ " else:\n",
+ " print data, \" was removed\"\n",
+ " elif option == 3:\n",
+ " break\n",
+ " else:\n",
+ " print \"BYE\"\n",
+ " break\n",
+ " display_prique(priq)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No of priority levels: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No of consecutive removls for proirity promotion: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1: Insert an element\n",
+ "2: Remove an element\n",
+ "3: Quit\n",
+ "Choose: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: q\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the priority: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The priority queue is ...\n",
+ "0 q \n",
+ "1 \n",
+ "2 \n",
+ "3 \n",
+ "\n",
+ "\n",
+ "1: Insert an element\n",
+ "2: Remove an element\n",
+ "3: Quit\n",
+ "Choose: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: w\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the priority: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The priority queue is ...\n",
+ "0 q -> w \n",
+ "1 \n",
+ "2 \n",
+ "3 \n",
+ "\n",
+ "\n",
+ "1: Insert an element\n",
+ "2: Remove an element\n",
+ "3: Quit\n",
+ "Choose: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: e\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the priority: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The priority queue is ...\n",
+ "0 q -> w -> e \n",
+ "1 \n",
+ "2 \n",
+ "3 \n",
+ "\n",
+ "\n",
+ "1: Insert an element\n",
+ "2: Remove an element\n",
+ "3: Quit\n",
+ "Choose: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: r\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the priority: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The priority queue is ...\n",
+ "0 q -> w -> e -> r \n",
+ "1 \n",
+ "2 \n",
+ "3 \n",
+ "\n",
+ "\n",
+ "1: Insert an element\n",
+ "2: Remove an element\n",
+ "3: Quit\n",
+ "Choose: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the data: z\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the priority: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The priority queue is ...\n",
+ "0 q -> w -> e -> r \n",
+ "1 z \n",
+ "2 \n",
+ "3 \n",
+ "\n",
+ "\n",
+ "1: Insert an element\n",
+ "2: Remove an element\n",
+ "3: Quit\n",
+ "Choose: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the priority: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "q was removed\n",
+ "The priority queue is ...\n",
+ "0 w -> e -> r \n",
+ "1 z \n",
+ "2 \n",
+ "3 \n",
+ "\n",
+ "\n",
+ "1: Insert an element\n",
+ "2: Remove an element\n",
+ "3: Quit\n",
+ "Choose: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the priority: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "w was removed\n",
+ "The priority queue is ...\n",
+ "0 e -> r \n",
+ "1 z \n",
+ "2 \n",
+ "3 \n",
+ "\n",
+ "\n",
+ "1: Insert an element\n",
+ "2: Remove an element\n",
+ "3: Quit\n",
+ "Choose: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the priority: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No elements to remove\n",
+ "The priority queue is ...\n",
+ "0 e -> r \n",
+ "1 z \n",
+ "2 \n",
+ "3 \n",
+ "\n",
+ "\n",
+ "1: Insert an element\n",
+ "2: Remove an element\n",
+ "3: Quit\n",
+ "Choose: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the priority: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "e was removed\n",
+ "The priority queue is ...\n",
+ "0 r \n",
+ "1 z \n",
+ "2 \n",
+ "3 \n",
+ "\n",
+ "\n",
+ "1: Insert an element\n",
+ "2: Remove an element\n",
+ "3: Quit\n",
+ "Choose: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the priority: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r was removed\n",
+ "The priority queue is ...\n",
+ "0 \n",
+ "1 z \n",
+ "2 \n",
+ "3 \n",
+ "\n",
+ "\n",
+ "1: Insert an element\n",
+ "2: Remove an element\n",
+ "3: Quit\n",
+ "Choose: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.14, page no. 495"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Node:\n",
+ " def __init__(self, data):\n",
+ " self.data = data\n",
+ " self.left = None\n",
+ " self.right = None\n",
+ "\n",
+ " def insert(self, data):\n",
+ " if data < self.data:\n",
+ " if self.left is None:\n",
+ " self.left = Node(data)\n",
+ " else:\n",
+ " self.left.insert(data)\n",
+ " elif data > self.data:\n",
+ " if self.right is None:\n",
+ " self.right = Node(data)\n",
+ " else:\n",
+ " self.right.insert(data)\n",
+ "\n",
+ " def inorder(self, tree):\n",
+ " solution = []\n",
+ " def recurse(node):\n",
+ " if not node:\n",
+ " return\n",
+ " recurse(node.left)\n",
+ " solution.append(node.data)\n",
+ " recurse(node.right)\n",
+ " recurse(tree)\n",
+ " return solution\n",
+ " def preorder(self, tree):\n",
+ " solution = []\n",
+ " def recurse(node):\n",
+ " if not node:\n",
+ " return\n",
+ " solution.append(node.data)\n",
+ " recurse(node.left)\n",
+ " recurse(node.right)\n",
+ " recurse(tree)\n",
+ " return solution\n",
+ " def postorder(self, tree):\n",
+ " solution = []\n",
+ " def recurse(node):\n",
+ " if not node:\n",
+ " return\n",
+ " recurse(node.left)\n",
+ " recurse(node.right)\n",
+ " solution.append(node.data)\n",
+ "\n",
+ " recurse(tree)\n",
+ " return solution\n",
+ "\n",
+ "print \"Type numbers, one per line\"\n",
+ "print \"-999 for terminating\"\n",
+ "num = int(raw_input())\n",
+ "tree = Node(num)\n",
+ "while num != -999:\n",
+ " num = int(raw_input())\n",
+ " if num == -999:\n",
+ " break\n",
+ " tree.insert(num)\n",
+ "choice = 0\n",
+ "while choice != 4:\n",
+ " print \"\\nType of TRAVERSAL ?\"\n",
+ " print \"1 - Inorder\"\n",
+ " print \"2 - Preorder\"\n",
+ " print \"3 - Postorder\"\n",
+ " print \"4 - STOP\"\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " print \"INORDER traversal: \"\n",
+ " sol = tree.inorder(tree)\n",
+ " for ele in sol:\n",
+ " print ele,\n",
+ " elif choice == 2:\n",
+ " print \"PREORDER traversal: \"\n",
+ " sol = tree.preorder(tree)\n",
+ " for ele in sol:\n",
+ " print ele,\n",
+ " elif choice == 3:\n",
+ " print \"POSTORDER traversal: \"\n",
+ " sol = tree.postorder(tree)\n",
+ " for ele in sol:\n",
+ " print ele,\n",
+ " else:\n",
+ " print \"BYE\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type numbers, one per line\n",
+ "-999 for terminating\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\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": [
+ "-999\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Type of TRAVERSAL ?\n",
+ "1 - Inorder\n",
+ "2 - Preorder\n",
+ "3 - Postorder\n",
+ "4 - STOP\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "INORDER traversal: \n",
+ "1 2 3 4 5 6 8 9 10 \n",
+ "Type of TRAVERSAL ?\n",
+ "1 - Inorder\n",
+ "2 - Preorder\n",
+ "3 - Postorder\n",
+ "4 - STOP\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "PREORDER traversal: \n",
+ "4 1 3 2 10 9 6 5 8 \n",
+ "Type of TRAVERSAL ?\n",
+ "1 - Inorder\n",
+ "2 - Preorder\n",
+ "3 - Postorder\n",
+ "4 - STOP\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "BYE\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/chapter15.ipynb b/Mastering_C/chapter15.ipynb
new file mode 100644
index 00000000..cf449021
--- /dev/null
+++ b/Mastering_C/chapter15.ipynb
@@ -0,0 +1,99 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:64bc6ed635ee782424e2a9c6d347d0d839901e22bcfed6521e3f281977a7711d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "C Library Functions\n"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.1 page no : 655"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"ratsdrowninwordstar is a palindrom\"\n",
+ "print \"length of \\\"ratsdrowninwordstar is a palindrom\\\" is\",\n",
+ "Len = len(\"ratsdrowninwordstar\")\n",
+ "print \"%d\"%Len"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ratsdrowninwordstar is a palindrom\n",
+ "length of \"ratsdrowninwordstar is a palindrom\" is 19\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.2 Pageno : 656"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "Num = 123.54\n",
+ "fNum = 0.0\n",
+ "cNum = 0.0\n",
+ "fNum = math.floor(Num)\n",
+ "cNum = math.ceil(Num)\n",
+ "print \"original number %.2lf\"%Num\n",
+ "print \"number rounded down %.lf\"%fNum\n",
+ "print \"number rounded up %.lf\"%cNum"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "original number 123.54\n",
+ "number rounded down 123\n",
+ "number rounded up 124\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/chapter16.ipynb b/Mastering_C/chapter16.ipynb
new file mode 100644
index 00000000..e1edaa97
--- /dev/null
+++ b/Mastering_C/chapter16.ipynb
@@ -0,0 +1,116 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:cdbb2a27d4aeed62bc661e588b07689ef9317248d78908eda6f1423b2cfb2027"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 16: Controlling Complexity"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.1, page no. 705"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def cube(i):\n",
+ " return i*i*i\n",
+ "def beep():\n",
+ " print \"\\a\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example mainprog.c, page no. 705"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"The cube of 10 is \", cube(10)\n",
+ "input_int = int(raw_input(\"Input Integer: \"))\n",
+ "if input_int < 1:\n",
+ " beep()\n",
+ " print \"Input is Invalid\"\n",
+ "else:\n",
+ " print \"The cube of %d is %d\" %(input_int, cube(input_int))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The cube of 10 is 1000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input Integer: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\u0007\n",
+ "Input is Invalid\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example make.c, page no. 709"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def cube(i):\n",
+ " return i*i*i\n",
+ "def beep():\n",
+ " print \"I am going to beep!\"\n",
+ " print \"\\a\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/chapter2.ipynb b/Mastering_C/chapter2.ipynb
new file mode 100644
index 00000000..03566b1a
--- /dev/null
+++ b/Mastering_C/chapter2.ipynb
@@ -0,0 +1,981 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c47c99279bcc1ed930609c37047619e07a7ba5a5f3802de8eeb54d6cf31ebdd4"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2: Variables and Expressions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example integer.c, page no. 35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "val = 10\n",
+ "print \"%d\" %val"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example float.c, page no. 36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i_var = 10\n",
+ "f_var = 100.3125\n",
+ "print \"i_var is %d and f_var is %f\" %(i_var, f_var)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i_var is 10 and f_var is 100.312500\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example decimal.c, page no. 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "inp_int = int(raw_input())\n",
+ "print \"The input integer (in decimal) is %u\" %inp_int\n",
+ "print \"The input integer (in hexadecimal) is %x\" %inp_int"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The input integer (in decimal) is 45\n",
+ "The input integer (in hexadecimal) is 2d\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example scanf.c, page no. 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "years = float(raw_input(\"Input your age in years: \"))\n",
+ "secs = years*365*24*60*60\n",
+ "print \"You have lived for %0.1f seconds\" %secs"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input your age in years: 21\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You have lived for 662256000.0 seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example char.c, page no. 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "c = '#'\n",
+ "print \"This is the hash symbol: %s\" %c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This is the hash symbol: #\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example ascii.c, page no. 39 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "code = int(raw_input(\"Input an ASCII code (0 to 127):\" ))\n",
+ "symbol = chr(code)\n",
+ "print \"The symbol corresponding to %d is %s\" %(code,symbol)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input an ASCII code (0 to 127):75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The symbol corresponding to 75 is K\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example string.c, page no. 40"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "my_string = \"13 is unlucky.\"\n",
+ "print \"my_string: %s\" %my_string"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "my_string: 13 is unlucky.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example size.c ,page no. 41"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "print \"Size of a int is %d\" %sys.getsizeof(int)\n",
+ "print \"Size of a long int is %d\" %sys.getsizeof(long)\n",
+ "\n",
+ "#Note: there is no short interger data type in Python\n",
+ "#Answers will differ"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size of a int is 872\n",
+ "Size of a long int is 872\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example inout.c, page no. 42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "shorti = int(raw_input(\"Input short int: \"))\n",
+ "longi = int(raw_input(\"Input long int: \"))\n",
+ "print \"shorti = %d and longi = %d\" %(shorti, longi)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input short int: 12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input long int: 200000000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "shorti = 12 and longi = 200000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example beep.c, page no. 47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"%c\" %('\\x07')\n",
+ "\n",
+ "#note: there won't be any beep in Python"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\u0007\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tax.c, page no. 49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "sal = float(raw_input(\"Salary: \"))\n",
+ "tax = sal * 0.3\n",
+ "print \"tax = %.1f\" %tax"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Salary: 200000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tax = 60000.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tax1.c, page no. 49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "tax_rate = 0.3\n",
+ "sal = float(raw_input(\"Salary: \"))\n",
+ "tax = sal * tax_rate\n",
+ "print \"tax = %.1f\" %tax"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Salary: 200000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tax = 60000.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example const.c, page no. 50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "tax_rate = 0.3\n",
+ "sal = float(raw_input(\"Salary: \"))\n",
+ "tax = sal * tax_rate\n",
+ "print \"tax = %.1f\" %tax\n",
+ "\n",
+ "#Note: there is no constant data type in Python so the program will remain same as above"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Salary: 200000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tax = 60000.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example const.c, page no. 50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "tax_rate = 0.3\n",
+ "sal = float(raw_input(\"Salary: \"))\n",
+ "tax = sal * tax_rate\n",
+ "print \"tax = %.1f\" %tax\n",
+ "\n",
+ "#Note: there is no #define preprocessor in Python so the program will remain same as above"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Salary: 200000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tax = 60000.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example relation.c, page no. 53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Input two numbers\"\n",
+ "i = int(raw_input(\"num1: \"))\n",
+ "j = int(raw_input(\"num2: \"))\n",
+ "if (i == j):\n",
+ " print \"They are equal.\"\n",
+ "print \"Got the message?\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input two numbers\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "num1: 34\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "num2: 34\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "They are equal.\n",
+ "Got the message?\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example char.c, page no. 54"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "c = 255\n",
+ "d = -1\n",
+ "if c < 0:\n",
+ " print \"c is less than 0\"\n",
+ "else:\n",
+ " print \"c is not less than 0\"\n",
+ "if d < 0:\n",
+ " print \"d is less than 0\"\n",
+ "else:\n",
+ " print \"d is not less than 0\"\n",
+ " \n",
+ "#the program will not have output as that given in the textbook\n",
+ "#because, there is no concept of char, signed or unsigned values in Python\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c is not less than 0\n",
+ "d is less than 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example char8.c, page no. 55"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "c = '255'\n",
+ "d = '-1'\n",
+ "if c < 0:\n",
+ " print \"c is less than 0\"\n",
+ "else:\n",
+ " print \"c is not less than 0\"\n",
+ "if d < 0:\n",
+ " print \"d is less than 0\"\n",
+ "else:\n",
+ " print \"d is not less than 0\"\n",
+ "\n",
+ "#the program will not have output as that given in the textbook\n",
+ "#because, there is no concept of char, signed or unsigned values in Python"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c is not less than 0\n",
+ "d is not less than 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example extract.c, page no. 59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i = int(raw_input(\"Input an integer: \"))\n",
+ "n = int(raw_input(\"Bit position to extract: \"))\n",
+ "bit = (i >> n)&1\n",
+ "print \"The bit is: %d\" %bit"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input an integer: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bit position to extract: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The bit is: 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example max.c, page no. 62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Input two numbers\"\n",
+ "i = int(raw_input(\"num1: \"))\n",
+ "j = int(raw_input(\"num2: \"))\n",
+ "larger = i if i > j else j\n",
+ "print \"The larger of the two is %d\" %larger"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input two numbers\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "num1: 34\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "num2: 45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The larger of the two is 45\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example interest.c, page no. 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "p = float(raw_input(\"Principal: \"))\n",
+ "r = float(raw_input(\"Rate: \"))\n",
+ "t = float(raw_input(\"Time: \"))\n",
+ "ncmp_year = float(raw_input(\"Compoundings per year: \"))\n",
+ "simple = p * r * t / 100\n",
+ "cmp_amount = p * pow(1 + r / (ncmp_year * 100), ncmp_year * t)\n",
+ "compound = cmp_amount - p\n",
+ "print \"The simple interest is : %f\" %simple\n",
+ "print \"The compound interest is : %f\" %compound"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Principal: 1000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rate: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Compoundings per year: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The simple interest is : 200.000000\n",
+ "The compound interest is : 218.402898\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.10, page no. 66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "c = float(raw_input(\"Enter temperature in celsius: \"))\n",
+ "f = 1.8 * c + 32\n",
+ "print \"Equivalent fahrenheit = %f\" %f\n",
+ "f = float(raw_input(\"Enter temperature in fahrenheit: \"))\n",
+ "c = (f - 32) / 1.8\n",
+ "print \"Equivalent celsius = %f\" %c\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter temperature in celsius: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Equivalent fahrenheit = 50.000000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter temperature in fahrenheit: 50\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Equivalent celsius = 10.000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.11, page no. 66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "print \"Enter the 3 sides: \"\n",
+ "a = float(raw_input(\"side1:\"))\n",
+ "b = float(raw_input(\"side2:\"))\n",
+ "c = float(raw_input(\"side3:\"))\n",
+ "peri = a + b + c\n",
+ "s = peri / 2\n",
+ "area = math.sqrt(s * (s - a) * (s - b) * (s - c))\n",
+ "print \"Area of the triangle is %f\" %area"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the 3 sides: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "side1:4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "side2:5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "side3:6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area of the triangle is 9.921567\n"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12, page no. 67"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "b = float(raw_input(\"Enter the base: \"))\n",
+ "h = float(raw_input(\"Enter the height: \"))\n",
+ "area = b * h / 2\n",
+ "print \"Area of the triangle is %f\" %area"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the base: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the height: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area of the triangle is 3.000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/chapter3.ipynb b/Mastering_C/chapter3.ipynb
new file mode 100644
index 00000000..9d7fda28
--- /dev/null
+++ b/Mastering_C/chapter3.ipynb
@@ -0,0 +1,584 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:48110bf73660634c54f30da35ad71ab95825c100a9ad798c30a92b3d23049e8e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3: Basic Input-Output"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example getchar.c, page no. 79"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "c = raw_input(\"Type one character: \")\n",
+ "print \"The character you typed is: %c\" %c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type one character: w\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The character you typed is: w\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example gets.c, page no. 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s = raw_input(\"Type a string (Less than 80 characters):\")\n",
+ "print \"The string typed is: %s\" %s"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type a string (Less than 80 characters):C Book\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The string typed is: C Book\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.1, page no. 81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "f_var = 10.12576893\n",
+ "print \"Output 1: %f\" %f_var\n",
+ "print \"Output 2: %20f\" %f_var\n",
+ "print \"Output 3: %-20f\" %f_var\n",
+ "print \"Output 4: %+f\" %f_var\n",
+ "wid_prec = int(raw_input(\"Input the width: \"))\n",
+ "print \"Output 5: %*f\" %(wid_prec,f_var)\n",
+ "print \"Output 6: %.5f\" %f_var\n",
+ "wid_prec = int(raw_input(\"Input the precision: \"))\n",
+ "print \"Output 7: %20.*f\" %(wid_prec,f_var)\n",
+ "print \"Output 8: %-+20.5f\" %(f_var)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output 1: 10.125769\n",
+ "Output 2: 10.125769\n",
+ "Output 3: 10.125769 \n",
+ "Output 4: +10.125769\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the width: 13\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output 5: 10.125769\n",
+ "Output 6: 10.12577\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the precision: 8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output 7: 10.12576893\n",
+ "Output 8: +10.12577 \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example scanf1.c, page no. 84"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Input an integer followed by a floating-point number:\"\n",
+ "int_var = int(raw_input(\"integer:\"))\n",
+ "float_var=float(raw_input(\"float:\"))\n",
+ "print \"The Integer: %d\" %int_var\n",
+ "print \"The floating-point number: %f\" %float_var"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input an integer followed by a floating-point number:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "integer:34\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "float:56.57\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Integer: 34\n",
+ "The floating-point number: 56.570000\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example scanf2.c, page no. 85"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#counting the inputs from user using raw_input() is not possible in Python. Hence, skipping the example"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example scanf3.c, page no. 86"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Input the day, followed by the date (dd-mm-yyyy):\"\n",
+ "day = raw_input(\"day:\")\n",
+ "date = int(raw_input(\"date:\"))\n",
+ "month = int(raw_input(\"month:\"))\n",
+ "year = int(raw_input(\"year:\"))\n",
+ "print \"Day: %s\" %day\n",
+ "print \"Date: %s\" %date\n",
+ "print \"Month: %s\" %month\n",
+ "print \"Year: %s\" %year"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the day, followed by the date (dd-mm-yyyy):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "day:Sunday\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "date:27\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "month:1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "year:1974\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Day: Sunday\n",
+ "Date: 27\n",
+ "Month: 1\n",
+ "Year: 1974\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example scanf4.c, page no. 87"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Enter two strings: \"\n",
+ "string1 = raw_input(\"string1:\")\n",
+ "string2 = raw_input(\"string2:\")\n",
+ "print \"You have input:\"\n",
+ "print string1\n",
+ "print string2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two strings: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "string1:Hello\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "string2:world\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You have input:\n",
+ "Hello\n",
+ "world\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example scanf5.c, page no. 88"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#getting input from user the way it is given in textbook is not possible in Python.\n",
+ "#Hence, output will be different compared to textbook.\n",
+ "\n",
+ "print \"Input two string: \"\n",
+ "string1 = raw_input(\"String 1: \")\n",
+ "string2 = raw_input(\"String 2: \")\n",
+ "\n",
+ "print \"The two strings are: %4s\" %string1\n",
+ "print \"The two strings are: %5s\" %string2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input two string: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "String 1: Morning\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "String 2: Comes\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The two strings are: Morning\n",
+ "The two strings are: Comes\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example scanf6.c, page no. 89"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Input the date:\"\n",
+ "date = int(raw_input(\"date:\"))\n",
+ "separator1 = raw_input(\"separator:\")\n",
+ "month = int(raw_input(\"month:\"))\n",
+ "separator2 = raw_input(\"separator:\")\n",
+ "year = int(raw_input(\"year:\"))\n",
+ "print \"Date: %d\" %date\n",
+ "print \"Month: %d\" %month\n",
+ "print \"Year: %d\" %year"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the date:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "date:31\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "separator:-\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "month:12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "separator:/\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "year:1999\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Date: 31\n",
+ "Month: 12\n",
+ "Year: 1999\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example scanf7.c, page no. 90"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Input the date:\"\n",
+ "date = int(raw_input(\"date:\"))\n",
+ "month = int(raw_input(\"month:\"))\n",
+ "year = int(raw_input(\"year:\"))\n",
+ "print \"Date: %d\" %date\n",
+ "print \"Month: %d\" %month\n",
+ "print \"Year: %d\" %year"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the date:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "date:31\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "month:12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "year:1999\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Date: 31\n",
+ "Month: 12\n",
+ "Year: 1999\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/chapter4.ipynb b/Mastering_C/chapter4.ipynb
new file mode 100644
index 00000000..fdd2c8c4
--- /dev/null
+++ b/Mastering_C/chapter4.ipynb
@@ -0,0 +1,1567 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:afd37f358b4faba0dd82fd8fdf176be8389b2a27c7cdec9882b3da534d4a3ec8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4: Control Structures"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example if1.c, page no. 101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i = int(raw_input(\"Enter a number: \")) \n",
+ "if i % 3 == 0 :\n",
+ " print \"Number entered is divisible by 3.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 30\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number entered is divisible by 3.\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example scanf8.c, page no. 102"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#The output in the textbok is 0.000000 because it was not able to convert string to float in C\n",
+ "#Hence, by default it stored 0.0000000. In Python the same would give error. Hence, the answer differs\n",
+ "\n",
+ "years = float(raw_input(\"Input your age in years: \"))\n",
+ "secs = years * 365 * 24 * 60 * 60\n",
+ "print \"You have livid for %f seconds \" %secs"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input your age in years: 25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You have livid for 788400000.000000 seconds \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example if2.c, page no. 102"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#the way it is given in textbook is not possible in Python. Doing it in different manner\n",
+ "\n",
+ "print \"Input your age in years: \",\n",
+ "years =(raw_input())\n",
+ "try:\n",
+ " float(years)\n",
+ " secs = float(years) * 365 * 24 * 60 * 60\n",
+ " print \"you have lived for %f seconds\" %secs\n",
+ "except:\n",
+ " print \"the input is not a floating-point number\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input your age in years: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " you have lived for 2365200000.000000 seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example if3.c, page no. 103"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#the program will remain same as the previous one\n",
+ "\n",
+ "print \"Input your age in years: \",\n",
+ "years =(raw_input())\n",
+ "try:\n",
+ " float(years)\n",
+ " secs = float(years) * 365 * 24 * 60 * 60\n",
+ " print \"you have lived for %f seconds\" %secs\n",
+ "except:\n",
+ " print \"the input is not a floating-point number\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input your age in years: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "sundeep\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " the input is not a floating-point number\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example large.c, page no. 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Input a b c\"\n",
+ "a = float(raw_input(\"a=\"))\n",
+ "b = float(raw_input(\"b=\"))\n",
+ "c = float(raw_input(\"c=\"))\n",
+ "big = a\n",
+ "if b>big :\n",
+ " big = b\n",
+ "if c>big :\n",
+ " big = c\n",
+ "print \"Largest of the three numbers = %7.2f\" %big"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input a b c\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a=10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "b=20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c=45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Largest of the three numbers = 45.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example ifelse1.c, page no. 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#the program will remain same as the previous one\n",
+ "\n",
+ "print \"Input your age in years: \",\n",
+ "years =(raw_input())\n",
+ "try:\n",
+ " float(years)\n",
+ " secs = float(years) * 365 * 24 * 60 * 60\n",
+ " print \"you have lived for %f seconds\" %secs\n",
+ "except:\n",
+ " print \"the input is not a floating-point number\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input your age in years: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " you have lived for 3153600000.000000 seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example ifelse2.c, page no. 107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "input1 = int(raw_input(\"Input an integer: \"))\n",
+ "if input1 :\n",
+ " print \"It is non-zero.\"\n",
+ "else :\n",
+ " print \"it is zero.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input an integer: 12\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "It is non-zero.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example scope.c, page no. 112"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#The block given in the textbook is not possible in Python. Here the value will remain the same.\n",
+ "\n",
+ "i = 10\n",
+ "print \"In main. i is %d \" %i\n",
+ "i = 20\n",
+ "print \"In compound statement. i is %d\" %i\n",
+ "i = i+1\n",
+ "print \"After incrementing: i is %d\" %i\n",
+ "print \"In main again. i is %d\" %i"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In main. i is 10 \n",
+ "In compound statement. i is 20\n",
+ "After incrementing: i is 21\n",
+ "In main again. i is 21\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example for.c, page no. 113"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "for i in range(1, 11):\n",
+ " print i*5,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5 10 15 20 25 30 35 40 45 50\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example sumsq1.c, page no. 115"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "sum = 0\n",
+ "sum_of_squares = 0\n",
+ "for i in range(2, 31, 2):\n",
+ " sum += i\n",
+ " sum_of_squares += i*i\n",
+ "print \"Sum of first 15 positive even numbers = \", sum\n",
+ "print \"Sum of their squares = \", sum_of_squares"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sum of first 15 positive even numbers = 240\n",
+ "Sum of their squares = 4960\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example sumsq2.c, page no. 116"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "sum = 0\n",
+ "sum_of_squares = 0\n",
+ "for i in range(30, 1, -2):\n",
+ " sum += i\n",
+ " sum_of_squares += i*i\n",
+ "print \"Sum of first 15 positive even numbers = \", sum\n",
+ "print \"Sum of their squares = \", sum_of_squares"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sum of first 15 positive even numbers = 240\n",
+ "Sum of their squares = 4960\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example for2.c, page no. 116"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "for i in range(1, 11):\n",
+ " print 5*i,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5 10 15 20 25 30 35 40 45 50\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.1, page no. 117"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#error in textbook, i should be initialized by 1\n",
+ "\n",
+ "sign = 1\n",
+ "print \"Input X and N: \"\n",
+ "x = float(raw_input(\"X: \"))\n",
+ "n = int(raw_input(\"N: \"))\n",
+ "x *= 3.1412/180.0\n",
+ "sum, t = x, x\n",
+ "for i in range(1, n):\n",
+ " sign *=-1\n",
+ " t = sign * x * x / (2*i*(2*i+1))\n",
+ " sum += t\n",
+ "print \"SIN(X) = %6.2f\" %sum"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input X and N: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X: 60\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "N: 12\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "SIN(X) = 0.90\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.2, page no. 118"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "num = 0\n",
+ "sum = 0\n",
+ "print \"Input the marks, -1 at the end\"\n",
+ "i = int(raw_input())\n",
+ "while i != -1:\n",
+ " sum += i\n",
+ " num += 1\n",
+ " i = int(raw_input())\n",
+ "average = sum / num\n",
+ "print \"The average is %.2f\" %average"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the marks, -1 at the end\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "14\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "16\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "18\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The average is 15.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example binary.c, page no. 120"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "binary = raw_input(\"Input the binary number: \")\n",
+ "decimal = int(binary, 2)\n",
+ "print \"The decimal equivalent of binary number %s is %d\" %(binary, decimal)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the binary number: 1101\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The decimal equivalent of binary number 1101 is 13\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example dowhile.c, page no. 122"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#there is no do while loop in Python. We will use simple while loop\n",
+ "inchar = ''\n",
+ "while(inchar != 'y' and inchar != 'n'):\n",
+ " inchar = raw_input(\"Input y or n: \")\n",
+ "if inchar == 'y':\n",
+ " print \"you pressed y.\"\n",
+ "if inchar == 'n':\n",
+ " print \"you pressed n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input y or n: j\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input y or n: j\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input y or n: n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "you pressed n\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4, page no. 123"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "num = int(raw_input(\"Input the number: \"))\n",
+ "n = num\n",
+ "sum = 0\n",
+ "rev = 0\n",
+ "while(num != 0):\n",
+ " digit = num % 10\n",
+ " sum += digit\n",
+ " rev = rev * 10 + digit\n",
+ " num /= 10\n",
+ "print \"Sum of the digits of the number = %4d\" %sum\n",
+ "print \"Reverse of the number = %7d\" %rev\n",
+ "if n == rev:\n",
+ " print \"The number is a palindrome\"\n",
+ "else:\n",
+ " print \"The number is not a palindrome\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the number: 1221\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sum of the digits of the number = 6\n",
+ "Reverse of the number = 1221\n",
+ "The number is a palindrome\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example iflese.c, page no. 127"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "print \"Choice of destinations: \"\n",
+ "print \"\\t1 - Mercury\"\n",
+ "print \"\\t2 - Venus\"\n",
+ "print \"\\t3 - Mars\"\n",
+ "choice = int(raw_input(\"Enter the number corresponding to your choice: \"))\n",
+ "if choice == 1:\n",
+ " print \"Mercury is closest to the sun.\"\n",
+ " print \"So the weather may be quite hot there.\"\n",
+ " print \"The journey will cost you 5200 IGCs.\"\n",
+ "elif choice == 2:\n",
+ " print \"Venus is the second planet from the sun.\"\n",
+ " print \"The weather may be hot and poisonous.\"\n",
+ " print \"The journey will cost you 3200 IGCs.\"\n",
+ "elif choice == 3:\n",
+ " print \"Mars is the closest planet to the earth.\"\n",
+ " print \"The weather has been excellent till now.\"\n",
+ " print \"The journey will cost you 1200 IGCs.\"\n",
+ "else:\n",
+ " \"Unknown destination. Unpredictable IGCs\"\n",
+ "print \"Note: IGC = Ingeer-Galactic Currency\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Choice of destinations: \n",
+ "\t1 - Mercury\n",
+ "\t2 - Venus\n",
+ "\t3 - Mars\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number corresponding to your choice: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Venus is the second planet from the sun.\n",
+ "The weather may be hot and poisonous.\n",
+ "The journey will cost you 3200 IGCs.\n",
+ "Note: IGC = Ingeer-Galactic Currency\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.5, page no. 128"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#there is no switch case in Python, hence, no use of break in if conditions. So, the program will remain same\n",
+ "\n",
+ "print \"Choice of destinations: \"\n",
+ "print \"\\t1 - Mercury\"\n",
+ "print \"\\t2 - Venus\"\n",
+ "print \"\\t3 - Mars\"\n",
+ "choice = int(raw_input(\"Enter the number corresponding to your choice: \"))\n",
+ "if choice == 1:\n",
+ " print \"Mercury is closest to the sun.\"\n",
+ " print \"So the weather may be quite hot there.\"\n",
+ " print \"The journey will cost you 5200 IGCs.\"\n",
+ "elif choice == 2:\n",
+ " print \"Venus is the second planet from the sun.\"\n",
+ " print \"The weather may be hot and poisonous.\"\n",
+ " print \"The journey will cost you 3200 IGCs.\"\n",
+ "elif choice == 3:\n",
+ " print \"Mars is the closest planet to the earth.\"\n",
+ " print \"The weather has been excellent till now.\"\n",
+ " print \"The journey will cost you 1200 IGCs.\"\n",
+ "else:\n",
+ " \"Unknown destination. Unpredictable IGCs\"\n",
+ "print \"Note: IGC = Ingeer-Galactic Currency\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Choice of destinations: \n",
+ "\t1 - Mercury\n",
+ "\t2 - Venus\n",
+ "\t3 - Mars\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number corresponding to your choice: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mars is the closest planet to the earth.\n",
+ "The weather has been excellent till now.\n",
+ "The journey will cost you 1200 IGCs.\n",
+ "Note: IGC = Ingeer-Galactic Currency\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6, page no. 130"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Input a b & c\"\n",
+ "a = float(raw_input(\"a: \"))\n",
+ "b = float(raw_input(\"b: \"))\n",
+ "c = float(raw_input(\"c: \"))\n",
+ "if a != 0:\n",
+ " disc = b * b - 4 * a * c\n",
+ " print \"Discriminant = %5.2f\" %disc\n",
+ " if disc < 0:\n",
+ " k = 1\n",
+ " elif disc == 0:\n",
+ " k = 2\n",
+ " elif disc > 0:\n",
+ " k = 3\n",
+ " if k == 1:\n",
+ " print \"Roots are imaginary\"\n",
+ " real = -b/(2*a)\n",
+ " disc = -disc\n",
+ " num = pow(disc, 0.5)\n",
+ " imag = num/(2*a)\n",
+ " print \"Root1 = %5.2f +j %5.2f\" %(real, imag)\n",
+ " print \"Root2 = %5.2f -j %5.2f\" %(real, imag)\n",
+ " elif k == 2:\n",
+ " print \"Roots are real equal\"\n",
+ " root1 = -b/(2*a)\n",
+ " print \"Root1 = Root2 = %7.2f\" %root1\n",
+ " elif k == 3:\n",
+ " print \"Roots are real and unequal\"\n",
+ " root1 = (-b + sqrt(disc))/(2*a)\n",
+ " root2 = (-b - sqrt(disc))/(2*a)\n",
+ " print \"Root1 = %7.2f Root2 = %7.2f\" %(root1, root2)\n",
+ "else:\n",
+ " print \"Equation is linear\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input a b & c\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "b: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c: 7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Discriminant = -24.00\n",
+ "Roots are imaginary\n",
+ "Root1 = -1.00 +j 2.45\n",
+ "Root2 = -1.00 -j 2.45\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7, page no. 132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "sum = 0\n",
+ "for i in range(5):\n",
+ " num = int(raw_input(\"Enter an integer: \"))\n",
+ " if num < 0:\n",
+ " print \"You have entered a negative number\"\n",
+ " continue\n",
+ " sum += num\n",
+ "print \"The sum of positive integers entered = \", sum"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an integer: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an integer: -15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You have entered a negative number\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an integer: 15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an integer: -100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You have entered a negative number\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an integer: 30\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The sum of positive integers entered = 55\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8, page no. 133"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Input X & N\"\n",
+ "x = float(raw_input(\"X: \"))\n",
+ "n = int(raw_input(\"N: \"))\n",
+ "t = 1\n",
+ "sum = 1\n",
+ "for i in range(1, n):\n",
+ " ifact = i\n",
+ " t = t*x/ifact\n",
+ " sum +=t\n",
+ "print \"E raies to power x = %10.4f\" %sum"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input X & N\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X: 1.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "N: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "E raies to power x = 2.0000\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.9, page no. 134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n = int(raw_input(\"Enter the number: \"))\n",
+ "if n == 0:\n",
+ " print \"The factorial of 0 is 1\"\n",
+ "else:\n",
+ " fact = 1\n",
+ " for i in range(1, n+1):\n",
+ " fact = fact * i\n",
+ " print \"Factorial of %4d is %5d\" %(n, fact)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Factorial of 5 is 120\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.10, page no. 135"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "binom = 1\n",
+ "q = 0\n",
+ "p = int(raw_input(\"Input the number of rows: \"))\n",
+ "print \"Pascal Triangle\"\n",
+ "while q < p:\n",
+ " for r in range(40-3*q, 0, -1):\n",
+ " print \" \",\n",
+ " for x in range(0, q+1):\n",
+ " if x == 0 or q == 0:\n",
+ " binom = 1\n",
+ " else:\n",
+ " binom = (binom*(q-x+1))/x\n",
+ " print \"%6d\" %binom,\n",
+ " print \"\\n\"\n",
+ " q+=1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the number of rows: 9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pascal Triangle\n",
+ " 1 \n",
+ "\n",
+ " 1 1 \n",
+ "\n",
+ " 1 2 1 \n",
+ "\n",
+ " 1 3 3 1 \n",
+ "\n",
+ " 1 4 6 4 1 \n",
+ "\n",
+ " 1 5 10 10 5 1 \n",
+ "\n",
+ " 1 6 15 20 15 6 1 \n",
+ "\n",
+ " 1 7 21 35 35 21 7 1 \n",
+ "\n",
+ " 1 8 28 56 70 56 28 8 1 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.11, page no. 136"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "print \"Enter 1 for triangle(3 sides) & 2 for triangle(base, ht): \",\n",
+ "k = int(raw_input())\n",
+ "if k == 1:\n",
+ " print \"Enter 3 sides - a,b and c\"\n",
+ " a = float(raw_input(\"a: \"))\n",
+ " b = float(raw_input(\"b: \"))\n",
+ " c = float(raw_input(\"c: \"))\n",
+ " p = a + b + c\n",
+ " s = (a + b + c)/2\n",
+ " area = math.sqrt(s*(s-a)*(s-b)*(s-c))\n",
+ " print \"Perimeter = %6.2f\" %p\n",
+ " print \"Area of triangle = %7.2f\" %area\n",
+ "elif k == 2:\n",
+ " print \"Enter height and base\"\n",
+ " height = float(raw_input(\"height: \"))\n",
+ " base = float(raw_input(\"base: \"))\n",
+ " area = (base*height)/2\n",
+ " print \"Area of triangle = %7.2f\" %area"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 1 for triangle(3 sides) & 2 for triangle(base, ht): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 3 sides - a,b and c\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a: 4.55\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "b: 5.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c: 6.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Perimeter = 15.55\n",
+ "Area of triangle = 11.11\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.12, page no. 137"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "print \"Enter the no of lines in the pyramid: \"\n",
+ "t = int(raw_input())\n",
+ "print \"\\t\\tREVERSED PYRAMID OF DIGITS\"\n",
+ "k = 0\n",
+ "for p in range(t, 0, -1):\n",
+ " k += 1\n",
+ " sys.stdout.write (\" \")\n",
+ " for r in range(0, (k*4)+1):\n",
+ " sys.stdout.write (\" \")\n",
+ " for q in range(p, (2*p)-1): \n",
+ " sys.stdout.write (\"%4d\" %q)\n",
+ " for s in range((2*p)-2, p-1, -1):\n",
+ " sys.stdout.write(\"%4d\\b\" %s)\n",
+ " sys.stdout.write (\"\\n\")\n",
+ "print \" %d\" %p\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the no of lines in the pyramid: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\t\tREVERSED PYRAMID OF DIGITS\n",
+ " 7 8 9 10 11 12 12\b 11\b 10\b 9\b 8\b 7\b\n",
+ " 6 7 8 9 10 10\b 9\b 8\b 7\b 6\b\n",
+ " 5 6 7 8 8\b 7\b 6\b 5\b\n",
+ " 4 5 6 6\b 5\b 4\b\n",
+ " 3 4 4\b 3\b\n",
+ " 2 2\b\n",
+ " \n",
+ " 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.13, page no. 137"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "n = 20\n",
+ "x = float(raw_input(\"Input x: \"))\n",
+ "x = x*3.1412/180\n",
+ "t = 1\n",
+ "sum = 1\n",
+ "for i in range(1, n+1):\n",
+ " t = t*pow(-1, (2*i-1))*x*x/(2*i*(2*i-1))\n",
+ " sum += t\n",
+ "print \"COS(X) = %7.3f\" %sum"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input x: 90.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "COS(X) = 0.000\n"
+ ]
+ }
+ ],
+ "prompt_number": 62
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.14, page no. 138"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n = int(raw_input(\"Enter the number of lines: \"))\n",
+ "for p in range(1, n+1):\n",
+ " for i in range(1, n-p):\n",
+ " print \" \",\n",
+ " m = p\n",
+ " for q in range(1, p+1):\n",
+ " print \"%4d\" %m,\n",
+ " m +=1\n",
+ " m = m - 2\n",
+ " for q in range(1, p):\n",
+ " print \"%4d\" %m,\n",
+ " m-=1\n",
+ " print \"\\n\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number of lines: 7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1 \n",
+ "\n",
+ "\n",
+ " 2 3 2 \n",
+ "\n",
+ "\n",
+ " 3 4 5 4 3 \n",
+ "\n",
+ "\n",
+ " 4 5 6 7 6 5 4 \n",
+ "\n",
+ "\n",
+ " 5 6 7 8 9 8 7 6 5 \n",
+ "\n",
+ "\n",
+ " 6 7 8 9 10 11 10 9 8 7 6 \n",
+ "\n",
+ "\n",
+ " 7 8 9 10 11 12 13 12 11 10 9 8 7 \n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 67
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/chapter5.ipynb b/Mastering_C/chapter5.ipynb
new file mode 100644
index 00000000..277c10b6
--- /dev/null
+++ b/Mastering_C/chapter5.ipynb
@@ -0,0 +1,1515 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:ce6594f5391167e50e92652dc99b5d59ded886787329ad2d8f4011e41b7e20c7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5: Functions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example main.c, page no. 157"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Welcome to functions\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Welcome to functions\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example prtmsg2.c, page no. 158"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def PrintMesg():\n",
+ " print \"PrintMesg, Welcome to functions\"\n",
+ "print \"Main, Welcome to functions\"\n",
+ "PrintMesg()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Main, Welcome to functions\n",
+ "PrintMesg, Welcome to functions\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.1, page no. 160"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def cube(i):\n",
+ " return i*i*i\n",
+ "print \"The ccube of 10 is\", cube(10)\n",
+ "input_int = int(raw_input(\"Input an integer: \"))\n",
+ "print \"The cube of \", input_int, \"is \", cube(input_int)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The ccube of 10 is 1000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input an integer: 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The cube of 20 is 8000\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2, page no. 161"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#there is no concept of function declaration in Python, program will remain same as above\n",
+ "def cube(i):\n",
+ " return i*i*i\n",
+ "print \"The cube of 10 is\", cube(10)\n",
+ "input_int = int(raw_input(\"Input an integer: \"))\n",
+ "print \"The cube of \", input_int, \"is \", cube(input_int)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The cube of 10 is 1000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input an integer: 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The cube of 20 is 8000\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.3, page no. 163"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#\\a for the beed would not work in Python\n",
+ "\n",
+ "def cube(i):\n",
+ " return i*i*i\n",
+ "print \"The cube of 10 is\", cube(10)\n",
+ "input_int = int(raw_input(\"Input an integer: \"))\n",
+ "if input_int < 1:\n",
+ " print \"Input is invalid!\"\n",
+ "else:\n",
+ " print \"The cube of \", input_int, \"is \", cube(input_int)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The cube of 10 is 1000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input an integer: -9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input is invalid!\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4, page no. 164"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#there is no concept of function declaration in Python. So, the program will remain same as above\n",
+ "\n",
+ "def cube(i):\n",
+ " return i*i*i\n",
+ "print \"The cube of 10 is\", cube(10)\n",
+ "input_int = int(raw_input(\"Input an integer: \"))\n",
+ "if input_int < 1:\n",
+ " print \"Input is invalid!\"\n",
+ "else:\n",
+ " print \"The cube of \", input_int, \"is \", cube(input_int)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The cube of 10 is 1000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input an integer: 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The cube of 20 is 8000\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7, page no. 165"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def maxfunc(i, j , k):\n",
+ " if i >= j and i >= k:\n",
+ " max = i\n",
+ " elif j >=k :\n",
+ " max = j\n",
+ " else:\n",
+ " max = k\n",
+ " return max\n",
+ "print \"Input 3 numbers\"\n",
+ "a = int(raw_input(\"a: \"))\n",
+ "b = int(raw_input(\"b: \"))\n",
+ "c = int(raw_input(\"c: \"))\n",
+ "m = maxfunc(a, b, c)\n",
+ "print \"The maximum is \", m"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input 3 numbers\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "b: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum is 6\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example funded.c, page no. 168"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def max(a, b):\n",
+ " return a if a > b else b\n",
+ "print \"Enter 2 numbers\"\n",
+ "i = int(raw_input(\"i: \"))\n",
+ "j = int(raw_input(\"j: \"))\n",
+ "iMax = max(i,j)\n",
+ "print \"The maximum of %d and %d is %d\" %(i, j, iMax)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 2 numbers\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "j: 7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum of 5 and 7 is 7\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example square1.c, page no. 169"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def SquareInt(x):\n",
+ " return x**2\n",
+ "Sq = SquareInt(32)\n",
+ "print \"The square of 32 is\", Sq"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The square of 32 is 1024\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5, page no. 170"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Min(m, n):\n",
+ " if m > n:\n",
+ " MinNum = n\n",
+ " else:\n",
+ " MinNum = m\n",
+ " return MinNum\n",
+ "print \"Enter 2 numbers\"\n",
+ "a = int(raw_input(\"a: \"))\n",
+ "b = int(raw_input(\"b: \"))\n",
+ "Small = Min(a,b)\n",
+ "print \"The minimum of 2 numbers is \", Small\n",
+ "print \"The minimum of 2 numbers is \", Min(a,b)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 2 numbers\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a: 32567\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "b: 32657\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum of 2 numbers is 32567\n",
+ "The minimum of 2 numbers is 32567\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example pval.c, page no. 171"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def ModifierFunc(Num):\n",
+ " print \"In function, the value of Num is %d\" %Num\n",
+ " Num = 19\n",
+ " print \"In function, after changing, value of Num is: %d\" %Num\n",
+ "Num = 100\n",
+ "print \"In Main, the value of num is %d\" %Num\n",
+ "ModifierFunc(Num)\n",
+ "print \"After calling function, the value of Num is %d\" %Num"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In Main, the value of num is 100\n",
+ "In function, the value of Num is 100\n",
+ "In function, after changing, value of Num is: 19\n",
+ "After calling function, the value of Num is 100\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example swap1.c, page no. 172"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(a, b):\n",
+ " temp = a\n",
+ " a = b\n",
+ " b = temp\n",
+ "print \"Input 2 integers\"\n",
+ "i = int(raw_input(\"i: \"))\n",
+ "j = int(raw_input(\"j: \"))\n",
+ "print \"Before Swapping: \", i, j\n",
+ "swap(i, j)\n",
+ "print \"After Swapping: \", i , j"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input 2 integers\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "j: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Before Swapping: 3 5\n",
+ "After Swapping: 3 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example swap2.c, page no. 173"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(l):\n",
+ " temp = l[0]\n",
+ " l[0] = l[1]\n",
+ " l[1] = temp\n",
+ " return l\n",
+ "print \"Input 2 integers\"\n",
+ "i = int(raw_input(\"i: \"))\n",
+ "j = int(raw_input(\"j: \"))\n",
+ "print \"Before Swapping: \", i, j\n",
+ "a = [i, j]\n",
+ "l = swap(a)\n",
+ "print \"After Swapping: \", l[0] , l[1]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input 2 integers\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "j: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Before Swapping: 3 5\n",
+ "After Swapping: 5 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6, page no. 174"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def fact(n):\n",
+ " if n == 0:\n",
+ " lfact = 1\n",
+ " else:\n",
+ " lfact = 1\n",
+ " for i in range(2, n+1):\n",
+ " lfact = lfact * i\n",
+ " return lfact\n",
+ "num = int(raw_input(\"Enter a positive number: \"))\n",
+ "factorial = fact(num)\n",
+ "print \"The factorial of %d is %d\" %(num, factorial)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a positive number: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The factorial of 5 is 120\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.7, page no. 174"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def SumTwo(n1, n2):\n",
+ " return n1+n2\n",
+ "def SumThree(n1, n2, n3):\n",
+ " return n1+n2+n3\n",
+ "i = 56\n",
+ "j = 32\n",
+ "SumTwo(3, 4)\n",
+ "SumTwo(i, j), SumThree(100, i, j)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 19,
+ "text": [
+ "(88, 188)"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.8, page no. 175"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#mistake in the book, it should print both 0 & 1 at the start instead of just 0\n",
+ "\n",
+ "def Fib(TotNum):\n",
+ " fLast = 1\n",
+ " sLast = 0\n",
+ " print \"Fibonacci numbers: \"\n",
+ " print \"0 1\",\n",
+ " while(TotNum > 2):\n",
+ " CurNum = fLast + sLast\n",
+ " print CurNum,\n",
+ " sLast = fLast\n",
+ " fLast = CurNum\n",
+ " TotNum -= 1\n",
+ "print \"Program to generate fibonacci numbers\"\n",
+ "print \"Enter the total numbers to be generated: \",\n",
+ "n = int(raw_input())\n",
+ "Fib(n)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Program to generate fibonacci numbers\n",
+ "Enter the total numbers to be generated: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Fibonacci numbers: \n",
+ "0 1 1 2 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.9, page no. 176"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Sum20():\n",
+ " sum = 0\n",
+ " for i in range(1, 21):\n",
+ " sum += i\n",
+ " return sum\n",
+ "print \"Program to print the sum of first 20 numbers\"\n",
+ "print \"The sum of first 20 number is \", Sum20()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Program to print the sum of first 20 numbers\n",
+ "The sum of first 20 number is 210\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.10, page no. 176"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def isPalindrome(string):\n",
+ " len1 = len(string)\n",
+ " if len1 == 0:\n",
+ " return True\n",
+ " if string==string[::-1]:\n",
+ " return True\n",
+ " return False\n",
+ "\n",
+ "print \"Program to test the given string is a palindrome\"\n",
+ "string = raw_input(\"Enter a string : \")\n",
+ "if isPalindrome(string):\n",
+ " print \"The given string %s is a palindrome\"%string\n",
+ "else:\n",
+ " print \"The given string %s is not a palindrome\"%string"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Program to test the given string is a palindrome\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string : ratsdrowninwordstar\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The given string ratsdrowninwordstar is a palindrome\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example ifact.c, page no. 178"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def calc_fact(num):\n",
+ " fact = 1\n",
+ " for i in range(num, 1, -1):\n",
+ " fact *= i\n",
+ " return fact\n",
+ "n = int(raw_input(\"Enter an integer: \"))\n",
+ "print \"The factorial of %d is %d\" %(n, calc_fact(n))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an integer: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The factorial of 5 is 120\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.11, page no. 179"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#output will differ as there is no concept of static in Python\n",
+ "i = 1\n",
+ "def CountNumber(n):\n",
+ " global i\n",
+ " print \"In the function the value of n is %d\" %n\n",
+ " print \"The depth of the call is: %d\" %i\n",
+ " i +=1\n",
+ " if n > 1:\n",
+ " CountNumber(n-1)\n",
+ " print \"After recurssive the value of i is %d\" %i\n",
+ "num = 3\n",
+ "CountNumber(num)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In the function the value of n is 3\n",
+ "The depth of the call is: 1\n",
+ "In the function the value of n is 2\n",
+ "The depth of the call is: 2\n",
+ "In the function the value of n is 1\n",
+ "The depth of the call is: 3\n",
+ "After recurssive the value of i is 4\n",
+ "After recurssive the value of i is 4\n",
+ "After recurssive the value of i is 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example fibrec1.c, page no. 180"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def uFibr(uNum):\n",
+ " if uNum == 0:\n",
+ " return 0\n",
+ " elif uNum == 1:\n",
+ " return 1\n",
+ " else:\n",
+ " return uFibr(uNum-1)+uFibr(uNum-2)\n",
+ "uTnum = int(raw_input(\"Enter how many number are to be generated: \"))\n",
+ "print \"The Fibonacci sequences are: \"\n",
+ "for uIndex in range(uTnum):\n",
+ " print \"%u\" %uFibr(uIndex),"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter how many number are to be generated: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Fibonacci sequences are: \n",
+ "0 1 1 2 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example fiborec2.c, page no. 181"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "f1 = 0\n",
+ "f2 = 1\n",
+ "def Fib(n):\n",
+ " global f1,f2\n",
+ " if n < 2:\n",
+ " f1 = 0\n",
+ " f2 = 1\n",
+ " else:\n",
+ " Fib(n-1)\n",
+ " temp = f2\n",
+ " f2 = f1+f2\n",
+ " f1 = temp\n",
+ "print \"Number of terms to be generated ?\",\n",
+ "n = int(raw_input())\n",
+ "print \"Fibonacci sequence up to %d terms: \" %n,Fib(n)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of terms to be generated ?"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Fibonacci sequence up to 10 terms: 0 1 1 2 3 5 8 13 21 34 None\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Eample 5.13, page no. 184"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def gcd(p, q):\n",
+ " remainder = p-(p/q*q)\n",
+ " if remainder == 0:\n",
+ " return q\n",
+ " else:\n",
+ " return gcd(q, remainder)\n",
+ "print \"Type in any 2 nubers whose GCD is to be found: \"\n",
+ "a = int(raw_input(\"a: \"))\n",
+ "b = int(raw_input(\"b: \"))\n",
+ "iGcd = gcd(a, b)\n",
+ "print iGcd\n",
+ "print \"GCD of %d and %d is %d\" %(a, b, iGcd)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type in any 2 nubers whose GCD is to be found: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a: 13\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "b: 45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n",
+ "GCD of 13 and 45 is 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.14, page no. 185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def hanoi(n, sndl, indl, dndl):\n",
+ " if n != 0:\n",
+ " hanoi(n-1, sndl, dndl, indl)\n",
+ " print \"Move disk %d from %c to %c\" %(n, sndl, dndl)\n",
+ " hanoi(n-1, indl, sndl, dndl)\n",
+ "snvalue = 'L'\n",
+ "invalue = 'C'\n",
+ "dnvalue = 'R'\n",
+ "print \"Enter the number of disks: \",\n",
+ "nvalue = int(raw_input())\n",
+ "print \"Tower of Hanoi problem with %d disks\" %nvalue\n",
+ "hanoi(nvalue, snvalue, invalue, dnvalue)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number of disks: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Tower of Hanoi problem with 3 disks\n",
+ "Move disk 1 from L to R\n",
+ "Move disk 2 from L to C\n",
+ "Move disk 1 from R to C\n",
+ "Move disk 3 from L to R\n",
+ "Move disk 1 from C to L\n",
+ "Move disk 2 from C to R\n",
+ "Move disk 1 from L to R\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.15, page nol 187"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "mid = 0\n",
+ "def binSrch(b, key, low, high):\n",
+ " global mid\n",
+ " if low <= high:\n",
+ " mid = int((low+high)/2)\n",
+ " if key < b[mid]:\n",
+ " high = mid - 1\n",
+ " return binSrch(b, key, low, high)\n",
+ " elif key > b[mid]:\n",
+ " low = mid + 1\n",
+ " return binSrch(b, key, low, high)\n",
+ " elif b[mid] == key:\n",
+ " return mid+1\n",
+ " else:\n",
+ " return 0\n",
+ "n = int(raw_input(\"Enter the size of array: \"))\n",
+ "print \"Array elements (ascending order) ?\"\n",
+ "a = []\n",
+ "for i in range(n):\n",
+ " a.append(int(raw_input()))\n",
+ "print \"Element to be searched ?\",\n",
+ "key = int(raw_input())\n",
+ "position = binSrch(a, key, 0, n-1)\n",
+ "if position == 0 :\n",
+ " print \"Unsuccessful search, %d not found\" %key\n",
+ "else:\n",
+ " print \"Successful search\"\n",
+ " print \"%d found at position %d\" %(key, position)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the size of array: 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Array elements (ascending order) ?\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "67\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "89\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "99\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element to be searched ?"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "99\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Successful search\n",
+ "99 found at position 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.16, page no. 188"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def my_max(j, n, a):\n",
+ " if n == 0:\n",
+ " return a[j]\n",
+ " else:\n",
+ " m1 = my_max(j, n/2, a)\n",
+ " m2 = my_max(j + n/2 + 1, n/2, a)\n",
+ " if m1 < m2:\n",
+ " return m2\n",
+ " else:\n",
+ " return m1\n",
+ "def my_min(j, n, a):\n",
+ " if n == 0:\n",
+ " return a[j]\n",
+ " else:\n",
+ " m1 = my_min(j, n/2, a)\n",
+ " m2 = my_min(j + n/2 + 1, n/2, a)\n",
+ " if m1 < m2:\n",
+ " return m1\n",
+ " else:\n",
+ " return m2\n",
+ "print \"Finding the maximum and minimum recursively\"\n",
+ "print \"Number of elements in vector ?\"\n",
+ "n = int(raw_input())\n",
+ "print \"Vector elements ?\"\n",
+ "x = []\n",
+ "for i in range(n):\n",
+ " x.append(int(raw_input()))\n",
+ "i = 0\n",
+ "m = n - 1\n",
+ "maxim = my_max(i, m, x)\n",
+ "print \"Maximum of %d elements is %d\" %(n, maxim)\n",
+ "i = 0\n",
+ "m = n - 1\n",
+ "minim = my_min(i,m,x)\n",
+ "print \"Minimum of %d elements is %d\" %(n, minim)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Finding the maximum and minimum recursively\n",
+ "Number of elements in vector ?\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vector elements ?\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "34\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "56\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "78\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "54\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "89\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum of 8 elements is 89\n",
+ "0 7 [12, 34, 56, 78, 54, -12, 0, 89]\n",
+ "Minimum of 8 elements is -12\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.17, page no. 189"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Command line arguments cannot be done using IPython notebook. Hence, skipping the example"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.18, page no. 190"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Command line arguments"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/chapter6.ipynb b/Mastering_C/chapter6.ipynb
new file mode 100644
index 00000000..99bf0cd9
--- /dev/null
+++ b/Mastering_C/chapter6.ipynb
@@ -0,0 +1,603 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:2b98cee86e6322a41a7dca7a85df32b68e0995a4fde2b6249b408a952c9387e4"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Scope & Extent"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example scope1.c, page no. 202"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#as mentioned in the textbook, the statement j = 30 will not give an error as in Python you can declare a vairable anywhere\n",
+ "#however, the statement does not refer to the variable j of the function.\n",
+ "def func():\n",
+ " j = 20\n",
+ " print \"j is a variable in the function\"\n",
+ " print \"Value of j is \",j\n",
+ "i = 10\n",
+ "print \"i is a variable in main.\"\n",
+ "print \"Value of i is \", i\n",
+ "print \"Calling func...\"\n",
+ "func()\n",
+ "j = 30"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i is a variable in main.\n",
+ "Value of i is 10\n",
+ "Calling func...\n",
+ "j is a variable in the function\n",
+ "Value of j is 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example global.c, page no. 202"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "g = 0\n",
+ "def func():\n",
+ " global g\n",
+ " print \"In func. g is visbile here, since it is global\"\n",
+ " print \"Incrementing g in func...\"\n",
+ " g += 1\n",
+ " return g\n",
+ "print \"In main. g is visible here, since it is global\"\n",
+ "print \"assigning 20 to g in main...\"\n",
+ "g = 20\n",
+ "print \"Callint func...\"\n",
+ "func()\n",
+ "print \"func returned g is \", g"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In main. g is visible here, since it is global\n",
+ "assigning 20 to g in main...\n",
+ "Callint func...\n",
+ "In func. g is visbile here, since it is global\n",
+ "Incrementing g in func...\n",
+ "func returned g is 21\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example colcolon.c, page no. 203"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#there is no concept of scope resolution operator in Python. we will do it in different way\n",
+ "a = 10\n",
+ "def func():\n",
+ " global a\n",
+ " b = 20\n",
+ " print b\n",
+ " print a\n",
+ "func()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "20\n",
+ "10\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.1, page no. 204"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#there is no concept of block in Python. writing if True is smiliar to it but still, output will differ\n",
+ "j = 144\n",
+ "print \"The value of j outside the block is \", j\n",
+ "if True:\n",
+ " j = 12\n",
+ " print \"The value of j inside the block is \", j\n",
+ "print \"The value of j outside the block is \", j"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of j outside the block is 144\n",
+ "The value of j inside the block is 12\n",
+ "The value of j outside the block is 12\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.2, page no. 205"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i = 144\n",
+ "j = 132\n",
+ "print \"i = \", i\n",
+ "if True:\n",
+ " k = 12\n",
+ " k = int(raw_input())\n",
+ " i = i%k\n",
+ "if i == 0:\n",
+ " print \"i is a divisor of %d \" %k"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i = 144\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "25\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3, page no. 205"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "iNum = 5\n",
+ "jNum = 30\n",
+ "if True:\n",
+ " iNum = 10\n",
+ " print \"%d %d\" %(iNum, jNum)\n",
+ "print \"%d %d\" %(iNum, jNum)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 30\n",
+ "10 30\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7, page no. 207"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "cName = raw_input(\"Enter a string: \")\n",
+ "print \"The reverse of the string is: \"\n",
+ "print cName[::-1]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string: this is a string\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reverse of the string is: \n",
+ "gnirts a si siht\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.4 pageno : 206"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "iGlobal = 35\n",
+ "Number = 47\n",
+ "iVal = 99\n",
+ "Number = 1000\n",
+ "print \"The value of local variable Number is %d\"%Number\n",
+ "print \"The value of global variable iGlobal is %d\"%iGlobal\n",
+ "print \"The value of global variable Number is %d\"%Number\n",
+ "print \"The value of static global variable iVal is %d\"%iVal\n",
+ "\n",
+ "# Python has no static functionality. and also local variable changes value when value assigned to it."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of local variable Number is 1000\n",
+ "The value of global variable iGlobal is 35\n",
+ "The value of global variable Number is 1000\n",
+ "The value of static global variable iVal is 99\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.5, page no. 208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Count = 1\n",
+ "def PrintCount():\n",
+ " global Count\n",
+ " print \"Count = %d\" %Count\n",
+ " Count = Count + 1\n",
+ "PrintCount()\n",
+ "PrintCount()\n",
+ "PrintCount()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Count = 1\n",
+ "Count = 2\n",
+ "Count = 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6, page no.208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "uF1 = 0\n",
+ "uF2 = 1\n",
+ "def PrintNextFibo():\n",
+ " global uF1,uF2\n",
+ " uFpre = uF1 + uF2\n",
+ " print \"%d\" %uFpre ,\n",
+ " uF2 = uF1\n",
+ " uF1 = uFpre\n",
+ "print \"Fibonacci sequences using static variables :\"\n",
+ "print \"Enter how many number are to be generated :\",\n",
+ "itotNum = int(raw_input())\n",
+ "print \"The first %d fibonacci numbers are\" %itotNum\n",
+ "for iIndex in range(1,itotNum+1):\n",
+ " PrintNextFibo()\n",
+ "\n",
+ "# it starts with zero but here function created called uses global variable so we need to print/assume manually zero value."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Fibonacci sequences using static variables :\n",
+ "Enter how many number are to be generated :"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The first 5 fibonacci numbers are\n",
+ "1 1 2 3 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 209"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import linsrch\n",
+ "import bubble\n",
+ "arr = []\n",
+ "num = 5\n",
+ "i = 0\n",
+ "pos = 1\n",
+ "print \"Enter five elements\"\n",
+ "while i < num:\n",
+ " arr.append(int(raw_input()))\n",
+ " i+=1\n",
+ "print \"Enter element to be searched: \",\n",
+ "key = int(raw_input())\n",
+ "pos = linsrch.LinSrch(arr, num, key)\n",
+ "if pos:\n",
+ " print \"Element %d found at %d position\" %(key, pos)\n",
+ "else:\n",
+ " print \"Ellement %d not found\" %key\n",
+ "bubble.BubSort(arr, num)\n",
+ "print \"The sorted element are\"\n",
+ "for ele in arr:\n",
+ " print ele,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter five elements\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "56\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "48\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "22\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter element to be searched: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "22\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Element 22 found at 5 position\n",
+ "The sorted element are\n",
+ "12 15 22 48 56\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import myglobal\n",
+ "globalVar = 10\n",
+ "print \"globalVar before calling = \", globalVar\n",
+ "myglobal.inc_global(globalVar)\n",
+ "print \"globalVar after calling \", globalVar"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "globalVar before calling = 10\n",
+ "globalVar after calling 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 212"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import myglobal\n",
+ "\n",
+ "globalVar = 10\n",
+ "print \"globalVar before calling = \", globalVar\n",
+ "g = myglobal.inc_global(globalVar)\n",
+ "print \"globalVar after calling \", g"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "globalVar before calling = 10\n",
+ "globalVar after calling 11\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/chapter7.ipynb b/Mastering_C/chapter7.ipynb
new file mode 100644
index 00000000..e41cbc36
--- /dev/null
+++ b/Mastering_C/chapter7.ipynb
@@ -0,0 +1,2482 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:df255fa9a4e53028d13370030da5fb9293c0b07c60111131baf99b22bd751792"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7 : Array and Strings"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, page no. 221"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "sum = 0\n",
+ "a1 = int(raw_input(\"Age:\"))\n",
+ "sum += a1\n",
+ "a2 = int(raw_input(\"Age:\"))\n",
+ "sum += a2\n",
+ "a3 = int(raw_input(\"Age:\"))\n",
+ "sum += a3\n",
+ "a4 = int(raw_input(\"Age:\"))\n",
+ "sum += a4\n",
+ "a5 = int(raw_input(\"Age:\"))\n",
+ "sum += a5\n",
+ "print \"The ages that were input are:\"\n",
+ "print a1\n",
+ "print a2\n",
+ "print a3\n",
+ "print a4\n",
+ "print a5\n",
+ "print \"Average = %d\" %(sum/5)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:30\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:40\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age:50\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The ages that were input are:\n",
+ "10\n",
+ "20\n",
+ "30\n",
+ "40\n",
+ "50\n",
+ "Average = 30\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, page no. 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "sum = 0.0\n",
+ "age = []\n",
+ "n = int(raw_input(\"Number of persons:\"))\n",
+ "if n<=0 or n>5:\n",
+ " print \"Invalid number of person entered\"\n",
+ "else:\n",
+ " for i in range(n):\n",
+ " age.append(int(raw_input(\"Age :\")))\n",
+ " sum += age[i]\n",
+ " print \"The ages input are:\"\n",
+ " for i in range (n):\n",
+ " print age[i]\n",
+ " print \"The average is :\",(sum/n)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of persons:5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age :10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age :20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age :30\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age :40\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age :50\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The ages input are:\n",
+ "10\n",
+ "20\n",
+ "30\n",
+ "40\n",
+ "50\n",
+ "The average is : 30.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.1, page no. 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a = []\n",
+ "n = int(raw_input(\"Size of vector ? \"))\n",
+ "print \"Vector elements ? \"\n",
+ "for i in range (n):\n",
+ " a.append(float(raw_input()))\n",
+ "large = max(a)\n",
+ "small = min(a)\n",
+ "print \"Largest element in vector is %8.2f\" %large\n",
+ "print \"Smallest element in vector is %8.2f\" %small"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size of vector ? 7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vector elements ? \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "34.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-9.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-6.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "36.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Largest element in vector is 36.00\n",
+ "Smallest element in vector is -9.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2, page no. 226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a = []\n",
+ "n = int(raw_input(\"Size of vector ? \"))\n",
+ "print \"Vector elements ? \"\n",
+ "for i in range (n):\n",
+ " a.append(float(raw_input()))\n",
+ "for i in range (n-1):\n",
+ " for j in range(i+1,n):\n",
+ " if a[i]> a[j]:\n",
+ " a[i],a[j]=a[j],a[i]\n",
+ "print \"Vector elements in ascending order :\"\n",
+ "for i in range(n):\n",
+ " print \"%8.2f\" %a[i]\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size of vector ? 8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vector elements ? \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "91.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "20.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "34.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-2.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vector elements in ascending order :\n",
+ " -2.00\n",
+ " 1.00\n",
+ " 6.00\n",
+ " 7.00\n",
+ " 11.00\n",
+ " 20.00\n",
+ " 34.00\n",
+ " 91.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3, page no. 227"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a = []\n",
+ "n = int(raw_input(\"Size of vector ? \"))\n",
+ "print \"Vector elements ? \"\n",
+ "for i in range (n):\n",
+ " a.append(float(raw_input()))\n",
+ "item = float(raw_input(\"Element to be inserted ?\"))\n",
+ "pos = int(raw_input(\"Position of insertion ?\"))\n",
+ "a.insert(pos-1, item)\n",
+ "print \"Vector after insertion\"\n",
+ "for ele in a:\n",
+ " print ele,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size of vector ? 7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vector elements ? \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element to be inserted ?10.00\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Position of insertion ?1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vector after insertion\n",
+ "10.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example arrfunc.c, page no. 230"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "rollno = 4\n",
+ "subject = 3\n",
+ "def display(studentmarks):\n",
+ " for r in range(rollno):\n",
+ " print \"\\nRoll no.: \", r+1,\n",
+ " for s in range(subject):\n",
+ " print \"%10.2f\" %studentmarks[r][s],\n",
+ "marks =[[35.5, 40.5, 45.5],\n",
+ " [50.5, 55.5, 60.5],\n",
+ " [65.0, 70.0, 75.5],\n",
+ " [80.0, 85.0, 90.0]]\n",
+ "display(marks)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Roll no.: 1 35.50 40.50 45.50 \n",
+ "Roll no.: 2 50.50 55.50 60.50 \n",
+ "Roll no.: 3 65.00 70.00 75.50 \n",
+ "Roll no.: 4 80.00 85.00 90.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.4, page no. 240"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy\n",
+ "\n",
+ "a = numpy.zeros((10, 10))\n",
+ "b = numpy.zeros((10, 10))\n",
+ "c = numpy.zeros((10, 10))\n",
+ "\n",
+ "print \"Input row & column of A matrix: \"\n",
+ "n = int(raw_input(\"row: \"))\n",
+ "m = int(raw_input(\"column: \"))\n",
+ "\n",
+ "print \"Input row & column of B matrix: \"\n",
+ "p = int(raw_input(\"row: \"))\n",
+ "q = int(raw_input(\"column: \"))\n",
+ "\n",
+ "if n == p and m == q:\n",
+ " print \"Matrices can be added\"\n",
+ " print \"Input A matrix: \",\n",
+ " for i in range(n):\n",
+ " for j in range(m):\n",
+ " a[i][j] = int(raw_input())\n",
+ " print \"\"\n",
+ " print \"Input B matrix: \",\n",
+ " for i in range(p):\n",
+ " for j in range(q):\n",
+ " b[i][j] = int(raw_input())\n",
+ " print \"\"\n",
+ " for i in range(p):\n",
+ " for j in range(q):\n",
+ " c[i][j] = a[i][j] + b[i][j]\n",
+ " print \"Sum of A & B matrices: \"\n",
+ " for i in range(n):\n",
+ " for j in range(m):\n",
+ " print \"%5d\" %c[i][j],\n",
+ " print \"\"\n",
+ "else:\n",
+ " print \"Matricess cannot be added\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input row & column of A matrix: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "row: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "column: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input row & column of B matrix: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "row: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "column: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrices can be added\n",
+ "Input A matrix: "
+ ]
+ },
+ {
+ "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": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Input B matrix: "
+ ]
+ },
+ {
+ "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": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Sum of A & B matrices: \n",
+ " 2 4 6 \n",
+ " 8 10 12 \n",
+ " 14 16 18 \n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5, page no. 233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy\n",
+ "\n",
+ "a = numpy.zeros((10, 10))\n",
+ "print \"Enter the order of A matrix: \",\n",
+ "n = int(raw_input())\n",
+ "print \"Input A matrix\"\n",
+ "for i in range(n):\n",
+ " for j in range(n):\n",
+ " a[i][j] = int(raw_input())\n",
+ "trace = 0\n",
+ "for i in range(n):\n",
+ " trace += a[i][i]\n",
+ "print \"Trace = \", trace"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the order of A matrix: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Input A matrix\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": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Trace = 15.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 48
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.6, page no. 233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy\n",
+ "\n",
+ "def read_mat(a, m, n):\n",
+ " for i in range(m):\n",
+ " for j in range(n):\n",
+ " a[i][j] = int(raw_input())\n",
+ "def write_mat(a, m, n):\n",
+ " for i in range(m):\n",
+ " for j in range(n):\n",
+ " print \"%d\" %a[i][j],\n",
+ " print \"\"\n",
+ "\n",
+ "a = numpy.zeros((10, 10))\n",
+ "b = numpy.zeros((10, 10))\n",
+ "c = numpy.zeros((10, 10))\n",
+ "\n",
+ "print \"Input row & column of A matrix: \"\n",
+ "n = int(raw_input(\"row: \"))\n",
+ "m = int(raw_input(\"column: \"))\n",
+ "\n",
+ "print \"Input row & column of b matrix: \"\n",
+ "k = int(raw_input(\"row: \"))\n",
+ "q = int(raw_input(\"column: \"))\n",
+ "\n",
+ "if n == k:\n",
+ " print \"Matrices can be multiplied\"\n",
+ " print \"Resultant Matrix is %d x %d\" %(m, q)\n",
+ " print \"Input A matrix\"\n",
+ " read_mat(a, m, n)\n",
+ " print \"Input B matrix\"\n",
+ " read_mat(b, k, q)\n",
+ " for i in range(m):\n",
+ " for j in range(q):\n",
+ " c[i][j] = 0\n",
+ " for ip in range(n):\n",
+ " c[i][j] = c[i][j]+a[i][ip]*b[ip][j]\n",
+ " print \"Resultant of A and B matrices: \"\n",
+ " write_mat(c, m, q)\n",
+ "else:\n",
+ " print \"col of matrix A must be equal to row of matrix B\"\n",
+ " print \"Matrices cannot be multiplied\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input row & column of A matrix: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "row: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "column: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input row & column of b matrix: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "row: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "column: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrices can be multiplied\n",
+ "Resultant Matrix is 3 x 3\n",
+ "Input A matrix\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": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input B matrix\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": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resultant of A and B matrices: \n",
+ "30 36 42 \n",
+ "66 81 96 \n",
+ "102 126 150 \n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7, page no. 235"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy\n",
+ "\n",
+ "a = numpy.zeros((10, 10))\n",
+ "\n",
+ "print \"Input row & column of A matrix: \"\n",
+ "n = int(raw_input(\"row: \"))\n",
+ "m = int(raw_input(\"column: \"))\n",
+ "\n",
+ "print \"Input A matrix: \"\n",
+ "for i in range(n):\n",
+ " for j in range(m):\n",
+ " a[i][j] = int(raw_input())\n",
+ "print \"Transpose of matrix A is\"\n",
+ "for i in range(m):\n",
+ " for j in range(n):\n",
+ " print \"%5d\" %a[j][i],\n",
+ " print \"\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input row & column of A matrix: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "row: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "column: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input A matrix: \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": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Transpose of matrix A is\n",
+ " 1 5 9 \n",
+ " 2 6 6 \n",
+ " 3 7 7 \n",
+ " 4 8 8 \n"
+ ]
+ }
+ ],
+ "prompt_number": 55
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8, page no. 237"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "strc = \"This is a string literal\"\n",
+ "print strc"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This is a string literal\n"
+ ]
+ }
+ ],
+ "prompt_number": 57
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example starray.c, page no. 238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "names = [\"Tejaswi\",\n",
+ " \"Prasad\",\n",
+ " \"Prasanth\",\n",
+ " \"Prakash\",\n",
+ " \"Anand\",]\n",
+ "for name in names:\n",
+ " print name"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tejaswi\n",
+ "Prasad\n",
+ "Prasanth\n",
+ "Prakash\n",
+ "Anand\n"
+ ]
+ }
+ ],
+ "prompt_number": 59
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example strcat.c, page no. 239"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "oneString = \"Fish\"\n",
+ "twoString = \"face\"\n",
+ "oneString += twoString\n",
+ "print oneString"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Fishface\n"
+ ]
+ }
+ ],
+ "prompt_number": 63
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9, page no. 241"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a = []\n",
+ "print \"Size of vector ?\"\n",
+ "n = int(raw_input())\n",
+ "num = n\n",
+ "print \"Vector Elements ?\"\n",
+ "for i in range(n):\n",
+ " a.append(float(raw_input()))\n",
+ "a = set(a)\n",
+ "a = list(a)\n",
+ "length = len(a)\n",
+ "print length\n",
+ "if length == n:\n",
+ " print \"No duplicates found\"\n",
+ "else:\n",
+ " print \"Vector has %d duplicates\" %(num - length)\n",
+ " print \"Vector after deleting duplicates: \",\n",
+ " for ele in a:\n",
+ " print ele,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size of vector ?\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vector Elements ?\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": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n",
+ "Vector has 2 duplicates\n",
+ "Vector after deleting duplicates: 1.0 2.0 3.0 4.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 73
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10, page no. 242"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy\n",
+ "\n",
+ "grade = ['', '', '', '', '', '', '', '', '', '', '', '', '', '']\n",
+ "a = numpy.zeros((50,10))\n",
+ "print \"Number of students ?\",\n",
+ "n = int(raw_input())\n",
+ "for i in range(n):\n",
+ " sum = 0.0\n",
+ " print \"Enter 3 socres of student %d\" %(i+1)\n",
+ " for j in range(3):\n",
+ " a[i][j] = (float(raw_input()))\n",
+ " sum += a[i][j]\n",
+ " avg = sum/3\n",
+ " a[i][3] = avg\n",
+ " if avg < 30.0:\n",
+ " grade[i] = 'E'\n",
+ " elif avg < 60.0:\n",
+ " grade[i] = 'D'\n",
+ " elif avg < 75.0:\n",
+ " grade[i] = 'B'\n",
+ " else:\n",
+ " grade[i] = 'A'\n",
+ "print \"S1.no scores AVERAGE GRADE\"\n",
+ "print \"---------------------------------------------\"\n",
+ "for i in range(n):\n",
+ " print i+1,\n",
+ " for j in range(4):\n",
+ " print \"%8.2f\" %a[i][j],\n",
+ " print \"%6c\" %grade[i],\n",
+ " print \"\"\n",
+ " print \"---------------------------------------------\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of students ?"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 3 socres of student 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "67\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "86\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "58\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 3 socres of student 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "30\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23.9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 3 socres of student 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "80\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "97\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "73\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 3 socres of student 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "56.8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "47.9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "62.0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 3 socres of student 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "45\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "35\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "40\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "S1.no scores AVERAGE GRADE\n",
+ "---------------------------------------------\n",
+ "1 67.00 86.00 58.00 70.33 B \n",
+ "---------------------------------------------\n",
+ "2 20.00 30.00 23.90 24.63 E \n",
+ "---------------------------------------------\n",
+ "3 80.00 97.00 73.00 83.33 A \n",
+ "---------------------------------------------\n",
+ "4 56.80 47.90 62.00 55.57 D \n",
+ "---------------------------------------------\n",
+ "5 45.00 35.00 40.00 40.00 D \n",
+ "---------------------------------------------\n"
+ ]
+ }
+ ],
+ "prompt_number": 85
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.11, page no. 243"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "sumsq = 0\n",
+ "sum = 0\n",
+ "print \"Calculation standard deviation of a\"\n",
+ "print \"Enter size of the list: \",\n",
+ "n = int(raw_input())\n",
+ "x = []\n",
+ "print \"Enter the %d items \" %n\n",
+ "for i in range(n):\n",
+ " x.append(float(raw_input()))\n",
+ " sum += x[i]\n",
+ "mean = sum/n\n",
+ "for i in range(n):\n",
+ " sumsq = sumsq + (mean-x[i]) * (mean-x[i])\n",
+ "variance = sumsq/n\n",
+ "sdn = math.sqrt(variance)\n",
+ "print \"Mean of %5d items : %10.6f\" %(n, mean)\n",
+ "print \"Variance : %10.6f\" %(variance)\n",
+ "print \"Standard Deviation : %10.6f\" %sdn"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Calculation standard deviation of a\n",
+ "Enter size of the list: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the 7 items \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "32\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "90\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "34\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "52\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "24\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mean of 7 items : 35.714286\n",
+ "Variance : 685.918367\n",
+ "Standard Deviation : 26.190043\n"
+ ]
+ }
+ ],
+ "prompt_number": 89
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.12, page no. 244"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy\n",
+ "import math\n",
+ "\n",
+ "def nrm(a, n, m):\n",
+ " sum = 0.0\n",
+ " for i in range(n):\n",
+ " for j in range(m):\n",
+ " sum = sum + a[i][j] * a[i][j]\n",
+ " print \"Sum = %6.2f\" %sum\n",
+ " return math.sqrt(sum)\n",
+ "\n",
+ "a = numpy.zeros((10, 10))\n",
+ "print \"Input row & column of A matrix\"\n",
+ "n = int(raw_input(\"row: \"))\n",
+ "m = int(raw_input(\"column: \"))\n",
+ "print \"Input A matrix\"\n",
+ "for i in range(n):\n",
+ " for j in range(m):\n",
+ " a[i][j] = float(raw_input())\n",
+ "norm = nrm(a, n, m)\n",
+ "print \"Norm = %6.2f\" %norm"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input row & column of A matrix\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "row: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "column: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input A matrix\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": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sum = 285.00\n",
+ "Norm = 16.88\n"
+ ]
+ }
+ ],
+ "prompt_number": 90
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.13, page no. 245"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy\n",
+ "\n",
+ "a = numpy.zeros((5, 5))\n",
+ "flag = True\n",
+ "print \"Input size of matrix\"\n",
+ "n = int(raw_input(\"row: \"))\n",
+ "m = int(raw_input(\"column: \"))\n",
+ "print \"Enter the elements of the matrix: \"\n",
+ "for i in range(m):\n",
+ " for j in range(n):\n",
+ " a[i][j] = float(raw_input())\n",
+ "for i in range(m):\n",
+ " min = a[i][0]\n",
+ " p = i\n",
+ " q = 0\n",
+ " for j in range(n):\n",
+ " if min > a[i][j]:\n",
+ " min = a[i][j]\n",
+ " p = i\n",
+ " q = j\n",
+ " for j in range(m):\n",
+ " if j != q:\n",
+ " if a[j][q] > a[p][q]:\n",
+ " flag = False\n",
+ " if flag:\n",
+ " print \"Saddle point a[%d][%d] = %d\" %(p+1, q+1, a[p][q])\n",
+ " else:\n",
+ " print \"No saddle is in row %d\" %(i+1)\n",
+ " flag = True"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input size of matrix\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "row: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "column: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the elements of the matrix: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\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": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Saddle point a[1][2] = 5\n",
+ "Saddle point a[2][2] = 5\n",
+ "No saddle is in row 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 91
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.14, page no. 246"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy\n",
+ "\n",
+ "a = numpy.zeros((10, 10))\n",
+ "b = numpy.zeros((10, 10))\n",
+ "flag = None\n",
+ "print \"Input order of A matrix\"\n",
+ "n = int(raw_input(\"row: \"))\n",
+ "print \"Input A matrix\"\n",
+ "for i in range(n):\n",
+ " for j in range(n):\n",
+ " a[i][j] = int(raw_input())\n",
+ "for i in range(n):\n",
+ " for j in range(n):\n",
+ " b[i][j] = a[j][i]\n",
+ "print \"Transpose of A matrix\"\n",
+ "for i in range(n):\n",
+ " for j in range(n):\n",
+ " print \"%5d\" %b[i][j],\n",
+ " print \"\"\n",
+ "for i in range(n):\n",
+ " for j in range(n):\n",
+ " if a[i][j] != b[i][j]:\n",
+ " flag = True\n",
+ "if flag:\n",
+ " print \"Matrix is not symmetric\"\n",
+ "else:\n",
+ " print \"Matrix is symmetric\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input order of A matrix\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "row: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input A matrix\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": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Transpose of A matrix\n",
+ " 1 3 \n",
+ " 2 4 \n",
+ "Matrix is not symmetric\n"
+ ]
+ }
+ ],
+ "prompt_number": 96
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/chapter8.ipynb b/Mastering_C/chapter8.ipynb
new file mode 100644
index 00000000..b93801ac
--- /dev/null
+++ b/Mastering_C/chapter8.ipynb
@@ -0,0 +1,2252 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:a09d4bcf6c9368fe8d58466e4e36512ef92468a06ab7b1aa67d8417eff2354ac"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: Pointers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example getaddr.c, page no. 261"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 4,
+ "metadata": {},
+ "source": [
+ "Note: There is no concept of pointers in Python. Hence, output may not match for some of the examples."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a = 100\n",
+ "b = 200\n",
+ "c = 300\n",
+ "\n",
+ "print \"Address: %x contains value: %i\" %(a, a)\n",
+ "print \"Address: %x contains value: %i\" %(b, b)\n",
+ "print \"Address: %x contains value: %i\" %(c, c)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address: 64 contains value: 100\n",
+ "Address: c8 contains value: 200\n",
+ "Address: 12c contains value: 300\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.1, page no. 263"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i = 7\n",
+ "f = 10.5\n",
+ "c = 'A'\n",
+ "print \"%d is stored at address %u\" %(i, id(i))\n",
+ "print \"%f is stored at address %u\" %(f, id(f))\n",
+ "print \"%c is stored at address %u\" %(c, id(c))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7 is stored at address 41297768\n",
+ "10.500000 is stored at address 53588120\n",
+ "A is stored at address 140471220157656\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2, page no. 263"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "var1 = 10\n",
+ "var2 = 20\n",
+ "iptr = id(var1)\n",
+ "print \"Address and contents of var1 is: %d & %d\" %(iptr, var1)\n",
+ "iptr = id(var2)\n",
+ "print \"Address and contents of var1 is: %d & %d\" %(iptr, var2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address and contents of var1 is: 41297696 & 10\n",
+ "Address and contents of var1 is: 41297456 & 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example derefer.c, page no. 265"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#note: we have used var1 instead of iptr because there is no point of pointer in python. Hence, instead of *iptr \n",
+ "#we have to refer to the same variable\n",
+ "var1 = 0\n",
+ "iptr = id(var1)\n",
+ "var1 = 25\n",
+ "var1 += 10\n",
+ "print \"Variable var1 contains %i \" %var1\n",
+ "var2 = var1\n",
+ "print \"Variable var2 contains: %i\" %var2\n",
+ "iptr = id(var2)\n",
+ "var2 += 20\n",
+ "print \"Variable var2 now contains: %i\" %var2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Variable var1 contains 35 \n",
+ "Variable var2 contains: 35\n",
+ "Variable var2 now contains: 55\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3, page no. 267"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a = 5\n",
+ "b = 10\n",
+ "ptr = id(a)\n",
+ "print \"Initial values of a & b\"\n",
+ "print \"a = %d\" %a\n",
+ "print \"b = %d\" %b\n",
+ "b = a\n",
+ "print \"Changed values of a & b\"\n",
+ "print \"a = %d\" %a\n",
+ "print \"b = %d\" %b\n",
+ "print \"Address of variable is \", id(a)\n",
+ "print \"Address of variable is \", id(b)\n",
+ "print \"Address assigned to pointer ptr is \", id(ptr)\n",
+ "print \"Value pointer ptr access is \", a"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Initial values of a & b\n",
+ "a = 5\n",
+ "b = 10\n",
+ "Changed values of a & b\n",
+ "a = 5\n",
+ "b = 5\n",
+ "Address of variable is 41297816\n",
+ "Address of variable is 41297816\n",
+ "Address assigned to pointer ptr is 51460736\n",
+ "Value pointer ptr access is 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4, page no. 268"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(d1, d2):\n",
+ " return d2, d1\n",
+ "\n",
+ "print \"Enter 2 real numbers:\"\n",
+ "data1 = float(raw_input(\"num1: \"))\n",
+ "data2 = float(raw_input(\"num2: \"))\n",
+ "\n",
+ "print \"Data1 contains: \", data1\n",
+ "print \"Data2 contains: \", data2\n",
+ "data1, data2 = swap(data1, data2)\n",
+ "print \"After swapping.....\"\n",
+ "print \"Data1 contains: \", data1\n",
+ "print \"Data2 contains: \", data2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 2 real numbers:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "num1: 23.55\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "num2: -65.73\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Data1 contains: 23.55\n",
+ "Data2 contains: -65.73\n",
+ "After swapping.....\n",
+ "Data1 contains: -65.73\n",
+ "Data2 contains: 23.55\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example voidptr.c, page no. 270"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i1 = 100\n",
+ "f1 = 200.5\n",
+ "vptr = id(i1)\n",
+ "print \"i1 contains \", i1\n",
+ "vptr = id(f1)\n",
+ "print \"f1 contians \", f1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i1 contains 100\n",
+ "f1 contians 200.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.5, page no. 271"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#the way it is given in the textbook is not possible as there is no concept of pointers in Python\n",
+ "a = []\n",
+ "print \"Size of array ?\"\n",
+ "n = int(raw_input())\n",
+ "print \"Array elements ?\"\n",
+ "for i in range(n):\n",
+ " a.append(int(raw_input()))\n",
+ "small = min(a)\n",
+ "print \"The smallest element is \", small"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size of array ?\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Array elements ?\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-77\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The smallest element is -77\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.6, page no. 272"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a = 5\n",
+ "b = 10\n",
+ "ptr1 = id(a)\n",
+ "ptr2 = id(b)\n",
+ "\n",
+ "c = a + b\n",
+ "d = a/b*7\n",
+ "\n",
+ "print \"Addresses of variables 'a' and 'b': \"\n",
+ "print \"a: \", ptr1\n",
+ "print \"b: \", ptr2\n",
+ "\n",
+ "print \"Addresses of pointers 'ptr1' and 'ptr2' hold: \"\n",
+ "print \"ptr1: \", ptr1\n",
+ "print \"ptr2: \", ptr2\n",
+ "\n",
+ "print \"values of 'a', 'b', 'c', 'd': \"\n",
+ "print \"a = %2d b = %2d c = %2d d = %2d\" %(a,b,c,d)\n",
+ "print \"Values accessed by pointers 'ptr1' and 'ptr2': \"\n",
+ "print \"ptr1: \", ptr1\n",
+ "print \"ptr2: \", ptr2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Addresses of variables 'a' and 'b': \n",
+ "a: 37181336\n",
+ "b: 37181216\n",
+ "Addresses of pointers 'ptr1' and 'ptr2' hold: \n",
+ "ptr1: 37181336\n",
+ "ptr2: 37181216\n",
+ "values of 'a', 'b', 'c', 'd': \n",
+ "a = 5 b = 10 c = 15 d = 0\n",
+ "Values accessed by pointers 'ptr1' and 'ptr2': \n",
+ "ptr1: 37181336\n",
+ "ptr2: 37181216\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example farptr.c, page no. 275"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# not possible in Python"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example ptriptr.c, page no. 275"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "data = 0\n",
+ "iptr = id(data)\n",
+ "ptriptr = id(iptr)\n",
+ "data = 100\n",
+ "print \"Variable 'data' contains: \", data\n",
+ "ptriptr = 200\n",
+ "print \"Variable 'data' contains: \", data\n",
+ "#value of data won't change as there is no pointer\n",
+ "data = 300\n",
+ "print \"ptriptr is pointing to: \", data"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Variable 'data' contains: 100\n",
+ "Variable 'data' contains: 100\n",
+ "ptriptr is pointing to: 300\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "iarray = [1, 2, 3, 4, 5]\n",
+ "for i in range(5):\n",
+ " print id(iarray[i]), iarray[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "37181432 1\n",
+ "37181408 2\n",
+ "37181384 3\n",
+ "37181360 4\n",
+ "37181336 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def sort_it(b):\n",
+ " return sorted(b)\n",
+ "\n",
+ "a = []\n",
+ "print \"Eneter the number of elements in the array (lessthan 21): \"\n",
+ "n = int(raw_input())\n",
+ "print \"Enter the elements: \"\n",
+ "for i in range(n):\n",
+ " a.append(int(raw_input()))\n",
+ "arr = sort_it(a)\n",
+ "print \"The sorted array: \"\n",
+ "for ele in arr:\n",
+ " print ele,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Eneter the number of elements in the array (lessthan 21): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the elements: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The sorted array: \n",
+ "-4 0 1 4 7\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.7, page no. 280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def SortByPtrExchange(person):\n",
+ " return sorted(person)\n",
+ "choice = 'y'\n",
+ "person = []\n",
+ "while choice == 'y':\n",
+ " print \"Enter Name: \"\n",
+ " person.append(raw_input())\n",
+ " print \"Enter another ? (y/n)\"\n",
+ " choice = raw_input()\n",
+ "print \"Unsorted list: \"\n",
+ "for per in person:\n",
+ " print per\n",
+ "person = SortByPtrExchange(person)\n",
+ "print \"Sorted List: \"\n",
+ "for per in person:\n",
+ " print per"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tejaswi\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another ? (y/n)\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Prasad\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another ? (y/n)\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Prakash\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another ? (y/n)\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sudeep\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another ? (y/n)\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Anand\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another ? (y/n)\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Unsorted list: \n",
+ "Tejaswi\n",
+ "Prasad\n",
+ "Prakash\n",
+ "Sudeep\n",
+ "Anand\n",
+ "Sorted List: \n",
+ "Anand\n",
+ "Prakash\n",
+ "Prasad\n",
+ "Sudeep\n",
+ "Tejaswi\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example argref.c, page no. 282"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Add10(studentmarks):\n",
+ " studentmarks += 10\n",
+ " return studentmarks\n",
+ "Marks = 25\n",
+ "print \"Value of Marks = %d\" %Marks\n",
+ "Marks = Add10(Marks)\n",
+ "print \"Value of Marks after execution = %d\" %Marks"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of Marks = 25\n",
+ "Value of Marks after execution = 35\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example accfunc.c, page no. 283"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Max = 5\n",
+ "def Add10(studentmarks):\n",
+ " global Max\n",
+ " for i in range(Max):\n",
+ " studentmarks[i] += 10\n",
+ " return studentmarks\n",
+ "Marks = [25, 43, 70, 80, 76]\n",
+ "Marks = Add10(Marks)\n",
+ "for j in range(Max):\n",
+ " print \"Marks[%d] = %d\" %(j, Marks[j])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Marks[0] = 35\n",
+ "Marks[1] = 53\n",
+ "Marks[2] = 80\n",
+ "Marks[3] = 90\n",
+ "Marks[4] = 86\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.8, page no. 285"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def exchange(x, y):\n",
+ " return y, x\n",
+ "print \"Program swaps values of the variables 'a' and 'b'\"\n",
+ "print \"Values of a & b: \"\n",
+ "a = int(raw_input(\"a: \"))\n",
+ "b = int(raw_input(\"b: \"))\n",
+ "print \"a: %5d \\t b = %5d\" %(a, b)\n",
+ "x, y = exchange(a, b)\n",
+ "print \"After swapping: \"\n",
+ "print \"a = %5d \\t b = %5d\" %(x, y)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Program swaps values of the variables 'a' and 'b'\n",
+ "Values of a & b: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a: 78\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "b: 196\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a: 78 \t b = 196\n",
+ "After swapping: \n",
+ "a = 196 \t b = 78\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 287"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#not possible in Python. Hence, skipping"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 288"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = [1, 2, 3]\n",
+ "ptr = id(arr)\n",
+ "for i in range(3):\n",
+ " print \"%d %d\" %(id(i), arr[i])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "37181456 1\n",
+ "37181432 2\n",
+ "37181408 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.9, page no. 289"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = [1, 2, 3, 4, 5]\n",
+ "for ele in arr[::-1]:\n",
+ " print ele,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5 4 3 2 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.10, page no. 289"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = [-1, -2, -3, -4, -5]\n",
+ "p = arr\n",
+ "arr = arr[::-1]\n",
+ "p = p[::-1]\n",
+ "for i in range(len(arr)):\n",
+ " print arr[i], \"\\t\", p[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-5 \t-5\n",
+ "-4 \t-4\n",
+ "-3 \t-3\n",
+ "-2 \t-2\n",
+ "-1 \t-1\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 290"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ia = [2, 5, 9]\n",
+ "ptr = ia\n",
+ "for ele in ptr:\n",
+ " print ele,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2 5 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.11, page no. 291"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def FindBig(x, y):\n",
+ " return x if x > y else y\n",
+ "print \"Enter two integers: \"\n",
+ "a = int(raw_input(\"int1: \"))\n",
+ "b = int(raw_input(\"int2: \"))\n",
+ "big = FindBig(a, b)\n",
+ "print \"Variable name \\t address of the variable \\t value\"\n",
+ "print \"a \\t\\t %d \\t\\t\\t %d\"%(id(a), a)\n",
+ "print \"The bigger of the two integers\"\n",
+ "print \"big \\t\\t %d \\t\\t\\t %d\" %(id(big), big)\n",
+ "print \"The value as botained form pointer: \", big"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two integers: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "int1: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "int2: 7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Variable name \t address of the variable \t value\n",
+ "a \t\t 37181336 \t\t\t 5\n",
+ "The bigger of the two integers\n",
+ "big \t\t 37181288 \t\t\t 7\n",
+ "The value as botained form pointer: 7\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example string1.c, page no. 292"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "city = \"Bangalore\"\n",
+ "i = 0\n",
+ "print \"Address \\t\\t\\t\\t Contents\"\n",
+ "for i in range(len(city)):\n",
+ " print id(city[i]), \"\\t\\t\\t \", city[i], city[i], city[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address \t\t\t\t Contents\n",
+ "140069470495088 \t\t\t B B B\n",
+ "140069470360920 \t\t\t a a a\n",
+ "140069470570416 \t\t\t n n n\n",
+ "140069470363320 \t\t\t g g g\n",
+ "140069470360920 \t\t\t a a a\n",
+ "140069470363160 \t\t\t l l l\n",
+ "140069470363280 \t\t\t o o o\n",
+ "140069470569656 \t\t\t r r r\n",
+ "140069470571696 \t\t\t e e e\n"
+ ]
+ }
+ ],
+ "prompt_number": 53
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 293"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "chArr = \"Pointer and Strings\"\n",
+ "chPtr = chArr\n",
+ "print \"Contents pointed by the pointer chPtr is: \", chPtr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Contents pointed by the pointer chPtr is: Pointer and Strings\n"
+ ]
+ }
+ ],
+ "prompt_number": 55
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 293"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def usrstrlen(ptr):\n",
+ " ln = 0\n",
+ " for ele in ptr:\n",
+ " ln += 1\n",
+ " return ln\n",
+ "s1 = \"Good\"\n",
+ "print \"Length of string using standard library function\", \n",
+ "print len(s1)\n",
+ "length = usrstrlen(s1)\n",
+ "print \"Length of string using user defined function \", length"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Length of string using standard library function 4\n",
+ "Length of string using user defined function 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 62
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.12, page no. 294"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Enger the string to find it's length\"\n",
+ "string = raw_input()\n",
+ "print \"String is: \", string\n",
+ "print \"It's length is : \", len(string)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enger the string to find it's length\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Visvesvaraya College\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "String is: Visvesvaraya College\n",
+ "It's length is : 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 63
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 294"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def usrstrcpy(s):\n",
+ " s2 = []\n",
+ " for ele in s:\n",
+ " s2.append(ele)\n",
+ " s2 = ''.join(s2)\n",
+ " return s2\n",
+ "s1 = \"Good\"\n",
+ "s2 = s1\n",
+ "print \"Copied string using normal assignment is \", s2\n",
+ "s2 = usrstrcpy(s1)\n",
+ "print \"Copied string using user defined function is \", s2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Copied string using normal assignment is Good\n",
+ "Copied string using user defined function is Good\n"
+ ]
+ }
+ ],
+ "prompt_number": 66
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 295"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def usrstrcat(s2, s1):\n",
+ " return s1 + s2\n",
+ "\n",
+ "s1 = \"Good\"\n",
+ "s2 = \" Morning\"\n",
+ "s3 = s1+s2\n",
+ "print \"Concatenation using normal Python addition\",\n",
+ "print s3\n",
+ "s1 = usrstrcat(s2, s1)\n",
+ "print \"concatenation using user defined function is \", s1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Concatenation using normal Python addition Good Morning\n",
+ "concatenation using user defined function is Good Morning\n"
+ ]
+ }
+ ],
+ "prompt_number": 70
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 296"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#only user defined way is possible in Python. Normal way would return either True or False only\n",
+ "s1 = \"Good\"\n",
+ "s2 = \" Morning\"\n",
+ "if s1 < s2:\n",
+ " r = -1\n",
+ "elif s1 > s2:\n",
+ " r = 1\n",
+ "else:\n",
+ " r = 0\n",
+ "print \"Comparison of strings using user defined way is \", r"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Comparison of strings using normal python way is 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 72
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 297"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "pet = [\"lion\", \"cat\"]\n",
+ "for i in range(len(pet)):\n",
+ " print id(pet[i]), pet[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "52705200 lion\n",
+ "140069470362560 cat\n"
+ ]
+ }
+ ],
+ "prompt_number": 76
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.13, page no. 298"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "st = \"hello\"\n",
+ "for i in range(len(st)):\n",
+ " print st[i], \"\\t\", st[i], \"\\t\", st[i], \"\\t\", st[i] "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "h \th \th \th\n",
+ "e \te \te \te\n",
+ "l \tl \tl \tl\n",
+ "l \tl \tl \tl\n",
+ "o \to \to \to\n"
+ ]
+ }
+ ],
+ "prompt_number": 78
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.14, page no. 299"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "st = \"Good Morning\"\n",
+ "print st[3:]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d Morning\n"
+ ]
+ }
+ ],
+ "prompt_number": 80
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.15, page no. 299"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#not possible in Python. Skipping"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 81
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example strchr.c, page no. 300"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "string = raw_input(\"Enter a string: \")\n",
+ "c = raw_input(\"Enter character to be searched: \")\n",
+ "try:\n",
+ " i = list(string).index(c)\n",
+ " print \"%c was found in position %d\" %(c, i)\n",
+ "except:\n",
+ " pass"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string: House\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter character to be searched: s\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s was found in position 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 86
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example strcspn.c, page no. 302"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "string1 = \"0123456789\"\n",
+ "string2 = \"A47DCF8\"\n",
+ "c = 0\n",
+ "for ele in string2:\n",
+ " if ele in string1:\n",
+ " index = string1.index(ele)\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example strcspn.c, page no.303"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "string1 = \"0123456789\"\n",
+ "string2 = \"A32DC014\"\n",
+ "c = 0\n",
+ "for ele in string1:\n",
+ " for ele1 in string2:\n",
+ " if ele == ele1:\n",
+ " c += 1\n",
+ "print c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example strpbrk.c, page no. 303"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "print \"Input two Strings: \"\n",
+ "str1 = raw_input(\"Str1: \")\n",
+ "str2 = raw_input(\"Str2: \")\n",
+ "\n",
+ "for ele in str1:\n",
+ " if ele in str2:\n",
+ " print \"Character found: \", ele\n",
+ " sys.exit()\n",
+ "print \"Character not found\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input two Strings: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Str1: House\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Str2: Sorrow\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Character found: o\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example strstr.c, page no. 304"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "print \"Input two Strings: \"\n",
+ "str1 = raw_input(\"Str1: \")\n",
+ "str2 = raw_input(\"Str2: \")\n",
+ "\n",
+ "if str2 in str1:\n",
+ " str1.index(str2)\n",
+ " print \"String 2 is found at position 6 in string1\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input two Strings: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Str1: I saw the cat click the mouse.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Str2: the\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "String 2 is found at position 6 in string1\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example strtok.c, page no. 305"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "my_str = raw_input(\"Input a string, parts separated by , or ;\")\n",
+ "print \"The tokens found were: \"\n",
+ "token = ''\n",
+ "for i in range(len(my_str)):\n",
+ " if my_str[i] == ',' or my_str[i] == ';':\n",
+ " if len(token) > 0:\n",
+ " print token\n",
+ " token = ''\n",
+ " else:\n",
+ " token = token + my_str[i]\n",
+ "print token"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input a string, parts separated by , or ;;abc,defgh;;hi,jklmn;op\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The tokens found were: \n",
+ "abc\n",
+ "defgh\n",
+ "hi\n",
+ "jklmn\n",
+ "op\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.16, pag eno. 307"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def func1(i, f):\n",
+ " print i, f\n",
+ "def func2(s):\n",
+ " print s\n",
+ " \n",
+ "i = 5\n",
+ "f = 5.375\n",
+ "s = \"string\"\n",
+ "func1(i, f)\n",
+ "func2(s)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5 5.375\n",
+ "string\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def fact(m):\n",
+ " if m == 1:\n",
+ " return 1\n",
+ " else:\n",
+ " return m*fact(m-1)\n",
+ "print \"Enter the integer whose factorial is to be found: \",\n",
+ "n = int(raw_input())\n",
+ "ans = fact(n)\n",
+ "print \"Factorial of \", n, \" is \", ans"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the integer whose factorial is to be found: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Factorial of 8 is 40320\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def large(b):\n",
+ " return max(b)\n",
+ "def small(b):\n",
+ " return min(b)\n",
+ "print \"Enter the number of integers: \",\n",
+ "n = int(raw_input())\n",
+ "print \"Enter the set of integers: \"\n",
+ "a = []\n",
+ "for i in range(n):\n",
+ " a.append(int(raw_input()))\n",
+ "print \"The largest integer is: \", large(a)\n",
+ "print \"The smallest integer is: \", small(a)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number of integers: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the set of integers: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The largest integer is: 5\n",
+ "The smallest integer is: -7\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.17, page no. 311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 20\n",
+ "def print_array(a):\n",
+ " print \"The elements of the array are: \"\n",
+ " for ele in a:\n",
+ " print ele,\n",
+ "print \"Enter the number of elements: \"\n",
+ "n = int(raw_input())\n",
+ "print \"Enter the elements: \"\n",
+ "a = []\n",
+ "for i in range(n):\n",
+ " a.append(int(raw_input()))\n",
+ "if n < 0 or n > MAX:\n",
+ " print \"Invalid number of elements...\"\n",
+ "else:\n",
+ " print_array(a)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number of elements: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the elements: \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": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The elements of the array are: \n",
+ "1 2 3 4 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.18, page no. 313"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def upper(instr):\n",
+ " return instr.upper()\n",
+ "def lower(instr):\n",
+ " return instr.lower()\n",
+ "instr = raw_input(\"Input a string: \")\n",
+ "print \"To upper or lower (u/l): \"\n",
+ "inchar = raw_input()\n",
+ "if inchar == 'l':\n",
+ " print \"The converted string is \\n\", lower(instr)\n",
+ "elif inchar == 'u':\n",
+ " print \"The conveerted string is \\n\", upper(instr)\n",
+ "else:\n",
+ " print \"Ivalid input...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input a string: UVCE, Bangalore\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "To upper or lower (u/l): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "l\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The converted string is \n",
+ "uvce, bangalore\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/chapter9.ipynb b/Mastering_C/chapter9.ipynb
new file mode 100644
index 00000000..9eacd97f
--- /dev/null
+++ b/Mastering_C/chapter9.ipynb
@@ -0,0 +1,1463 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:2b328a00a423d96b629425895ccbcc90fde898bdf09e6f58382db5eb59593f31"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9: Structures & Unions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.1, page no. 338"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class date:\n",
+ " dat = 0\n",
+ " month = 0\n",
+ " year = 0\n",
+ "class person:\n",
+ " name = ''\n",
+ " lastnam = ''\n",
+ " birthday = date()\n",
+ " salary = 0.0\n",
+ "emprec = person()\n",
+ "birth = emprec.birthday\n",
+ "emprec.name = \"Tejaswi.V.\"\n",
+ "emprec.lastnam = \"Rajuk\"\n",
+ "emprec.birthday.day = 24\n",
+ "emprec.birthday.month = 7\n",
+ "emprec.birthday.year = 90\n",
+ "x = 6500.00\n",
+ "emprec.salary = x\n",
+ "print \"Employee Details: \"\n",
+ "print \"Name: \", emprec.name, \" \", emprec.lastnam\n",
+ "print \"Birthdate: \", emprec.birthday.day, \":\", emprec.birthday.month, \":\", emprec.birthday.year\n",
+ "print \"Salary: \", emprec.salary"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Details: \n",
+ "Name: Tejaswi.V. Rajuk\n",
+ "Birthdate: 24 : 7 : 90\n",
+ "Salary: 6500.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.2, page no. 340"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "CURRENT_YEAR = 96\n",
+ "def increment(sal, year, inc):\n",
+ " if CURRENT_YEAR - year > 30:\n",
+ " sal += inc\n",
+ " return sal\n",
+ "class date:\n",
+ " day = 0\n",
+ " month = 0\n",
+ " year = 0\n",
+ "class person:\n",
+ " name = ''\n",
+ " birthday = date()\n",
+ " salary = 0.0\n",
+ "n = 500\n",
+ "emprec = person()\n",
+ "emprec.name = 'Arun R.'\n",
+ "emprec.birthday.day = 10\n",
+ "emprec.birthday.month = 8\n",
+ "emprec.birthday.year = 64\n",
+ "emprec.salary = 4000.00\n",
+ "print \"Employee Details: \"\n",
+ "print \"Name: \", emprec.name\n",
+ "print \"Birthdate: \", emprec.birthday.day, \":\", emprec.birthday.month, \":\", emprec.birthday.year\n",
+ "print \"Salary: \", emprec.salary\n",
+ "emprec.salary = increment(emprec.salary, emprec.birthday.year, n)\n",
+ "print \"Employee Details: \"\n",
+ "print \"Name: \", emprec.name\n",
+ "print \"Birthdate: \", emprec.birthday.day, \":\", emprec.birthday.month, \":\", emprec.birthday.year\n",
+ "print \"Salary: \", emprec.salary"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Details: \n",
+ "Name: Arun R.\n",
+ "Birthdate: 10 : 8 : 64\n",
+ "Salary: 4000.0\n",
+ "Employee Details: \n",
+ "Name: Arun R.\n",
+ "Birthdate: 10 : 8 : 64\n",
+ "Salary: 4500.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.3, page no. 342"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "CURRENT_YEAR = 96\n",
+ "def increment(emprec):\n",
+ " if CURRENT_YEAR - emprec.birthday.year > 30:\n",
+ " emprec.salary += 500\n",
+ " return emprec\n",
+ "class date:\n",
+ " day = 0\n",
+ " month = 0\n",
+ " year = 0\n",
+ "class person:\n",
+ " name = ''\n",
+ " birthday = date()\n",
+ " salary = 0.0\n",
+ "emprec = person()\n",
+ "emprec.name = 'Arun R.'\n",
+ "emprec.birthday.day = 10\n",
+ "emprec.birthday.month = 8\n",
+ "emprec.birthday.year = 64\n",
+ "emprec.salary = 4000.00\n",
+ "print \"Employee Details: \"\n",
+ "print \"Name: \", emprec.name\n",
+ "print \"Birthdate: \", emprec.birthday.day, \":\", emprec.birthday.month, \":\", emprec.birthday.year\n",
+ "print \"Salary: \", emprec.salary\n",
+ "emprec = increment(emprec)\n",
+ "print \"Employee Details: \"\n",
+ "print \"Name: \", emprec.name\n",
+ "print \"Birthdate: \", emprec.birthday.day, \":\", emprec.birthday.month, \":\", emprec.birthday.year\n",
+ "print \"Salary: \", emprec.salary"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Details: \n",
+ "Name: Arun R.\n",
+ "Birthdate: 10 : 8 : 64\n",
+ "Salary: 4000.0\n",
+ "Employee Details: \n",
+ "Name: Arun R.\n",
+ "Birthdate: 10 : 8 : 64\n",
+ "Salary: 4500.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4, page no. 343"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class date:\n",
+ " day = 0\n",
+ " month = 0\n",
+ " year = 0\n",
+ "\n",
+ "class person:\n",
+ " name = ''\n",
+ " birthday = date()\n",
+ " salary = 0.0\n",
+ "\n",
+ "def printout(per):\n",
+ " print \"Employee Details: \"\n",
+ " print \"Name: \", per.name\n",
+ " print \"Birthdate: %3d:%3d:%3d\" %(per.birthday.day, per.birthday.month, per.birthday.year)\n",
+ " print \"Salary: %6.2f\" %(per.salary)\n",
+ "\n",
+ "def readin(record):\n",
+ " record.name = raw_input(\"Enter the name: \")\n",
+ " print \"Enter Birthdate\"\n",
+ " record.birthday.day = int(raw_input(\"Day: \"))\n",
+ " record.birthday.month = int(raw_input(\"Month: \"))\n",
+ " record.birthday.year = int(raw_input(\"Year: \"))\n",
+ " record.salary = float(raw_input(\"Enter the salary: \"))\n",
+ "\n",
+ "test = person()\n",
+ "test.name = \"Arun\"\n",
+ "test.birthday.day = 10\n",
+ "test.birthday.month = 8\n",
+ "test.birthday.year = 75\n",
+ "test.salary = 4500.00\n",
+ "temp = person()\n",
+ "readin(temp)\n",
+ "printout(test)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the name: Balaji\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Birthdate\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Day: 24\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Month: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Year: 74\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the salary: 6500.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Details: \n",
+ "Name: Arun\n",
+ "Birthdate: 24: 2: 74\n",
+ "Salary: 4500.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.5 page no. 344"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class date:\n",
+ " day = 0\n",
+ " month = 0\n",
+ " year = 0\n",
+ "\n",
+ "class person:\n",
+ " name = ''\n",
+ " birthday = date()\n",
+ " salary = 0.0\n",
+ "\n",
+ "def printout(per):\n",
+ " print \"Employee Details: \"\n",
+ " print \"Name: \", per.name\n",
+ " print \"Birthdate: %3d:%3d:%3d\" %(per.birthday.day, per.birthday.month, per.birthday.year)\n",
+ " print \"Salary: %6.2f\" %(per.salary)\n",
+ "\n",
+ "def readin(record):\n",
+ " record.name = raw_input(\"Enter the name: \")\n",
+ " print \"Enter Birthdate\"\n",
+ " record.birthday.day = int(raw_input(\"Day: \"))\n",
+ " record.birthday.month = int(raw_input(\"Month: \"))\n",
+ " record.birthday.year = int(raw_input(\"Year: \"))\n",
+ " record.salary = float(raw_input(\"Enter the salary: \"))\n",
+ "\n",
+ "test = person()\n",
+ "test.name = \"Arun\"\n",
+ "test.birthday.day = 10\n",
+ "test.birthday.month = 8\n",
+ "test.birthday.year = 75\n",
+ "test.salary = 4500.00\n",
+ "temp = person()\n",
+ "readin(temp)\n",
+ "printout(temp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the name: Balaji\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Birthdate\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Day: 24\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Month: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Year: 74\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the salary: 6500.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Details: \n",
+ "Name: Balaji\n",
+ "Birthdate: 24: 2: 74\n",
+ "Salary: 6500.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6, page no. 346"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class date:\n",
+ " day = 0\n",
+ " month = 0\n",
+ " year = 0\n",
+ "\n",
+ "class person:\n",
+ " name = ''\n",
+ " birthday = date()\n",
+ " salary = 0.0\n",
+ " \n",
+ " def __init__(self, n, dt, sal):\n",
+ " self.name = n\n",
+ " self.birthday.day = dt[0]\n",
+ " self.birthday.month = dt[1]\n",
+ " self.birthday.year = dt[2]\n",
+ " self.salary = sal\n",
+ "\n",
+ "def printout(per):\n",
+ " print \"Employee Details: \"\n",
+ " print \"Name: \", per.name\n",
+ " print \"Birthdate: %3d:%3d:%3d\" %(per.birthday.day, per.birthday.month, per.birthday.year)\n",
+ " print \"Salary: %6.2f\" %(per.salary)\n",
+ "\n",
+ "def highest(sals):\n",
+ " return max(sals)\n",
+ " \n",
+ "record = [[\"Arun R.\", 10, 8, 75, 4000.00],\n",
+ " [\"vinod S.\", 3, 10, 74, 3000.00],\n",
+ " [\"Tanuj M.\", 21, 1, 73, 5500.00]]\n",
+ "\n",
+ "emp1 = person(record[0][0], (record[0][1], record[0][2], record[0][3]), record[0][4])\n",
+ "emp2 = person(record[1][0], (record[1][1], record[1][2], record[1][3]), record[1][4])\n",
+ "emp3 = person(record[2][0], (record[2][1], record[2][2], record[2][3]), record[2][4])\n",
+ "\n",
+ "sals = [emp1.salary, emp2.salary, emp3.salary]\n",
+ "\n",
+ "highest = highest(sals)\n",
+ "print \"The highest salary being paid is %6.2f\" %highest\n",
+ "printout(emp3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The highest salary being paid is 5500.00\n",
+ "Employee Details: \n",
+ "Name: Tanuj M.\n",
+ "Birthdate: 21: 1: 73\n",
+ "Salary: 5500.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.7, page no. 347"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class date:\n",
+ " day = 0\n",
+ " month = 0\n",
+ " year = 0\n",
+ "\n",
+ "class person:\n",
+ " name = ''\n",
+ " birthday = date()\n",
+ " salary = 0.0\n",
+ "\n",
+ "def readin(rec, list1):\n",
+ " rec.name = list1[0]\n",
+ " rec.birthday.day = list1[1]\n",
+ " rec.birthday.month = list1[2]\n",
+ " rec.birthday.year = list1[3]\n",
+ " rec.salary = list1[4]\n",
+ "\n",
+ " \n",
+ "def printout(per):\n",
+ " print \"Employee Details: \"\n",
+ " print \"Name: \", per.name\n",
+ " print \"Birthdate: %3d:%3d:%3d\" %(per.birthday.day, per.birthday.month, per.birthday.year)\n",
+ " print \"Salary: %6.2f\" %(per.salary)\n",
+ "\n",
+ "def highest(sals):\n",
+ " return max(sals)\n",
+ " \n",
+ "record = [[\"Tejaswi\", 24, 7, 70, 7000.00],\n",
+ " [\"vinod S.\", 3, 10, 74, 3000.00],\n",
+ " [\"Tanuj M.\", 21, 1, 73, 5500.00]]\n",
+ "\n",
+ "emp1 = person()\n",
+ "readin(emp1, record[0])\n",
+ "print emp1.birthday.day\n",
+ "emp2 = person()\n",
+ "readin(emp2, record[1])\n",
+ "emp3 = person()\n",
+ "readin(emp3, record[2])\n",
+ "\n",
+ "highest = highest([emp1.salary, emp2.salary, emp3.salary])\n",
+ "temp = emp1\n",
+ "print \"Highest salary being paid is \", highest\n",
+ "printout(temp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "24\n",
+ "Highest salary being paid is 7000.0\n",
+ "Employee Details: \n",
+ "Name: Tejaswi\n",
+ "Birthdate: 21: 1: 73\n",
+ "Salary: 7000.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.8, page no. 349"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class date:\n",
+ " day = 0\n",
+ " month = 0\n",
+ " year = 0\n",
+ "\n",
+ "class person:\n",
+ " name = ''\n",
+ " birthday = date()\n",
+ " salary = 0.0\n",
+ "\n",
+ "def readin():\n",
+ " record = []\n",
+ " for i in range(3):\n",
+ " print \"Employee no. \", i+1\n",
+ " temp = person()\n",
+ " temp.name = raw_input(\"Enter the name: \")\n",
+ " print \"Enter Birthdate\"\n",
+ " temp.birthday.day = int(raw_input(\"Day: \"))\n",
+ " temp.birthday.month = int(raw_input(\"Month: \"))\n",
+ " temp.birthday.year = int(raw_input(\"Year: \"))\n",
+ " temp.salary = float(raw_input(\"Enter the salary: \"))\n",
+ " record.append(temp)\n",
+ " return record\n",
+ "\n",
+ "def printout(per):\n",
+ " print \"Employee Details: \"\n",
+ " print \"Name: \", per.name\n",
+ " print \"Birthdate: %3d:%3d:%3d\" %(per.birthday.day, per.birthday.month, per.birthday.year)\n",
+ " print \"Salary: %6.2f\" %(per.salary)\n",
+ "\n",
+ "record = readin()\n",
+ "for i in range(3):\n",
+ " printout(record[i])\n",
+ " print \"hit enter to continue...\"\n",
+ " raw_input()\n",
+ " \n",
+ "#there is a printing mistake in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee no. 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the name: Balaji\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Birthdate\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Day: 24\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Month: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Year: 74\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the salary: 6500.50\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee no. 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the name: Tarun\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Birthdate\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Day: 30\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Month: 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Year: 69\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the salary: 6890.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee no. 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the name: Vinod\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Birthdate\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Day: 7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Month: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Year: 70\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the salary: 6700.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Details: \n",
+ "Name: Balaji\n",
+ "Birthdate: 7: 6: 70\n",
+ "Salary: 6500.50\n",
+ "hit enter to continue...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Details: \n",
+ "Name: Tarun\n",
+ "Birthdate: 7: 6: 70\n",
+ "Salary: 6890.00\n",
+ "hit enter to continue...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Details: \n",
+ "Name: Vinod\n",
+ "Birthdate: 7: 6: 70\n",
+ "Salary: 6700.00\n",
+ "hit enter to continue...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9, page no. 351"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class date:\n",
+ " day = 0\n",
+ " month = 0\n",
+ " year = 0\n",
+ "\n",
+ "class person:\n",
+ " name = ''\n",
+ " birthday = date()\n",
+ " salary = 0.0\n",
+ "\n",
+ "def readin(n):\n",
+ " record = []\n",
+ " for i in range(n):\n",
+ " print \"Employee no. \", i+1\n",
+ " temp = person()\n",
+ " temp.name = raw_input(\"Enter the name: \")\n",
+ " print \"Enter Birthdate\"\n",
+ " temp.birthday.day = int(raw_input(\"Day: \"))\n",
+ " temp.birthday.month = int(raw_input(\"Month: \"))\n",
+ " temp.birthday.year = int(raw_input(\"Year: \"))\n",
+ " temp.salary = float(raw_input(\"Enter the salary: \"))\n",
+ " record.append(temp)\n",
+ " return record\n",
+ "\n",
+ "def printout(record):\n",
+ " for i in range(n):\n",
+ " print \"Employee Details: \"\n",
+ " print \"Name: \", record[i].name\n",
+ " print \"Birthdate: %3d:%3d:%3d\" %(record[i].birthday.day, record[i].birthday.month, record[i].birthday.year)\n",
+ " print \"Salary: %6.2f\" %(record[i].salary)\n",
+ "\n",
+ "def sortalpha(rec):\n",
+ " for i in range(n-1):\n",
+ " for j in range(n-i-1):\n",
+ " if rec[j].name > rec[j+1].name:\n",
+ " rec[j], rec[j+1] = rec[j+1], rec[j]\n",
+ " return rec\n",
+ "\n",
+ "def sortage(rec):\n",
+ " for i in range(n-1):\n",
+ " for j in range(n-i-1):\n",
+ " if (rec[j].birthday.year > rec[j+1].birthday.year or rec[j].birthday.year == rec[j+1].birthday.year and\n",
+ " rec[j].birthday.month > rec[j+1].birthday.month or rec[j].birthday.month == rec[j+1].birthday.month and\n",
+ " rec[j].birthday.day > rec[j+1].birthday.day or rec[j].birthday.day == rec[j+1].birthday.day):\n",
+ " rec[j], rec[j+1] = rec[j+1], rec[j]\n",
+ " return rec\n",
+ "\n",
+ "def sortsal(rec):\n",
+ " for i in range(n-1):\n",
+ " for j in range(n-i-1):\n",
+ " if rec[j].salary > rec[j+1].salary:\n",
+ " rec[j], rec[j+1] = rec[j+1], rec[j]\n",
+ " return rec\n",
+ "\n",
+ "n = int(raw_input(\"Enter the number of records: \"))\n",
+ "record = readin(n)\n",
+ "\n",
+ "flag = True\n",
+ "while(flag):\n",
+ " print \"1: SORT BY NAME\"\n",
+ " print \"2: SORT BY AGE\"\n",
+ " print \"3: SORT BY SALARY\"\n",
+ " print \"4: QUIT \"\n",
+ " i = int(raw_input(\"Enter your choice: \"))\n",
+ " if i == 1:\n",
+ " sorted_rec = sortalpha(record)\n",
+ " printout(sorted_rec)\n",
+ " elif i == 2:\n",
+ " sorted_rec = sortage(record)\n",
+ " printout(sorted_rec)\n",
+ " elif i == 3:\n",
+ " sorted_rec = sortsal(record)\n",
+ " printout(sorted_rec)\n",
+ " elif i == 4:\n",
+ " flag = False\n",
+ " break\n",
+ " else:\n",
+ " print \"invalid choice...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number of records: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee no. 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the name: Vinod\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Birthdate\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Day: 23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Month: 8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Year: 74\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the salary: 6500\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee no. 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the name: Arun\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Birthdate\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Day: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Month: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Year: 70\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the salary: 7000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee no. 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the name: Puneet\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Birthdate\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Day: 30\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Month: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Year: 74\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the salary: 6900\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee no. 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the name: Tanuj\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Birthdate\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Day: 7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Month: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Year: 70\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the salary: 7700\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee no. 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the name: Rohit\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Birthdate\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Day: 17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Month: 12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Year: 73\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the salary: 6800\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1: SORT BY NAME\n",
+ "2: SORT BY AGE\n",
+ "3: SORT BY SALARY\n",
+ "4: QUIT \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your choice: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Details: \n",
+ "Name: Arun\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 7000.00\n",
+ "Employee Details: \n",
+ "Name: Puneet\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 6900.00\n",
+ "Employee Details: \n",
+ "Name: Rohit\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 6800.00\n",
+ "Employee Details: \n",
+ "Name: Tanuj\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 7700.00\n",
+ "Employee Details: \n",
+ "Name: Vinod\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 6500.00\n",
+ "1: SORT BY NAME\n",
+ "2: SORT BY AGE\n",
+ "3: SORT BY SALARY\n",
+ "4: QUIT \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your choice: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Details: \n",
+ "Name: Vinod\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 6500.00\n",
+ "Employee Details: \n",
+ "Name: Tanuj\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 7700.00\n",
+ "Employee Details: \n",
+ "Name: Rohit\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 6800.00\n",
+ "Employee Details: \n",
+ "Name: Puneet\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 6900.00\n",
+ "Employee Details: \n",
+ "Name: Arun\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 7000.00\n",
+ "1: SORT BY NAME\n",
+ "2: SORT BY AGE\n",
+ "3: SORT BY SALARY\n",
+ "4: QUIT \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your choice: 33\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "invalid choice...\n",
+ "1: SORT BY NAME\n",
+ "2: SORT BY AGE\n",
+ "3: SORT BY SALARY\n",
+ "4: QUIT \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your choice: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Details: \n",
+ "Name: Vinod\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 6500.00\n",
+ "Employee Details: \n",
+ "Name: Rohit\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 6800.00\n",
+ "Employee Details: \n",
+ "Name: Puneet\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 6900.00\n",
+ "Employee Details: \n",
+ "Name: Arun\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 7000.00\n",
+ "Employee Details: \n",
+ "Name: Tanuj\n",
+ "Birthdate: 17: 12: 73\n",
+ "Salary: 7700.00\n",
+ "1: SORT BY NAME\n",
+ "2: SORT BY AGE\n",
+ "3: SORT BY SALARY\n",
+ "4: QUIT \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your choice: 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example mem.c, page no. 359"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Note: There is no concept of unions in Python. We will implment using classes\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "class emp:\n",
+ " name = ''\n",
+ " idno = 0\n",
+ " salary = 0.0\n",
+ "\n",
+ "class desc:\n",
+ " name = ''\n",
+ " idno = 0\n",
+ " salary = 0.0\n",
+ "\n",
+ "e = emp()\n",
+ "d = desc()\n",
+ " \n",
+ "print \"The size of the structure is \", sys.getsizeof(e)\n",
+ "print \"The size of the union is \", sys.getsizeof(d)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The size of the structure is 72\n",
+ "The size of the union is 72\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on page no. 359"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class desc:\n",
+ " name = ''\n",
+ " idno = 0\n",
+ " salary = 0.0\n",
+ "\n",
+ "des = desc()\n",
+ "des.name = 'Vinod'\n",
+ "print \"Employee Details: \"\n",
+ "print \"The name is \", des.name\n",
+ "print \"The idno is \", des.idno\n",
+ "print \"The salary is \", des.salary\n",
+ "des.idno = 10\n",
+ "print \"Employee Details: \"\n",
+ "print \"The name is \", des.name\n",
+ "print \"The idno is \", des.idno\n",
+ "print \"The salary is \", des.salary\n",
+ "des.salary = 6500.00\n",
+ "print \"Employee Details: \"\n",
+ "print \"The name is \", des.name\n",
+ "print \"The idno is \", des.idno\n",
+ "print \"The salary is \", des.salary\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Details: \n",
+ "The name is Vinod\n",
+ "The idno is 0\n",
+ "The salary is 0.0\n",
+ "Employee Details: \n",
+ "The name is Vinod\n",
+ "The idno is 10\n",
+ "The salary is 0.0\n",
+ "Employee Details: \n",
+ "The name is Vinod\n",
+ "The idno is 10\n",
+ "The salary is 6500.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Mastering_C/screenshots/interest.png b/Mastering_C/screenshots/interest.png
new file mode 100644
index 00000000..1ac244be
--- /dev/null
+++ b/Mastering_C/screenshots/interest.png
Binary files differ
diff --git a/Mastering_C/screenshots/matrix.png b/Mastering_C/screenshots/matrix.png
new file mode 100644
index 00000000..4225f87e
--- /dev/null
+++ b/Mastering_C/screenshots/matrix.png
Binary files differ
diff --git a/Mastering_C/screenshots/stack.png b/Mastering_C/screenshots/stack.png
new file mode 100644
index 00000000..6de0cc8b
--- /dev/null
+++ b/Mastering_C/screenshots/stack.png
Binary files differ
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C10_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C10_1.ipynb
new file mode 100644
index 00000000..1b13f377
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C10_1.ipynb
@@ -0,0 +1,430 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10: AC Performance : Bandwidth, Slew rate and Noise"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 10.1 Page No 277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "t=0.35 #rise time\n",
+ "\n",
+ "#calculation\n",
+ "B=0.35/t #Bandwidth\n",
+ "\n",
+ "#result\n",
+ "print\"Bandwidth is\",B,\"MHz\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bandwidth is 1.0 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 10.2 Page No 277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "t=0.35 #rise time\n",
+ "\n",
+ "#calculation\n",
+ "B=0.35/t #Bandwidth\n",
+ "gain=B\n",
+ "\n",
+ "#result\n",
+ "print\"Openloop Voltage gain is\",gain\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Openloop Voltage gain is 1.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 10.3 Page No 277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "B1=10**6 #Hz\n",
+ "B2=100*10**3 #Hz\n",
+ "\n",
+ "#calculation\n",
+ "gain=B1/B2\n",
+ "\n",
+ "#Result\n",
+ "print\"As frenquency goes down by a factor 10, Gain rise sby same which is\",gain\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "As frenquency goes down by a factor 10, Gain rise sby same which is 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 10.4 Page No 278"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "B=1.5 #Mhz\n",
+ "f=1 #KHz\n",
+ "\n",
+ "#Calculation\n",
+ "gain=B*1000/f\n",
+ "\n",
+ "#Result\n",
+ "print\"Open loop Voltage gain is\",gain\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Open loop Voltage gain is 1500.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 10.5 Page No 279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Find the actual gain\n",
+ "\n",
+ "#Given\n",
+ "Acl=100.0 #Ideal Dc cloesd loop gain\n",
+ "Aol1=10000.0\n",
+ "Aol2=1000.0\n",
+ "Aol3=100.0\n",
+ "Aol4=10.0\n",
+ "Aol5=1.0\n",
+ "\n",
+ "#Calculation (a)\n",
+ "#For a noninverting amplifier\n",
+ "a1=Acl #ideal gain, a=(Rf+Ri)/Ri\n",
+ "actualAcl1=a1/((1+1*a1/Aol1))\n",
+ "#For the inverting amplifier\n",
+ "a2=101 #gain\n",
+ "actualAcl1_=-a1/(1+1*a2/Aol1)\n",
+ "\n",
+ "# (b)\n",
+ "#For a noninverting amplifier\n",
+ "a1=Acl #ideal gain, a=(Rf+Ri)/Ri\n",
+ "actualAcl2=a1/(1+1*a1/Aol2)\n",
+ "#For the inverting amplifier\n",
+ "a2=101 #gain\n",
+ "actualAcl2_=-a1/(1+1*a2/Aol2)\n",
+ "\n",
+ "#(c)\n",
+ "#For a noninverting amplifier\n",
+ "a1=Acl #ideal gain, a=(Rf+Ri)/Ri\n",
+ "actualAcl3=a1/(1+1*a1/Aol3)\n",
+ "#For the inverting amplifier\n",
+ "a2=101 #gain\n",
+ "actualAcl3_=-a1/(1+1*a2/Aol3)\n",
+ "\n",
+ "#(d)\n",
+ "#For a noninverting amplifier\n",
+ "a1=Acl #ideal gain, a=(Rf+Ri)/Ri\n",
+ "actualAcl4=a1/(1+1*a1/Aol4)\n",
+ "#For the inverting amplifier\n",
+ "a2=101 #gain\n",
+ "actualAcl4_=-a1/(1+1*a2/Aol4)\n",
+ "\n",
+ "#(e)\n",
+ "#For a noninverting amplifier\n",
+ "a1=Acl #ideal gain, a=(Rf+Ri)/Ri\n",
+ "actualAcl5=a1/(1+1*a1/Aol5)\n",
+ "#For the inverting amplifier\n",
+ "a2=101 #gain\n",
+ "actualAcl5_=-a1/(1+1*a2/Aol5)\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)Actual gain in noninverting amplifier is\",round(actualAcl5,2)\n",
+ "print\"Actual gain in inverting amplifier is\",round(actualAcl5_,2)\n",
+ "print\"(b)Actual gain in noninverting amplifier is\",round(actualAcl4,2)\n",
+ "print\"Actual gain in inverting amplifier is\",round(actualAcl4_,2)\n",
+ "print\"(c)Actual gain in noninverting amplifier is\",round(actualAcl3,2)\n",
+ "print\"Actual gain in inverting amplifier is\",round(actualAcl3_,2)\n",
+ "print\"(d)Actual gain in noninverting amplifier is\",round(actualAcl2,2)\n",
+ "print\"Actual gain in inverting amplifier is\",round(actualAcl2_,2)\n",
+ "print\"(e)Actual gain in noninverting amplifier is\",round(actualAcl1,0)\n",
+ "print\"Actual gain in inverting amplifier is\",round(actualAcl1_,2)\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)Actual gain in noninverting amplifier is 0.99\n",
+ "Actual gain in inverting amplifier is -0.98\n",
+ "(b)Actual gain in noninverting amplifier is 9.09\n",
+ "Actual gain in inverting amplifier is -9.01\n",
+ "(c)Actual gain in noninverting amplifier is 50.0\n",
+ "Actual gain in inverting amplifier is -49.75\n",
+ "(d)Actual gain in noninverting amplifier is 90.91\n",
+ "Actual gain in inverting amplifier is -90.83\n",
+ "(e)Actual gain in noninverting amplifier is 99.0\n",
+ "Actual gain in inverting amplifier is -99.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 10.6 Page No 283"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ri=10.0 #Kohm\n",
+ "Rf=Ri\n",
+ "B=10**6 #Hz\n",
+ "\n",
+ "#Calculation\n",
+ "#(a)\n",
+ "Acl1=-Rf/Ri\n",
+ "fh1=B/((Ri+Rf)/Ri)\n",
+ "\n",
+ "#(b)\n",
+ "ACl2=(Ri+Rf)/Ri\n",
+ "\n",
+ "#(c)\n",
+ "Acl3=1 #Voltage follower gain\n",
+ "Rf2=0\n",
+ "Ri2=1\n",
+ "fh2=B/((Ri2+Rf2)/Ri2)\n",
+ "\n",
+ "#Resilt\n",
+ "print\"(a)The voltage gain is\",Acl1\n",
+ "print\"bandwidth is\",fh1/1000,\"khz\"\n",
+ "print\"(b)The voltage gain is\",ACl2\n",
+ "print\"(c)The voltage gain is\",Acl3\n",
+ "print\"bandwidth is\",fh2/1000000,\"Mhz\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The voltage gain is -1.0\n",
+ "bandwidth is 500.0 khz\n",
+ "(b)The voltage gain is 2.0\n",
+ "(c)The voltage gain is 1\n",
+ "bandwidth is 1 Mhz\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 10.7 Page No 285"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "V=10 #V\n",
+ "slewrate=0.5 #per microsecond\n",
+ "\n",
+ "#Calculation\n",
+ "t=V/slewrate\n",
+ "\n",
+ "#Result\n",
+ "print\"The time taken is\",t,\"microsecond\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The time taken is 20.0 microsecond\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 10.8 Page No 286"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "slewrate=0.5 #per microsecond\n",
+ "V1=10.0 #Peak voltage\n",
+ "V2=1\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "fmax1=slewrate*1000/(6.28*V1)\n",
+ "fmax2=slewrate*1000/(6.28*V2)\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)maximum frenquency is\",round(fmax1,1),\"KHz\"\n",
+ "print\"(b)maximum frenquency is\",round(fmax2,0),\"KHz\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)maximum frenquency is 8.0 KHz\n",
+ "(b)maximum frenquency is 80.0 KHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 10.9 Page No 287"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "B1=500 #Khz, bandwidth\n",
+ "gain1=-1 #Gain for inverting amplifier\n",
+ "gain2=2 #Gain for non-inverting amplifier\n",
+ "slewrate=0.5 #per micros\n",
+ "V=10 #V\n",
+ "\n",
+ "#Calculation\n",
+ "Vopmax=slewrate*10**6/(6.28*B1*10**3)\n",
+ "fmax=slewrate*1000/(6.28*V)\n",
+ "\n",
+ "#Result\n",
+ "print\"Maximum operating voltage is\",round(Vopmax*1000,1),\"mV\"\n",
+ "print\"maximum frenquency is\",round(fmax,0),\"Khz\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum operating voltage is 159.2 mV\n",
+ "maximum frenquency is 8.0 Khz\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C11_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C11_1.ipynb
new file mode 100644
index 00000000..057dd53b
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C11_1.ipynb
@@ -0,0 +1,694 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Active Filters"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.1 Page No 298"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "R=10 #Kohm\n",
+ "C=0.001 #microF\n",
+ "\n",
+ "#Calculation\n",
+ "wc=1/(R*10**3*C*10**-6)\n",
+ "fc=wc/(6.28)\n",
+ "\n",
+ "#Result\n",
+ "print\"The cut off frequency is\",round(fc/1000,2),\"Khz\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The cut off frequency is 15.92 Khz\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.2 Page No 298"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "f=2 #Frequency, khz\n",
+ "C=0.005 #MicroF\n",
+ "\n",
+ "#Calculation\n",
+ "R=1/(6.28*2*10**3*C*10**-6)\n",
+ "\n",
+ "#Result\n",
+ "print\"The value of R is\",round(R/1000,1),\"Kohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of R is 15.9 Kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.3 Page No 298"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "f=30 #rad/s, frequency\n",
+ "C=0.01 #microF\n",
+ "R=1/(f*10**3*C*10**-6)\n",
+ "\n",
+ "#Result\n",
+ "print\"The value of R is\",round(R/1000,1),\"Kohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of R is 3.3 Kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.4 Page No 301"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "f=1 #Khz, cut off frequency\n",
+ "C1=0.01 #MicroF\n",
+ "\n",
+ "#Calculation\n",
+ "C2=2*C1\n",
+ "R=0.707/(6.28*f*10**3*C1*10**-6)\n",
+ "Rf=2*R\n",
+ "\n",
+ "#Result\n",
+ "print\"The value of R is\",round(R,0),\"ohm\"\n",
+ "print\"The value of Rf is\",round(Rf,0),\"ohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of R is 11258.0 ohm\n",
+ "The value of Rf is 22516.0 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.5 Page No 304"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "C3=0.01 #microF, from fig 11.5 (a)\n",
+ "f=1.0 #Khz, cut off frequency\n",
+ "\n",
+ "#Calculation\n",
+ "C1=C3/2.0\n",
+ "C2=2*C3\n",
+ "R=1/(6.28*f*10**3*C3*10**-6)\n",
+ "\n",
+ "#Result\n",
+ "print\"The value of C1=\",C1,\"microF\"\n",
+ "print\"The value of C2=\",C2,\"microF\"\n",
+ "print\"The value of R=\",round(R),\"ohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of C1= 0.005 microF\n",
+ "The value of C2= 0.02 microF\n",
+ "The value of R= 15924.0 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.6 Page No 307"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "C=0.002 #microF, capacitance\n",
+ "fc=10 #Khz, frequency\n",
+ "\n",
+ "#Calculation\n",
+ "R=1/(6.28*f*10**3*C*10**-6)\n",
+ "\n",
+ "#Result\n",
+ "print\"The value of R=\",round(R/10000),\"kohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of R= 8.0 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.7 Page No 307"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "R=22.0 #kohm\n",
+ "C=0.001 #microF\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "wc=1/(R*10**3*C*10**-6)\n",
+ "fc=wc/(2*math.pi)\n",
+ "\n",
+ "#Result\n",
+ "print\"The value of wc is\",round(wc/10000,2),\"krad/s\"\n",
+ "print\"The value of fc is\",round(fc/10,1),\"Hz\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of wc is 4.55 krad/s\n",
+ "The value of fc is 723.4 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.8 Page No 309"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "C1=0.01 #microF\n",
+ "C2=C1\n",
+ "f=1 #KHz, frequency\n",
+ "\n",
+ "#Calculation\n",
+ "#From eq 11.9\n",
+ "R1=1.414/(6.28*f*10**3*C1*10**-6)\n",
+ "R2=R1/2.0\n",
+ "\n",
+ "#result\n",
+ "print\"The value of R1 is\",round(R1/1000,1),\"kohm\"\n",
+ "print\"The value of R2 is\",round(R2/1000,1),\"kohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of R1 is 22.5 kohm\n",
+ "The value of R2 is 11.3 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.9 Page No 309"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "C1=125 #pF\n",
+ "C2=C1 #KHz,cut off frequency\n",
+ "f=80 #Krad/s cutoff frequency\n",
+ "\n",
+ "#Calculation\n",
+ "#From eq 11.9\n",
+ "R1=1.414/(f*10**3*C1*10**-12)\n",
+ "R2=R1/2.0\n",
+ "\n",
+ "#result\n",
+ "print\"The value of R1 is\",round(R1/1000,0),\"kohm\"\n",
+ "print\"The value of R2 is\",round(R2/1000,1),\"kohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of R1 is 141.0 kohm\n",
+ "The value of R2 is 70.7 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.10 Page No 311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "f=159.0 #Hz, cut off frequency\n",
+ "C=0.1 #microF\n",
+ "C1=C\n",
+ "C2=C\n",
+ "C3=C\n",
+ "wc=1\n",
+ "\n",
+ "#calculation\n",
+ "R3=1/(wc*10**3*C*10**-6)\n",
+ "R1=2*R3\n",
+ "R2=R3/2.0\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)The value of R3 is\",round(R3/1000),\"kohm\"\n",
+ "print\"(b)The value of R1 is\",round(R1/1000),\"kohm\"\n",
+ "print\"(c)The value of R2 is\",round(R2/1000,0),\"kohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The value of R3 is 10.0 kohm\n",
+ "(b)The value of R1 is 20.0 kohm\n",
+ "(c)The value of R2 is 5.0 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.11 Page No 311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "f=60 #kHz, cut off frequency\n",
+ "C=220 #pF\n",
+ "C1=C\n",
+ "C2=C\n",
+ "C3=C\n",
+ "\n",
+ "#calculation\n",
+ "R3=1/(6.28*f*10**3*C*10**-12)\n",
+ "R1=2*R3\n",
+ "R2=R3/2.0\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)The value of R3 is\",round(R3/1000,0),\"kohm\"\n",
+ "print\"(b)The value of R1 is\",round(R1/1000),\"kohm\"\n",
+ "print\"(c)The value of R2 is\",round(R2/1000),\"kohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The value of R3 is 12.0 kohm\n",
+ "(b)The value of R1 is 24.0 kohm\n",
+ "(c)The value of R2 is 6.0 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.12 Page No 313"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "f1=300 # Hz, lower cutoff frequency\n",
+ "f2=3000 #Hz, upper cutoff frequency\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "B=f2-f1\n",
+ "f=math.sqrt(f1*f2)\n",
+ "\n",
+ "#Result\n",
+ "print\"The bandwidth is\",B,\"Hz\"\n",
+ "print\"The frequency is\",round(f,1),\"Hz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The bandwidth is 2700 Hz\n",
+ "The frequency is 948.7 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.13 Page No 314"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "fr=950 #Hz, resonant frequency\n",
+ "B=2700 #Hz\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "fl=math.sqrt(B**2/4.0+fr**2)-B/2.0\n",
+ "fh=fl+B\n",
+ "\n",
+ "#Result\n",
+ "print\"The lower cutoff frequency is\",round(fl,1),\"Hz\"\n",
+ "print\"The upper cutoff frequency is\",round(fh,1),\"Hz\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The lower cutoff frequency is 300.8 Hz\n",
+ "The upper cutoff frequency is 3000.8 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.14 Page No 314"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "B=2700.0 #Hz\n",
+ "fr=950 #Hz resonant frequency\n",
+ "\n",
+ "#calculation\n",
+ "Q=fr/B\n",
+ "\n",
+ "#Result\n",
+ "print\"The quality factor\",round(Q,2)\n",
+ "\n",
+ "if Q<0.5:\n",
+ " print\"This filter is classified\"\n",
+ "else:\n",
+ " print\"This filter is not classified\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The quality factor 0.35\n",
+ "This filter is classified\n"
+ ]
+ }
+ ],
+ "prompt_number": 55
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.15 Page No 318"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "fr=1000 #Hz, resonant frequency\n",
+ "fl=80 #From eq 11.16\n",
+ "fh=1280 #upper frequency\n",
+ "C=0.015 #microF\n",
+ "Q=2.0 #Quality factor\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "B=fr/Q\n",
+ "fl=math.sqrt(B**2/4.0+fr**2)-B/2.0\n",
+ "fh=fl+B\n",
+ "\n",
+ "R=0.1591/(B*C*10**-6)\n",
+ "Rr=R/(2*Q**2-1)\n",
+ "\n",
+ "#Result\n",
+ "print\"The Rr is\",round(Rr/1000,2),\"kohm\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Rr is 3.03 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 57
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.16 Page No 319"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "R=21.21*10**3 #ohm, resiatance\n",
+ "Rr=3.03*10**3 \n",
+ "C=0.015*10**-6 #F, capacitance\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "#From eq 11.12\n",
+ "fr=0.1125*math.sqrt(1+R/Rr)/(R*C)\n",
+ "B=0.1591/(R*C)\n",
+ "\n",
+ "#Result\n",
+ "print\"The resonant frequency is\",round(fr,0),\"Hz\"\n",
+ "print\"Bandwidth is\",round(B,0),\"Hz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The resonant frequency is 1000.0 Hz\n",
+ "Bandwidth is 500.0 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 11.17 Page No 321"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "fr=120 #Hz resonant frequency\n",
+ "B=12 #Hz\n",
+ "Q=10 #Quality factor\n",
+ "\n",
+ "#Calculation\n",
+ "C=0.33 #MicroF\n",
+ "R=0.1591/(B*C*10**-6)\n",
+ "Rr=R/(2*Q**2-1)\n",
+ "\n",
+ "#Result\n",
+ "print\"The value of resistance is\",round(R/1000,1),\"kohm\"\n",
+ "print\"The value of Rr is\",round(Rr,1),\"kohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of resistance is 40.2 kohm\n",
+ "The value of Rr is 201.9 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 64
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C12_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C12_1.ipynb
new file mode 100644
index 00000000..ca52f7c0
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C12_1.ipynb
@@ -0,0 +1,358 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12:Modulating,Demodulating and frequency Changing with the multiplier"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 12.1 Page No 332"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "#(a)\n",
+ "V=10.0\n",
+ "x1=10 #Polarity combination of voltages\n",
+ "y1=10 #V\n",
+ "#(b)\n",
+ "x2=-10 #V, 2nd combination\n",
+ "y2=10 #V\n",
+ "#(c)\n",
+ "x3=10 #V\n",
+ "y3=-10 #V\n",
+ "#(d)\n",
+ "x4=-10 #V\n",
+ "y4=-10 #V\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "Vo1=x1*y1/V\n",
+ "Vo2=x2*y2/V\n",
+ "Vo3=x3*y3/V\n",
+ "Vo4=x4*y4/V\n",
+ "\n",
+ "#Result\n",
+ "print\"The values of Vo are\",Vo1,\"V ,\",Vo2,\"V ,\",Vo3,\"V ,\",Vo4,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The values of Vo are 10.0 V , -10.0 V , -10.0 V , 10.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 12.2 Page No 334"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ei1=10 #V\n",
+ "Ei2=-10 #V\n",
+ "\n",
+ "#Calculation\n",
+ "Vo1=Ei1**2/Ei1\n",
+ "Vo2=Ei2**2/Ei1\n",
+ "\n",
+ "#Reult\n",
+ "print\"(a)The value of Vo is\",Vo1,\"V\"\n",
+ "print\"(b)The value of Vo is\",Vo2,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The value of Vo is 10 V\n",
+ "(b)The value of Vo is 10 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 12.4 Page No 336"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ei1=10 #V\n",
+ "f1=1 #KHz\n",
+ "Ei2=2 #V\n",
+ "f1=2.5 #KHz\n",
+ "\n",
+ "#Calculation\n",
+ "dcvalue=Ei1**2/20.0\n",
+ "pac=Ei1**2/20.0\n",
+ "\n",
+ "\n",
+ "#(b)\n",
+ "dcvalue_=Ei2**2/20.0\n",
+ "pac_=Ei2**2/20.0\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)The DC and AC output voltage are\",dcvalue,\"V,\",pac,\"V at 2 KHz\"\n",
+ "print\"(b)The DC and AC output voltage are\",dcvalue_,\"V,\",pac_,\"V at 5 KHz\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The DC and AC output voltage are 5.0 V, 5.0 V at 2 KHz\n",
+ "(b)The DC and AC output voltage are 0.2 V, 0.2 V at 5 KHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 12.5 Page No 339"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Exp=5 #V\n",
+ "Eyp=5 #V\n",
+ "Vodc=1.25 #DC component of Vo\n",
+ "\n",
+ "#calculation\n",
+ "import math\n",
+ "theta=math.acos(20*Vodc/(Exp*Eyp))\n",
+ "\n",
+ "#Result\n",
+ "print\"The angle is\",theta,\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The angle is 0.0 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 12.6 Page No 339"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vo=0 #AVerage value of DC component\n",
+ "\n",
+ "#calculation\n",
+ "import math\n",
+ "theta=math.acos(Vo)\n",
+ "\n",
+ "#Result\n",
+ "print\"The angle is\",round(theta*180/3.14,0),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The angle is 90.0 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 12.7 Page No 339"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "theta1=30 #degree\n",
+ "theta2=45 #degree\n",
+ "theta3=60 #degree\n",
+ "theta4=0 #Degree from example 12.5 \n",
+ "theta5=90 #Degree from example 12.6\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "Vodc1=math.cos(theta1*3.14/180.0)\n",
+ "Vodc2=math.cos(theta2*3.14/180.0)\n",
+ "Vodc3=math.cos(theta3*3.14/180.0)\n",
+ "Vodc4=math.cos(theta4*3.14/180.0)\n",
+ "Vodc5=math.cos(theta5*3.14/180.0)\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print\"The Output Dc voltages are\",round(Vodc1,3),\"V ,\",round(Vodc2,3),\"V ,\",round(Vodc3,3),\"V ,\",round(Vodc4,3),\"V ,\",round(Vodc5,3),\"V ,\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Output Dc voltages are 0.866 V , 0.707 V , 0.5 V , 1.0 V , 0.001 V ,\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 12.8 Page No 340"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#GIven\n",
+ "theta1=90 #degree\n",
+ "theta2=120 #degree\n",
+ "theta3=135 #degree\n",
+ "theta4=150 #degree\n",
+ "theta5=180 #degree\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "Vodc1=math.cos(theta1*3.14/180.0)\n",
+ "Vodc2=math.cos(theta2)\n",
+ "Vodc3=math.cos(theta3)\n",
+ "Vodc4=math.cos(theta4)\n",
+ "Vodc5=math.cos(theta5)\n",
+ "\n",
+ "#Result\n",
+ "print\"The Voltages are\",round(Vodc1,3),\"V ,\",round(Vodc2,3),\"V \",round(Vodc3,3),\"V \",round(Vodc4,3),\"V \",round(Vodc5,3),\"V \"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Voltages are 0.001 V , 0.814 V -0.996 V 0.699 V -0.598 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 12.10 Page No 349"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ecp=5 #V, Voltage\n",
+ "fc=10000 #Hz frequency\n",
+ "Em=5 #V peak voltage\n",
+ "fm=1000 #Hz frequency\n",
+ "\n",
+ "#Calculation\n",
+ "Vc=Em*Ecp/(10.0) #The carrier term peak voltage\n",
+ "Vp=Vc #product term Peak voltage\n",
+ "Vs=Em*Ecp/(20.0) #The side term peak voltagec\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print\"The carrier term peak voltage is\",Vc,\"V\"\n",
+ "print\"The product term peak voltage is\",Vp,\"V\"\n",
+ "print\"The side term peak voltage is\",Vs,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The carrier term peak voltage is 2.5 V\n",
+ "The product term peak voltage is 2.5 V\n",
+ "The side term peak voltage is 1.25 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C13_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C13_1.ipynb
new file mode 100644
index 00000000..19a9a8b1
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C13_1.ipynb
@@ -0,0 +1,496 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13: Integrated circuit Timers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 13.1 Page No 371"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "#From fig 13.7 (a)\n",
+ "Ra=6.8 #kohm, resistance\n",
+ "Rb=3.3 #Kohm\n",
+ "C=0.1 #microF, capacitance\n",
+ "\n",
+ "#Calculation\n",
+ "thigh=0.695*(Ra+Rb)*C\n",
+ "tlow=0.695*Rb*C\n",
+ "f=1.44/((Ra+2*Rb)*C)\n",
+ "\n",
+ "#Result\n",
+ "print\"The value of high time is\",round(thigh,1),\"ms\"\n",
+ "print\"The value of low time is\",round(tlow,2),\"ms\"\n",
+ "print\"The value of frequency is\",round(f,2),\"khz\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of high time is 0.7 ms\n",
+ "The value of low time is 0.23 ms\n",
+ "The value of frequency is 1.07 ms\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 13.2 Page No 373"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "#From fig 13.7 (a)\n",
+ "Ra=6.8 #kohm, resistance\n",
+ "Rb=3.3 #Kohm\n",
+ "\n",
+ "#Calculation\n",
+ "D=Rb/(Ra+2*Rb)\n",
+ "\n",
+ "#Result\n",
+ "print\"The Duty Cycle is\",round(D,2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Duty Cycle is 0.25\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 13.3 Page No 377"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#GIven\n",
+ "V=5 #V, Voltage\n",
+ "E1=0 #V\n",
+ "E2=1\n",
+ "Re=3 #Kohm, resistance (fig 13-10)\n",
+ "C=1 #microF\n",
+ "\n",
+ "#Calculation\n",
+ "I=(V-E1)/(3.0) #Current\n",
+ "fc=3/(Re*C)\n",
+ "df=0.2*fc*E2\n",
+ "fout=fc+df\n",
+ "E3=-1 #V\n",
+ "df_=0.2*fc*E3\n",
+ "fout_=fc+df_\n",
+ "Elower=-4\n",
+ "Eupper=4\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)The charge current is\",round(I,2),\"mA\"\n",
+ "print\"(b)The current frequency is\",fc,\"KHz\"\n",
+ "print\"(c)df=\",df*1000,\"Hz\",\"\\nand The frequency shift is\",(df-df_)*1000,\"Hz\"\n",
+ "print\"fout was initially\",fout*1000,\"Hz . then changes to\",fout_*1000,\"Hz\"\n",
+ "print\"(d)The positive nd negative limits are\",Eupper,\"V and\",Elower,\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The charge current is 1.67 mA\n",
+ "(b)The current frequency is 1 KHz\n",
+ "(c)df= 200.0 Hz \n",
+ "and The frequency shift is 400.0 Hz\n",
+ "fout was initially 1200.0 Hz . then changes to 800.0 Hz\n",
+ "(d)The positive nd negative limits are 4 V and -4 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 13.4 Page No 380"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#GIven\n",
+ "Ra=9.1 #Kohm\n",
+ "thigh=1 #ms\n",
+ "\n",
+ "#Calculation\n",
+ "C=thigh*10**-3/(1.1*Ra)\n",
+ "\n",
+ "#Result\n",
+ "print\"The value of C is\",round(C*10**3,1),\"microF\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of C is 0.1 microF\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 13.5 Page No 381"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ra=10 #Kohm\n",
+ "C=0.2 #microF\n",
+ "Ci=0.001 #microF\n",
+ "\n",
+ "#calculation\n",
+ "thigh=1.1*(Ra*10**3*C*10**-6)\n",
+ "t=Ra*10**3*Ci\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)The value of high time is\",thigh*1000,\"ms\"\n",
+ "print\"(b)Time constant is\",t/1000,\"ms\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The value of high time is 2.2 ms\n",
+ "(b)Time constant is 0.01 ms\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 13.6 Page No 383"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ra=10 #Kohm\n",
+ "C=0.1 #microF\n",
+ "f=1 #kHz\n",
+ "\n",
+ "#Calculation\n",
+ "thigh=1.1*(Ra*10**3*C*10**-6)\n",
+ "#thigh should exceed two periods and be less than 3 periods.\n",
+ "thigh_=2.2 #ms, chose a value\n",
+ "Ra=thigh_/(1.1*C*10**-6)\n",
+ "\n",
+ "#Result\n",
+ "print\"(a) The time interval is\",thigh*1000,\"ms\"\n",
+ "print\"Ra is\",Ra/10**6,\"Kohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The time interval is 1.1 ms\n",
+ "Ra is 20.0 Kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 13.7 Page No 387"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "R=100 #Kohm\n",
+ "C=0.01 #microF\n",
+ "p1=3 #pin\n",
+ "p2=4\n",
+ "p3=7\n",
+ "p4=8\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "T=R*10**3*C*10**-6\n",
+ "tlow1=4*T #Using Table 13-2, pin=3 , time= 4*T\n",
+ "tlow2=8*T\n",
+ "tlow3=64*T\n",
+ "tlow4=128*T\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)The required time is\",tlow1*1000,\"ms\"\n",
+ "print\"(b)The required time is\",tlow2*1000,\"ms\"\n",
+ "print\"(c)The required time is\",tlow3*1000,\"ms\"\n",
+ "print\"(d)The required time is\",tlow4*1000,\"ms\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The required time is 4.0 ms\n",
+ "(b)The required time is 8.0 ms\n",
+ "(c)The required time is 64.0 ms\n",
+ "(d)The required time is 128.0 ms\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 13.8 Page No 389"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "T=1 #s\n",
+ "\n",
+ "#Calculation\n",
+ "#Pins 3,6,7 are jumpered\n",
+ "Tsum1=8*T+16*T\n",
+ "Tsum2=4*T+32*T+64*T\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)The timing cycle is\",Tsum1,\"s\"\n",
+ "print\"(b)The timing cycle is\",Tsum2,\"s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The timing cycle is 24 s\n",
+ "(b)The timing cycle is 100 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 13.9 Page No 389"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "C=1 #microF\n",
+ "R=5 #Mohm\n",
+ "T=5 #s\n",
+ "\n",
+ "#Calculation\n",
+ "Tsum1=4*T+8*T\n",
+ "t=1*T\n",
+ "Tsum2=T+2*T+4*T+8*T+16*T+32*T+64*T+128*T\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)The timing cycle is\",Tsum1/60,\"min\"\n",
+ "print\"(b)Minimum programmeble timing cycle is\",t,\"s\"\n",
+ "print\"(c)maximum programmable timing cycle is\",round(Tsum2,2),\"s or 21 min 15 s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The timing cycle is 1 min\n",
+ "(b)Minimum programmeble timing cycle is 5 s\n",
+ "(c)maximum programmable timing cycle is 1275.0 s or 21 min 15 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 13.10 Page No 391"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "T=2.5 #ms\n",
+ "\n",
+ "#pin from fig 13-19\n",
+ "p1=1\n",
+ "p2=2\n",
+ "p3=3\n",
+ "p4=4\n",
+ "\n",
+ "#Calculation\n",
+ "#Time base rating\n",
+ "t1=T\n",
+ "t2=2*T\n",
+ "t3=4*T\n",
+ "t4=8*T\n",
+ "\n",
+ "#Period\n",
+ "P1=2*T\n",
+ "P2=4*T\n",
+ "P3=8*T\n",
+ "P4=16*T\n",
+ "\n",
+ "#Frequency\n",
+ "f1=1/(P1)\n",
+ "f2=1/(P2)\n",
+ "f3=1/(P3)\n",
+ "f4=1/(P4)\n",
+ "\n",
+ "#Result\n",
+ "print\"The frequencies are\",f1*1000,\"Hz,\",f2*1000,\"Hz,\",f3*1000,\"Hz,\",f4*1000,\"Hz\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The frequencies are 200.0 Hz, 100.0 Hz, 50.0 Hz, 25.0 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 13.11 Page No 393"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "#From fig 13.11 (a)\n",
+ "T=1 #ms\n",
+ "\n",
+ "#Calculation\n",
+ "Tsum=T+4*T\n",
+ "period=Tsum+T\n",
+ "f=1/(period*10**-3)\n",
+ "\n",
+ "#Result\n",
+ "print\"The frequency is\",round(f,1),\"Hz\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The frequency is 166.7 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C14_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C14_1.ipynb
new file mode 100644
index 00000000..5eaa01c3
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C14_1.ipynb
@@ -0,0 +1,509 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 14:Digital to analog Converters"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.1 Page no 403"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "n=8 #An 8-bit DAC wire\n",
+ "V1=0 #Voltage range\n",
+ "V2=5.12\n",
+ "\n",
+ "#Calculation\n",
+ "R=2**n\n",
+ "dvo=V2/R\n",
+ "Vfs=V2*(1-1/R)\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)The resolution is\",R\n",
+ "print\"(b)The output change per bit is\",dvo*1000,\"mV/bit\"\n",
+ "print\"(c)the ideal full scale output voltage is\",Vfs,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The resolution is 256\n",
+ "(b)The output change per bit is 20.0 mV/bit\n",
+ "(c)the ideal full scale output voltage is 5.12 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.2 Page no 404"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Res=20 #mV/bit\n",
+ "#From the given code 00010110 and 10000000\n",
+ "#The binary weighted code for unipolar operation\n",
+ "b7=0\n",
+ "b6=0\n",
+ "b5=0\n",
+ "b4=1\n",
+ "b3=0\n",
+ "b2=1\n",
+ "b1=1\n",
+ "b0=0\n",
+ "#For part (b)\n",
+ "b7_=1\n",
+ "b6_=0\n",
+ "b5_=0\n",
+ "b4_=0\n",
+ "b3_=0\n",
+ "b2_=0\n",
+ "b1_=0\n",
+ "b0_=0\n",
+ "\n",
+ "#Calculation\n",
+ "D=b7*2**7+b6*2**6+b5*2**5+b4*2**4+b3*2**3+b2*2**2+b1*2**1+b0*2**0\n",
+ "Vo=D*Res*10**-3\n",
+ "D_=b7_*2**7+b6_*2**6+b5_*2**5+b4_*2**4+b3_*2**3+b2_*2**2+b1_*2**1+b0_*2**0\n",
+ "Vo_=D_*Res*10**-3\n",
+ "\n",
+ "#Resul\n",
+ "print\"(a)The output voltage is\",Vo,\"V\"\n",
+ "print\"(b)The output voltage is\",Vo_,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The output voltage is 0.44 V\n",
+ "(b)The output voltage is 2.56 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.3 Page no 404"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "#From Example 14.1\n",
+ "n=8 #An 8-bit DAC wire\n",
+ "V1=0 #Voltage range\n",
+ "V2=5.12\n",
+ "\n",
+ "#Calculation\n",
+ "dvo=2*V2/2**n \n",
+ "\n",
+ "#Result\n",
+ "print\"The full scale output voltage range\",dvo*1000,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The full scale output voltage range 40.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.4 Page no 405"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vref=10.24 #V, input ref voltage\n",
+ "p=0.05 #Percentage error\n",
+ "n=12 #12 bit unipolar DAC\n",
+ "\n",
+ "#Calculation\n",
+ "Voff=0.05/100*Vref\n",
+ "dvo=Vref/(2**n)\n",
+ "a=Voff/dvo\n",
+ "\n",
+ "#REsult\n",
+ "print\"The offset voltage is\",Voff*1000,\"mV\"\n",
+ "print\"Interms of least significant bit(s) it is\",dvo*1000,\"mV/bit\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The offset voltage is 5.12 mV\n",
+ "Interms of least significant bit(s) it is 2.5 mV/bit\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.5 Page no 407"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "n=8.0 #8-bit DAC\n",
+ "error=0.2 #percent\n",
+ "Vref=5.12 #V\n",
+ "Vos=0\n",
+ "\n",
+ "#Calculation\n",
+ "V11=(((-error/100.0))+1)*(Vref)+Vos\n",
+ "\n",
+ "#REsult\n",
+ "print\"The minimum output voltage is\",round(V11,1),\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum output voltage is 5.1 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.6 Page no 411"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "n=4.0 #4 bit resistance ladder\n",
+ "R=10.0 #kohm\n",
+ "Vref=10.0 #V\n",
+ "\n",
+ "#Calculation\n",
+ "Res=Vref/(2**n*R*10**3)\n",
+ "\n",
+ "#From dicimal value of binary 1111\n",
+ "D=15\n",
+ "Iout=Res*D\n",
+ "\n",
+ "#Result\n",
+ "print\"The resolution of 1 LSB is\",Res*10**6,\"microA\"\n",
+ "print\"output current is\",Iout*1000,\"microA\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The resolution of 1 LSB is 62.5 microA\n",
+ "output current is 0.9375 microA\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.7 Page no 412"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Io=62.5 #microA, from ex. 14.6\n",
+ "Rf=10 #kohm , from fig.14.7\n",
+ "Vref=10 #V, reference voltage\n",
+ "R=Rf\n",
+ "n=4 #no of bits\n",
+ "\n",
+ "#Calculation\n",
+ "VR=Io*Rf*10**-3\n",
+ "D=15 #For a digital input of 1111\n",
+ "Vo=-VR*D\n",
+ "\n",
+ "#REsult\n",
+ "print\"The voltage resolution of 1 LSB is\",VR,\"V\"\n",
+ "print\"When digital input is 1111 , Vo is\",Vo,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The voltage resolution of 1 LSB is 0.625 V\n",
+ "When digital input is 1111 , Vo is -9.375 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.8 Page no 416"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vref=10.0 #V, from fig. 14.8. reference voltage\n",
+ "Rref=5.0 #kohm\n",
+ "n=8.0 #no of bits\n",
+ "\n",
+ "#Calculation\n",
+ "Iref=Vref/Rref\n",
+ "I=Vref/(Rref*2**n)\n",
+ "\n",
+ "#Result\n",
+ "print\"The ladder input current is\",Iref,\"mA\"\n",
+ "print\"Current value of 1 LSB is\",round(I*1000,3),\"microA\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The ladder input current is 2.0 mA\n",
+ "Current value of 1 LSB is 7.813 microA\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.9 Page no 417"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "I=7.812 #Current resolution from ex 14.8\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "Ifs=I*10**-3*255 #From eq. 14-15(a)\n",
+ "#The value of D for part (a),(b),(c)\n",
+ "D1=1 #for digital input 00000001\n",
+ "D2=128\t\t#for digital input 10000000\n",
+ "D3=255\t\t#for digital input 11111111\n",
+ "Iout1=I*D1\n",
+ "Iout2=I*D2\n",
+ "Iout3=I*D3\n",
+ "Iout_1=Ifs-Iout1*10**-3\n",
+ "Iout_2=Ifs-Iout2*10**-3\n",
+ "Iout_3=Ifs-Iout3*10**-3\n",
+ "\n",
+ "#Result\n",
+ "print\"(a) The Iout is\",Iout1,\"mA and Iout_ is\",round(Iout_1,3),\"mA\"\n",
+ "print\"(b) The Iout is\",Iout2,\"mA and Iout_ is\",round(Iout_2,3),\"mA\"\n",
+ "print\"(c) The Iout is\",Iout3,\"mA and Iout_ is\",Iout_3,\"mA\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The Iout is 7.812 mA and Iout_ is 1.984 mA\n",
+ "(b) The Iout is 999.936 mA and Iout_ is 0.992 mA\n",
+ "(c) The Iout is 1992.06 mA and Iout_ is 0.0 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.10 Page no 417"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "#From fig 14.8 (a)\n",
+ "Vref=10 #V\n",
+ "Rf=5\t\t#kohm\n",
+ "Rref=5.0\t\t#kohm\n",
+ "n=8\t\t#\n",
+ "\n",
+ "#Calculation\n",
+ "VR=Vref*Rf/(Rref*2**n)\n",
+ "D1=1\t\t#Value of D for 00000001\n",
+ "D2=255\t\t#Value of D for 11111111\n",
+ "Vo1=VR*1000*D1\n",
+ "Vo2=VR*1000*D2\n",
+ "\n",
+ "#Result\n",
+ "print\"(a) Vo is \",round(Vo1,0),\"V\"\n",
+ "print\"(b) Vo is \",round(Vo2/1000,3),\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) Vo is 39.0 V\n",
+ "(b) Vo is 9.961 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 43
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.11 Page no 418"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "#From fig 14.9(a)\n",
+ "I=8 #microA, value of 1 LSB\n",
+ "Rf=5\t\t# kohm\n",
+ "\n",
+ "#Calculation\n",
+ "#from eq 14-15(a)\n",
+ "Ifs=I*10**-3*255\n",
+ "D1=0 \t\t#Value of D for 00000000\n",
+ "Iout1=I*D1\n",
+ "Iout_1=Ifs-Iout1\n",
+ "Vo1=(Iout1-Iout_1)*Rf\n",
+ "\n",
+ "D2=127 #From digital value(b)\n",
+ "Iout2=I*D2\n",
+ "Iout_2=Ifs-Iout2/1000.0\n",
+ "Vo2=(Iout2/1000.0-Iout_2)*Rf\n",
+ "\n",
+ "D3=128 \t\t#Value of D for 00000000\n",
+ "Iout3=I*D3\n",
+ "Iout_3=Ifs-Iout3/1000.0\n",
+ "Vo3=(Iout3/1000.0-Iout_3)*Rf\n",
+ "\n",
+ "D4=255 \t\t#Value of D for 00000000\n",
+ "Iout4=I*D4\n",
+ "Iout_4=Ifs-Iout4/1000\n",
+ "Vo4=(Iout4/1000-Iout_4)*Rf\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)Vo is \",Vo1,\"V . (b)Vo is \",round(Vo2,3),\"V. (c)Vo is \",Vo3,\"V .(d)Vo is \",round(Vo4,0),\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 2.04\n",
+ "(a)Vo is -10.2 V . (b)Vo is -0.04 V. (c)Vo is 0.04 V .(d)Vo is 10.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C15_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C15_1.ipynb
new file mode 100644
index 00000000..27c99a7a
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C15_1.ipynb
@@ -0,0 +1,321 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 15: Analog to digital converters"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 15.1 Page No 432"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "n=8 \t\t#8 bit ADC\n",
+ "V1=0\t\t#V, input unipolar voltage\n",
+ "V2=10\t\t#V\n",
+ "Vi=5.2 \t#V, applied input voltage\n",
+ "\n",
+ "#calculation\n",
+ "LSB=V2*1000/(2**n)\n",
+ "Vifs=V2-LSB*10**-3\n",
+ "D=Vi/LSB*10**3\n",
+ "binary=10000101\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)The minimum input voltage is\",LSB,\"mV\"\n",
+ "print\"(b)Input voltage that will cause all 1s at ADC's output\",Vifs,\"V\"\n",
+ "print\"(c)The No of LSB's are \",round(D,0),\"So The digital output code is\",binary\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The minimum input voltage is 39 mV\n",
+ "(b)Input voltage that will cause all 1s at ADC's output 9.961 V\n",
+ "(c)The No of LSB's are 133.0 So The digital output code is 10000101\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 15.2 Page No 434"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given (from example 15.1)\n",
+ "n=8 \t\t#8 bit ADC\n",
+ "FSR=10\t\t#V\n",
+ "LSB=39.1 #mA, from ex. 15.1\n",
+ "\n",
+ "#Calculation\n",
+ "Vifs=FSR*10**3-LSB+LSB/2.0\n",
+ "\n",
+ "#Result\n",
+ "print\"The voltahe is\",Vifs/1000,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The voltahe is 9.98045 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 15.3 Page No 435"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "error=0.5 #percent\n",
+ "FSR=10\t\t#V\n",
+ "Vifs=9.961 #From ex 15.1 (c)\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "V=FSR*error/100.0\n",
+ "Vin=Vifs-V*10**-3\n",
+ "\n",
+ "#result\n",
+ "print\"The required voltage is\",round(Vin,2),\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The required voltage is 9.96 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 15.4 Page No 438"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vin1=100 #mV, input voltage\n",
+ "Vin2=200 #mV, input voltage\n",
+ "\n",
+ "#Calculation\n",
+ "T2=0.833*Vin1 #From eq 15.6(b)\n",
+ "T2_=0.833*Vin2\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)The required tome is\",T2,\"ms\"\n",
+ "print\"(b)The required tome is\",T2_,\"ms\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)The required tome is 83.3 ms\n",
+ "(b)The required tome is 166.6 ms\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 15.5 Page No 439"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vin=100 #mV\n",
+ "\n",
+ "#Calculation\n",
+ "Vo=10*Vin #From eq 15.7(c)\n",
+ "\n",
+ "#Result\n",
+ "print\"The digital output is\",Vo,\"counts \"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The digital output is 1000 counts \n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 15.6 Page No 442"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "n=8 \t\t#Bit\n",
+ "t=1 #micros, time for 1 clock pulse\n",
+ "\n",
+ "#Calcultion\n",
+ "Tc=t*(n+1)\n",
+ "\n",
+ "#Result\n",
+ "print\"The required time is\",Tc,\"microsecond\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The required time is 9 microsecond\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 15.7 Page No 450"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "n=8 \t\t#8 bit ADC\n",
+ "t=10 \t\t#micros, conversion time\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "fmax=1/(2*math.pi*2**n*t*10**-6)\n",
+ "\n",
+ "#Result\n",
+ "print\"The maximum frequency is\",round(fmax,0),\"Hz\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum frequency is 62.0 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 15.8 Page No 451"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "t=50 \t\t#ns, aperture time\n",
+ "n=8\n",
+ "error=1 #LSB\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "fmax=1/(2*math.pi*2**n*t*10**-9)\n",
+ "\n",
+ "#Result\n",
+ "print\"The maximum frequency is\",round(fmax/1000,1),\"Hz\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum frequency is 12.4 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C16_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C16_1.ipynb
new file mode 100644
index 00000000..6ba96200
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C16_1.ipynb
@@ -0,0 +1,344 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 16:Power Supplies"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 16.1 Page No 455"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "#from fig. 16.1\n",
+ "Erms=24 #V, rms voltage\n",
+ "\n",
+ "#Calculation\n",
+ "Em=1.4*Erms\n",
+ "\n",
+ "#Result\n",
+ "print\"The maximum instantaneous voltage is\",round(Em,0),\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum instantaneous voltage is 34.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 16.2 Page No 460"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "#From fig 16.4 and 16.5\n",
+ "#at no load\n",
+ "Ilnl=0 #A, load current\t\t\n",
+ "Vdcnl=34\t#V\n",
+ "Ilfl=1 #A, at full load\n",
+ "Vdcfl=24 #V\t\n",
+ "Il=0.5 \n",
+ "\n",
+ "#Calculation\n",
+ "Ro=(Vdcnl-Vdcfl)/(Ilfl)\n",
+ "Vdc=Vdcnl-Il*Ro\n",
+ "\n",
+ "#result\n",
+ "print\"Th output resistance is\",Ro,\"ohm\"\n",
+ "print\"The dc output voltage is\",Vdc,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Th output resistance is 10 ohm\n",
+ "The dc output voltage is 29.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 16.3 Page No 461"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#GIven\n",
+ "Vdcnl=34\t#V, at no load\n",
+ "Ilfl=1 #A, at full load\n",
+ "Vdcfl=24 #V, at full load\n",
+ "\n",
+ "#Calculation\n",
+ "regu=(Vdcnl-Vdcfl)*100/Vdcfl\n",
+ "\n",
+ "#Result\n",
+ "print\"Thepercent regulation is\",round(regu,1),\"percent\"\t\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Thepercent regulation is 41.0 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 16.4 Page No 463"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "If=1 #A, full load current\n",
+ "Vf=24 #V full load voltage\n",
+ "C=1000 \t\t#microF , capacitance\n",
+ "\n",
+ "#Calculation\n",
+ "dvo=If/(200*C**10**-6)\n",
+ "Vrms=dvo/(3.5)\n",
+ "Vlmin=Vf-(round(dvo*1000,0)/2.0)\n",
+ "\n",
+ "#result\n",
+ "print\"(a)peak to peak and rms value of ripple voltage is\",round(dvo*1000,0),\"V and\",round(Vrms*1000,2),\"V\"\n",
+ "print\"(b) The minimum instanttaneous output voltage is\",Vlmin,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)peak to peak and rms value of ripple voltage is 5.0 V and 1.43 V\n",
+ "(b) The minimum instanttaneous output voltage is 21.5 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 16.5 Page No 463"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "#from example 16.4\n",
+ "Vf=24.0 #V\n",
+ "Vrms=1.43 #V\n",
+ "\n",
+ "#Calculation\n",
+ "ripple=Vrms/Vf*100\n",
+ "\n",
+ "#result\n",
+ "print\"The percentage ripple is\",round(ripple,0),\"percent\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The percentage ripple is 6.0 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 16.6 Page No 464"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vdcfl=12.0 #V, voltage\n",
+ "Ilfl=1.0 #A current\n",
+ "ripp=10.0 #percent, ripple\n",
+ "Ro=10.0 #ohm, guess value\n",
+ "\n",
+ "\n",
+ "#calculation\n",
+ "#DC design procedure\n",
+ "#from eq 16.3(a)\n",
+ "Vdcnl=Vdcfl+Ilfl*Ro\n",
+ "Em=Vdcnl\n",
+ "Erms=Em/1.4\n",
+ "#For a FWB rectifier\n",
+ "Isec=1.8*Ilfl\n",
+ "PIV=Vdcnl+(20/100.0)*Vdcnl\n",
+ "\n",
+ "#AC design procedure\n",
+ "Vrms=(ripp/100.0)*Vdcfl\n",
+ "dvo=3.5*Vrms #From eq 16.5 (b)\n",
+ "C=Ilfl/(200*dvo)\n",
+ "WVDC=Vdcnl+(20/100.0)*Vdcnl\n",
+ "\n",
+ "#result\n",
+ "print\" Transformer at :115V/18V at \",round(Isec,0),\"A\"\n",
+ "print\"Four diodes :each 1 A at PIV\",PIV,\"V (or more)\"\n",
+ "print\"THree capacitors: 500 muF connected in parallel,WVDC=\",WVDC,\"V (or more)\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Transformer at :115V/18V at 2.0 A\n",
+ "Four diodes :each 1 A at PIV 26.4 V (or more)\n",
+ "THree capacitors: 500 muF connected in parallel,WVDC= 26.4 V (or more)\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Analysis Example 16.7 Page No 466"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ro=7\t\t#ohm\n",
+ "Ilfl=1\t\t#A, \n",
+ "C=1000 #microF\n",
+ "\n",
+ "#Calculation\n",
+ "Erms=1.8*Vrms\n",
+ "Em=1.4*Erms\n",
+ "Vdcnl=Em\n",
+ "Vdcfl=Vdcnl-Ilfl*Ro\n",
+ "reg=(Vdcnl-Vdcfl)*100/Vdcfl \n",
+ "\n",
+ "dvo=(Ilfl/200*C*10**-6)\n",
+ "Vrms=dvo/3.5\n",
+ "rip=Vrms*100/Vdcfl\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)Vdcfl is\",Vdcfl,\"V and percentag eregulation is\",round(reg,0)\n",
+ "print\"(b)percentage ripple is\",round(rip,1)\n",
+ "\n",
+ "#Plot\n",
+ "I=[0,5,10]\n",
+ "VdcNL=[26,22,18.5]\n",
+ "a1=plot(I,VdcNL)\n",
+ "show(a1)\n",
+ "\n",
+ "t1=[0,16.7]\n",
+ "Vdcnl=[26,26]\n",
+ "t2=[0,2,8.34,10.34,16.7]\n",
+ "Vdcfl=[16,21,16,21.5,16]\n",
+ "a2=plot(t1,Vdcnl)\n",
+ "a3=plot(t2,Vdcfl)\n",
+ "show(a2)\n",
+ "show(a3)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)Vdcfl is -7.0 V and percentag eregulation is -100.0\n",
+ "(b)percentage ripple is -0.0\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAEACAYAAACuzv3DAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGbZJREFUeJzt3X1wVPW9x/HPAvEWXRTDQ0IJDgyKbDaEjQGjvRI2QpwJ\nE5gIGRFHRRLpTCtKKmqfs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jzjvvNJqbm80uyTQVFRVGamqqkZaWZtx/\n//3GuXPnzC6pz9x9993GiBEjjISEBCMlJcVYs2aNceLECWPatGnGDTfcYOTm5hqnTp3q9jicEAQA\nFhff4wMAEANo5ABgcTRyALA4GjkAWByNHAAsjkYOABZHIwcAi6ORA4DF/T+aRJA0b7FFuwAAAABJ\nRU5ErkJggg==\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x75605c0>"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAEACAYAAACuzv3DAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XtUVPXeBvBnhmuKV0RQMEURQ1BAE8yjCAJCqMRFUVBA\nsVwnz8ksU/PU++o55a0yL6eLp1OGiOY9mUEkuThgenyxo1nmCbyAIV5TUEENkP3+4StvInKdmd/s\n4fmsxVo6MHs/yzXzuPnO3vunkCRJAhERyZZSdAAiImodFjkRkcyxyImIZI5FTkQkcyxyIiKZY5ET\nEclcg0VeXFwMPz8/uLq6ws3NDevWrav93t///ne4uLjAzc0NCxcu1HlQIiKqn2lD3zQzM8Pq1avh\n4eGB8vJyDB06FIGBgbh8+TJUKhV++OEHmJmZ4dq1a/rKS0REdTRY5HZ2drCzswMAWFlZwcXFBSUl\nJfjnP/+JRYsWwczMDABgY2Oj+6RERFSvJs/Ii4qKcPz4cXh7e6OgoAC5ubkYPnw4fH198d133+ky\nIxERNaDBI/KHysvLMXHiRKxduxYdOnRAdXU1SktLceTIERw9ehRRUVE4d+6crrMSEVE9Gi3yqqoq\nREZGYtq0aQgLCwMAODg4ICIiAgAwbNgwKJVKXL9+HdbW1o88V6FwAnBW+6mJiIxUv379cObMmWY9\np8HRiiRJmDlzJgYOHIi5c+fWPh4WFobs7GwAQEFBASorKx8r8QfOQpIkg/pavHix8AzMZDyZDDUX\nM8k309mzzT/4bfCI/NChQ0hOTsbgwYPh6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ZIkaeXKldLAgQMl\nNzc3KS4urvYsA32aMmWK1KNHD8nMzExycHCQNmzYIF2/fl3y9/eX+vfvLwUGBkqlpaVCM33xxReS\nk5OT9PTTT9e+1l9++WUhmczNzWv/nX7P0dFRyFkr9eWqrKyUpk2bJrm5uUlDhgyRDhw4ICTT719T\nR48elby8vCR3d3dp+PDh0rFjxxrdDi8IIiKSOcM5XYKIiFqERU5EJHMsciIimWORExHJHIuciEjm\nWORERDLHIicikjkWORGRzP0vdswUY8DlrCUAAAAASUVORK5CYII=\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x7533ba8>"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C2_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C2_1.ipynb
new file mode 100644
index 00000000..c91c71a1
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C2_1.ipynb
@@ -0,0 +1,212 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2:First Experiences with Op Amp"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 2.1 Page No 19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vplus=15\n",
+ "Vminus=-15\n",
+ "Vsatp=13\n",
+ "Vsatm=-13 #All in Volts\n",
+ "Aol=200000.0 #gain\n",
+ "#Example 2-1(a)\n",
+ "Vam=-10*(10**-6) #voltage at minus input\n",
+ "Vap=-15*(10**-6) #voltage at plus input\n",
+ "Ed1=Vap-Vam #Differential Input Voltage\n",
+ "Vout1=Ed1*Aol #Output Voltage\n",
+ "if Vout1>15:\n",
+ " print\"Value of o/p voltage1 = 13.0000V\" #positive saturation voltage\n",
+ "elif(Vout1<-15):\n",
+ " print\"Value of o/p voltage1 = -13.0000V\" #negative saturation voltage\n",
+ "else:\n",
+ " print\" Value of o/p voltage1 = \",Vout1*Vsatp,\"V\"\n",
+ "\n",
+ "#Example 2-1(b)\n",
+ "Vbm=-10*(10**-6) #voltage at minus input\n",
+ "Vbp=+15*(10**-6) #voltage at plus input\n",
+ "Ed2=Vbp-Vbm #Differential Input Voltage\n",
+ "Vout2=Ed2*Aol #Output Voltage\n",
+ "if Vout2>15:\n",
+ " print\"Value of o/p voltage2 = 13.0000V\" #positive saturation voltage\n",
+ "elif(Vout2<-15):\n",
+ " print\"Value of o/p voltage2 = -13.0000V\" #negative saturation voltage\n",
+ "else:\n",
+ " print\" Value of o/p voltage2 = \",Vout2,\"V\"\n",
+ "\n",
+ "#Example 2-1(c)\n",
+ "Vcm=-10*(10**-6) #voltage at minus input\n",
+ "Vcp=-5*(10**-6) #voltage at plus input\n",
+ "Ed3=Vcp-Vcm #Differential Input Voltage\n",
+ "Vout3=Ed3*Aol #Output Voltage\n",
+ "if(Vout3>15):\n",
+ " print\"Value of o/p voltage3 = 13.0000V\" #positive saturation voltage\n",
+ "elif(Vout3<-15):\n",
+ " print\"Value of o/p voltage3 = -13.0000V\" #negative saturation voltage\n",
+ "else:\n",
+ " print\" Value of o/p voltage3 = \",Vout3,\"V\"\n",
+ "\n",
+ "\n",
+ "#Example 2-1(d)\n",
+ "Vdm=+1.000001 #voltage at minus input\n",
+ "Vdp=+1.000000 #voltage at plus input\n",
+ "Ed4=Vdp-Vdm #Differential Input Voltage\n",
+ "Vout4=Ed4*Aol #Output Voltage\n",
+ "if(Vout4>15):\n",
+ " print\"Value of o/p voltage4 = 13.0000V\" #positive saturation voltage\n",
+ "elif(Vout4<-15):\n",
+ " print\"Value of o/p voltage4 = -13.0000V\" #negative saturation voltage\n",
+ "else:\n",
+ " print\" Value of o/p voltage4 = \",round(Vout4,2),\"V\"\n",
+ "\n",
+ "\n",
+ "#Example 2-1(e)\n",
+ "Vem=+5*(10**-3) #voltage at minus input\n",
+ "Vep=0 #voltage at plus input\n",
+ "Ed5=Vep-Vem #Differential Input Voltage\n",
+ "Vout5=Ed5*Aol #Output Voltage\n",
+ "if(Vout5>15):\n",
+ " print\"Value of o/p voltage5 = 13.0000V\" #positive saturation voltage\n",
+ "elif(Vout5<-15):\n",
+ " print\"Value of o/p voltage5 = -13.0000V\" #negative saturation voltage\n",
+ "else:\n",
+ " print\" Value of o/p voltage5 = \",Vout5\n",
+ "\n",
+ "#Example 2-1(f)\n",
+ "Vfm=0 #voltage at minus input\n",
+ "Vfp=+5*(10**-3) #voltage at plus input\n",
+ "Ed6=Vfp-Vfm #Differential Input Voltage\n",
+ "Vout6=Ed6*Aol #Output Voltage\n",
+ "if(Vout6>15):\n",
+ " print\"Value of o/p voltage6 = 13.0000V\" #positive saturation voltage\n",
+ "elif(Vout6<-15):\n",
+ " print\"Value of o/p voltage6 = -13.0000V\" #negative saturation voltage\n",
+ "else:\n",
+ " print\" Value of o/p voltage6 = V \",Vout6\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of o/p voltage1 = -13.0 V\n",
+ " Value of o/p voltage2 = 5.0 V\n",
+ " Value of o/p voltage3 = 1.0 V\n",
+ " Value of o/p voltage4 = -0.2 V\n",
+ "Value of o/p voltage5 = -13.0000V\n",
+ "Value of o/p voltage6 = 13.0000V\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 2.2 Page No 35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "f=50.0 #in Hz\n",
+ "Vtemp=4.0 #input signal in volts\n",
+ "Ecm=10.0 \n",
+ "\n",
+ "#Calculation\n",
+ "#Example 2-2(a)\n",
+ "T=1/f\n",
+ "Th=(Vtemp*T)/Ecm #High time in seconds\n",
+ "\n",
+ "#Example 2-2(b)\n",
+ "d=(Th/T)*100 #duty cycle in percentage\n",
+ "\n",
+ "#Result\n",
+ "print\" High Time is \",Th*1000,\"ms\"\n",
+ "print\" Duty cycle is\",d,\"percent\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " High Time is 8.0 ms\n",
+ " Duty cycle is 40.0 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 2.3 Page No 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vtemp=4.0 #in volts\n",
+ "Ecm=5.0 #maximum peak voltage of a sawtooth carrier wave\n",
+ "T=0.01 #in seconds\n",
+ "\n",
+ "#calculation\n",
+ "Th=T*(1-(Vtemp/Ecm)) #High Time\n",
+ "\n",
+ "#Result\n",
+ "print\" High Time is \",Th*1000,\"ms\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " High Time is 2.0 ms\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C3_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C3_1.ipynb
new file mode 100644
index 00000000..e799a9b7
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C3_1.ipynb
@@ -0,0 +1,555 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3: Inverting and Non Inverting Amplifiers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.1 Page No 47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Rf=100*(10**3) #Feedback Resistance in ohms\n",
+ "Ri=10*(10**3) #Input Resistance in ohms\n",
+ "Ei=1.0 #Input volts\n",
+ "\n",
+ "#Calculation \n",
+ "I=Ei/Ri #Equation for current through Rf\n",
+ "Vout=-(Rf/Ri)*Ei #Equation for Output Voltage\n",
+ "Acl=-(Rf/Ri) #Closed loop gain of the amplifier \n",
+ "\n",
+ "#Result\n",
+ "print\"(a) Current through Rf is\",I*1000,\"mA\"\n",
+ "print\"(b) Value of output voltage is \",Vout,\"V\"\n",
+ "print\"(c) Value of closed loop gain is\",Acl"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) Current through Rf is 0.1 mA\n",
+ "(b) Value of output voltage is -10.0 V\n",
+ "(c) Value of closed loop gain is -10\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.2 Page No 47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vout=10.0 #output voltage\n",
+ "I=0.1*(10**-3) #current through Rf in amperes\n",
+ "Rl=25*(10**3) #Load resistance in ohms\n",
+ "\n",
+ "#Calculation\n",
+ "Il=Vout/Rl\n",
+ "Iout=I+Il\n",
+ "\n",
+ "#Result\n",
+ "print\"(a) Value of load current is\",Il*1000,\"m\"\n",
+ "print\"(b) Total current into the output pin of the opamp is \",Iout*1000,\"mA\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) Value of load current is 0.4 m\n",
+ "(b) Total current into the output pin of the opamp is 0.5 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.3 Page No 49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Rf=250*(10**3)#Feedback Resistance in Ohms\n",
+ "Ri=10*(10**3)#Input Resistance in Ohms\n",
+ "Ei=0.5#Input voltage\n",
+ "\n",
+ "#Calculation\n",
+ "I=Ei/(Ri)\n",
+ "VRf=I*Rf\n",
+ "Ei1=-0.5\n",
+ "Vout=-(Rf/Ri)*Ei1\n",
+ "\n",
+ "#Result\n",
+ "print\"(a) Value of current through Rf is\",I,\"A\"\n",
+ "print\"(b) Voltage through Rf is \",VRf,\"V\"\n",
+ "print\"(c) Output Voltage is\",Vout,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) Value of current through Rf is 5e-05 A\n",
+ "(b) Voltage through Rf is 12.5 V\n",
+ "(c) Output Voltage is 12.5 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.4 Page No 49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vout=12.5 #in volts\n",
+ "Il=2*10**-3 #in amperes\n",
+ "\n",
+ "#Calculation\n",
+ "Rl=Vout/Il #Load resistance in ohm\n",
+ "I=0.05*10**-3\n",
+ "Iout=I+Il\n",
+ "\n",
+ "#Result\n",
+ "print\"(a) Value of Load Resistance is\",Rl/1000,\"kohm\"\n",
+ "print\"(b) Value of output current is \",Iout*1000,\"mA\"\n",
+ "print\"(c)The circuit input resistance is Rl=10Kohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) Value of Load Resistance is 6.25 kohm\n",
+ "(b) Value of output current is 2.05 mA\n",
+ "(c)The circuit input resistance is Rl=10Kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.5 Page No 50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Rf=20*10**3\n",
+ "Ri=10*10**3\n",
+ "\n",
+ "#calculation\n",
+ "Acl=-(Rf/Ri) #Voltage Gain\n",
+ "\n",
+ "#Result\n",
+ "print\" Value of Voltage Gain is\",Acl"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of Voltage Gain is -2\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.6 Page No 51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ei=-5 #input voltage\n",
+ "Acl=-2 #Voltage Gain\n",
+ "\n",
+ "#Calculation\n",
+ "Vout=Ei*Acl #output voltage\n",
+ "\n",
+ "#Result\n",
+ "print\" Value of Output Voltage is\",Vout,\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of Output Voltage is 10 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.7 Page No :51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ri=10*10**3 #input resistance in ohm\n",
+ "Gain= 25\n",
+ "\n",
+ "#Calculation\n",
+ "Rf=Gain*Ri #feedback resistance in ohm\n",
+ "\n",
+ "#result\n",
+ "print\" Value of Rf is\",Rf/1000,\"kohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of Rf is 250 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.8 Page No 52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "E1=2\n",
+ "E2=3\n",
+ "E3=1 #input voltage\n",
+ "R=10*10**3 #in ohm\n",
+ "\n",
+ "#calculation\n",
+ "Vout=-(E1+E2+E3)\n",
+ "\n",
+ "#result\n",
+ "print\" Value of o/p voltage is \",Vout,\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of o/p voltage is -6 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.9 Page No 53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "E1=2.0\n",
+ "E2=3.0\n",
+ "E3=-1.0 #input voltage\n",
+ "R=10*10**3 #in ohm\n",
+ "\n",
+ "#Calculation\n",
+ "Vout=-(E1+E2+E3)\n",
+ "\n",
+ "#result\n",
+ "print\" Value of o/p voltage is\",Vout"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of o/p voltage is -4.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.11 Page No 56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "#Channel 1\n",
+ "Ri= 10*10**3 #Choosing Input resistance\n",
+ "Acl = -10.0 \n",
+ "\n",
+ "#Calculation\n",
+ "Rf1 = - (Acl * Ri)\n",
+ "#Channel 2\n",
+ "Acl1 = -5\n",
+ "Rf2 = - (Acl1 * Ri)\n",
+ "#channel 3\n",
+ "Acl2 = -2\n",
+ "Rf3 = - (Acl2 * Ri)\n",
+ "\n",
+ "#result\n",
+ "print\" Value of Rf1 = \",Rf1/1000,\"kohm\"\n",
+ "print\" Value of Rf2 = \",Rf2/1000,\"kohm\"\n",
+ "print\" Value of Rf3 = \",Rf3/1000,\"kohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of Rf1 = 100.0 kohm\n",
+ " Value of Rf2 = 50 kohm\n",
+ " Value of Rf3 = 20 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.12 Page No 57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "R1=100000.0\n",
+ "R2=100000.0\n",
+ "R3=100000.0\n",
+ "R=100000.0 #in ohm\n",
+ "Rf=33*10**3 #in ohm\n",
+ "E1=5\n",
+ "E2=5\n",
+ "E3=-1 #in volts\n",
+ "n=3.0 #number of inputs\n",
+ "\n",
+ "#Calculation\n",
+ "Vout=-(E1+E2+E3)/n #output voltage\n",
+ "\n",
+ "#Result\n",
+ "print\" Value of output voltage is\",Vout,\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of output voltage is -3.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.13 Page No 59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Rf = 40*10**3\n",
+ "R1 = 10*10**3\n",
+ "\n",
+ "#calculation\n",
+ "Acl = (Rf + R1)/R1\n",
+ "print\"(a) Value of Voltage Gain = \",Acl\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) Value of Voltage Gain = 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.14 Page No 59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given \n",
+ "Acl = 10.0 # Gain is positive, so choose noninvering amplifier\n",
+ "R1 = 10*10**3\n",
+ "\n",
+ "#Calculation\n",
+ "Rf = (Acl*R1)-R1\n",
+ "\n",
+ "#Result\n",
+ "print\" Value of Rf is\",Rf/1000,\"kohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 3.15 Page No 62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ei=4.0 #in volts\n",
+ "Rl=10*10**3 #in ohm\n",
+ "I=0 #in ampere\n",
+ "\n",
+ "#Calculation\n",
+ "Vout=Ei #output voltage\n",
+ "Il=Vout/Rl #load current\n",
+ "I0=I+Il #output current \n",
+ "\n",
+ "#Result\n",
+ "print\" Value of o/p voltage is\",Vout,\"V\"\n",
+ "print\" Value of load current is \",Il*1000,\"mA\"\n",
+ "print\" Value of output current is \",I0*1000,\"mA\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of o/p voltage is 4.0 V\n",
+ " Value of load current is 0.4 mA\n",
+ " Value of output current is 0.4 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C4_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C4_1.ipynb
new file mode 100644
index 00000000..7fb262ec
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C4_1.ipynb
@@ -0,0 +1,236 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4: Comparators and Controls"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 4.1 Page No 88"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vsat = 14.0 #Saturation Voltage\n",
+ "R1 = 1000.0 \n",
+ "R2 = 100.0 #Load resistances\n",
+ "\n",
+ "#Calculation\n",
+ "Vut = (R2/(R1*R2))*Vsat\n",
+ "\n",
+ "#Result\n",
+ "print\" Value of Upper Threshold Voltage = \",Vut*1000,\"mV\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of Upper Threshold Voltage = 14.0 mV\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 4.2 Page No 88"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vsat = -13.0 #Saturation Voltage\n",
+ "R1 = 1000.0\n",
+ "R2 = 100.0 #Load resistances\n",
+ "\n",
+ "#Calculation\n",
+ "Vlt = (R2/(R1*R2))*Vsat\n",
+ "\n",
+ "#Result\n",
+ "print\" Value of Lower Threshold Voltage = \",Vlt*1000,\"mV\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of Lower Threshold Voltage = -13.0 mV\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 4.4 Page No 94"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vut = 12.0\n",
+ "Vlt = 8.0 #Upper and Lower Threshold Voltages \n",
+ "Vsatp = 15.0\n",
+ "Vsatm = -15.0 # Saturation Voltages\n",
+ "R = 10*10**3 #Choosing R\n",
+ "\n",
+ "#Calculation\n",
+ "Vh = Vut - Vlt # Hysteresis Voltage \n",
+ "Vctr = (Vut + Vlt)/2.0 #Center Voltage\n",
+ "n = (Vsatp - Vsatm)/Vh # Resistor Factor\n",
+ "Vref = Vctr / (1 + (1/n)) #Reference Voltage\n",
+ "Resistance = n * R\n",
+ "\n",
+ "#Result\n",
+ "print\" Center Voltage = \", Vctr ,\"V\"\n",
+ "print\" Resistor Factor = \" , n \n",
+ "print\" Reference Voltage = \", round(Vref,2)\n",
+ "print\" Feedback resistor is \", Resistance"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Center Voltage = 10.0 V\n",
+ " Resistor Factor = 7.5\n",
+ " Reference Voltage = 8.82\n",
+ " Feedback resistor is 75000.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 4.5 Page No 95"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vsatp = 15.0\n",
+ "Vsatm = -15.0 # Saturation Voltages\n",
+ "Vh = 4.0 #Hysteresis Voltage\n",
+ "Vctr = 10.0 #Center voltage\n",
+ "\n",
+ "#Calculation\n",
+ "n = ((Vsatp - Vsatm)/Vh)-1 \n",
+ "R = 10*10**3 #Input Resistance\n",
+ "Vref = ((n + 1)*(Vctr))/n # Reference Voltage\n",
+ "Resistance = n * R # Feedback Resistance\n",
+ "\n",
+ "#Result\n",
+ "print\" Resistance Factor = \", n\n",
+ "print\" Reference Voltage = \", round(Vref,2),\"V\"\n",
+ "print\" Feedback Resistance = \", Resistance/1000,\"kohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Resistance Factor = 6.5\n",
+ " Reference Voltage = 11.54 V\n",
+ " Feedback Resistance = 65.0 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 4.6 Page No 98"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vut = 13.5\n",
+ "Vlt = 10.5 #Upper and Lower Threshold Voltages\n",
+ "Vref = -15 # Reference Voltage\n",
+ "Vsatp = 13.0\n",
+ "Vsatm = -13.0 #Saturation Voltages \n",
+ "R = 10*10**3 # Input Resistance\n",
+ "\n",
+ "#Calculation\n",
+ "Vctr = (Vut + Vlt)/2.0\n",
+ "Vh = Vut - Vlt \n",
+ "m = -(Vref / Vctr)\n",
+ "Resistance = m * R \n",
+ "n = (Vsatp-Vsatm)/Vh \n",
+ "Resistance1 = n * R \n",
+ "\n",
+ "#Result\n",
+ "print\" Hysteresis Voltage = \", Vh \n",
+ "print\" Center Voltage = \", Vctr \n",
+ "print\" Resistor mR = \", Resistance/1000,\"kohm\"\n",
+ "print\" Resistor nR = \", round(Resistance1/1000,2),\"kohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Hysteresis Voltage = 3.0\n",
+ " Center Voltage = 12.0\n",
+ " Resistor mR = 12.5 kohm\n",
+ " Resistor nR = 86.67 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C5_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C5_1.ipynb
new file mode 100644
index 00000000..e04d327d
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C5_1.ipynb
@@ -0,0 +1,733 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5 :Selected applications of Op Amps"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.1 Page No 120"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ei = 0.5 #Input voltage\n",
+ "Ri = 1*10**3 #Input resistance in ohm\n",
+ "\n",
+ "#Calculation\n",
+ "Im = Ei / Ri #Meter Current\n",
+ "\n",
+ "#Result\n",
+ "print\"Meter Current = \", Im*1000,\"mA\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Meter Current = 0.5 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.2 Page No 120"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Efs = 5.0 #Full scale Voltage\n",
+ "Ifs = 50*10**-6 #Full scale Meter Current\n",
+ "#Calculation\n",
+ "Ri = Efs / Ifs # Input Resistance\n",
+ "\n",
+ "#Result\n",
+ "print\" Input Resistance =\", Ri/1000,\"Kohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Input Resistance = 100.0 Kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.3 Page No 122"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Edc = 5.0\n",
+ "Erms = 5.0\n",
+ "Epeak = 5.0\n",
+ "Eptop = 5.0 # Voltages of meters \n",
+ "Ifs = 50*10**-6 # Full scale Meter Current\n",
+ "\n",
+ "#Calculation\n",
+ "Ri1 = Edc / Ifs # DC Voltmeter\n",
+ "Ri2 = 0.90 * (Erms / Ifs ) # Rms ac voltmeter ( math.sine wave only )\n",
+ "Ri3 = 0.636 * (Epeak / Ifs ) #Peak Reading Voltmeter ( math.sine wave only )\n",
+ "Ri4 = 0.318 * (Eptop / Ifs ) #Peak-to-Peak ac Voltmeter(math.sine wave only)\n",
+ "\n",
+ "#Result\n",
+ "print\" Ri1 \", Ri1/1000,\"kohm\"\n",
+ "print\" Ri2 =\",Ri2/1000 ,\"kohm\"\n",
+ "print\" Ri3 = \", Ri3/1000,\"kohm\"\n",
+ "print\" Ri4 = \", Ri4/1000,\"kohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Ri1 100.0 kohm\n",
+ " Ri2 = 90.0 kohm\n",
+ " Ri3 = 63.6 kohm\n",
+ " Ri4 = 31.8 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.4 Page No 123"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vo = 10.3 #Voltage across the load resistor\n",
+ "Ei = 5.0 #Input voltage\n",
+ "Ri = 1*10**3 #Input Resistance\n",
+ "\n",
+ "#calculation\n",
+ "I = Ei / Ri #Zener Current\n",
+ "Vt = Vo - Ei #Zener Voltage\n",
+ "\n",
+ "#Result\n",
+ "print\" Zener Current = \", I,\"A\"\n",
+ "print\" Zener Voltage = \", Vt ,\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Zener Current = 0.005 A\n",
+ " Zener Voltage = 5.3 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.5 Page No 124"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ei = 1.0 #Reference voltage\n",
+ "Ri = 1*10**3 #Input Resistance\n",
+ "Vo = 0.6 #Outpur Voltage\n",
+ "\n",
+ "#Calculation\n",
+ "I = Ei / Ri #Diode Current\n",
+ "Vdiode = Vo \n",
+ "\n",
+ "#Result\n",
+ "print\" Diode Current = \", I*1000 ,\"mA\"\n",
+ "print\" Voltage drop across the diode = \", Vdiode,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Diode Current = 1.0 mA\n",
+ " Voltage drop across the diode = 0.6 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.6 Page No 127"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "R = 10*10**3 #Resistance\n",
+ "E2 = 0 #Source across negative terminal\n",
+ "Rl = 5*10**3 # Load Resistance\n",
+ "E1 = 5.0 # source across positive terminal\n",
+ "\n",
+ "#calculation\n",
+ "Il = (E1 - E2)/R #Load Current\n",
+ "Vl = Il * Rl # Voltage across Rl \n",
+ "Vo = (2*Vl)-E2 #Output voltage\n",
+ "\n",
+ "#Result\n",
+ "print\"(a) Load current across Rl = \" , Il*1000 ,\"mA\"\n",
+ "print\"(b) Voltage across load resistance = \" , Vl,\"V\"\n",
+ "print\"(c) Output Voltage = \", Vo ,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) Load current across Rl = 0.5 mA\n",
+ "(b) Voltage across load resistance = 2.5 V\n",
+ "(c) Output Voltage = 5.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.7 Page No 127"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "R = 10*10**3 #Resistance\n",
+ "E2 = 5.0 #Source across negative terminal\n",
+ "Rl = 5*10**3 # Load Resistance\n",
+ "E1 = 0 # source across positive terminal\n",
+ "\n",
+ "#Calculation\n",
+ "Il = (E1 - E2)/R #Load Current\n",
+ "Vl = Il * Rl # Voltage across Rl \n",
+ "Vo = (2*Vl)-E2 #Output voltage\n",
+ "\n",
+ "#Result\n",
+ "print\"(a) Load current across Rl = \" , Il*1000,\"mA\"\n",
+ "print\"(b) Voltage across load resistance = \" , Vl,\"V\"\n",
+ "print \"(c) Output Voltage = \", Vo ,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) Load current across Rl = -0.5 mA\n",
+ "(b) Voltage across load resistance = -2.5 V\n",
+ "(c) Output Voltage = -10.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.8 Page No 132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vo = 5.0 #Output Voltage\n",
+ "Rf = 100*10**3 #Feedback Resistance\n",
+ "\n",
+ "#calculation\n",
+ "Isc = Vo / Rf #Short Circuit Current\n",
+ "\n",
+ "#Result\n",
+ "print\" Short Circuit Current = \" , Isc*10**6,\"microA\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Short Circuit Current = 50.0 microA\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.9 Page No 132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given \n",
+ "Rf = 10*10**3 #Feedback Resistance\n",
+ "I = 10*10**-6 #Current through Photo Detector\n",
+ "\n",
+ "#calculation\n",
+ "Vo = Rf * I #Vo for Dark Condition\n",
+ "I1 = 1*10**-3 #Current in presence of sunlight\n",
+ "Vo1 = Rf * I1 #output voltage in light condition\n",
+ "\n",
+ "#Result\n",
+ "print\"(a)Output Voltage for dark Condition = \", Vo,\"V\"\n",
+ "print\"(b) Output voltage in light condition = \", Vo1,\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)Output Voltage for dark Condition = 0.1 V\n",
+ "(b) Output voltage in light condition = 10.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.10 Page No 133"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Rf = 100*10**3 #Feedback Resistance\n",
+ "Il1 = 1*10**-6 #Load current 1\n",
+ "\n",
+ "#calculation\n",
+ "Vo1 = Rf * Il1 #Output voltage in photo detector\n",
+ "Il2 = 50*10**-6 # Load current 2\n",
+ "Vo2 = Rf * Il2 #Output Voltage in photo detector\n",
+ "\n",
+ "#Result\n",
+ "print\" (a)Output Voltage in photo detector for Il1 = \",Vo1 ,\"V\"\n",
+ "print \" (b)Output Voltage in photo detector for Il2 = \",Vo2 ,\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (a)Output Voltage in photo detector for Il1 = 0.1 V\n",
+ " (b)Output Voltage in photo detector for Il2 = 5.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.11 Page No 134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "R = 1*10**3\n",
+ "R1 = 99*10**3 \n",
+ "\n",
+ "#calculation\n",
+ "m = R1 / R #multiplier\n",
+ "Isc = 10*10**-6 #Current on short-circuit condition\n",
+ "Il = (1 + m)*Isc \n",
+ "\n",
+ "#result\n",
+ "print\" Load current = \", Il*1000,\"mA\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Load current = 1.0 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.12 Page No 136"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Im = 100*10**-6 #Meter current \n",
+ "Isc = 0.5 # Current in short-circuit condition\n",
+ "Rf = 20 # Feedback resistance\n",
+ "Rm = 0.8*10**3 #Meter resistance\n",
+ "\n",
+ "#calculation\n",
+ "d = Isc / Im #Current divider\n",
+ "R1 = d * Rf \n",
+ "Rscale = R1 - Rm \n",
+ "\n",
+ "#Result\n",
+ "print\" Resistance dRf = \", R1/1000 ,\"kohm\"\n",
+ "print\" Rscale = \", Rscale/1000,\"kohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Resistance dRf = 100.0 kohm\n",
+ " Rscale = 99.2 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.13 Page No 138"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "f = 10**3 #Frequency of Ei in Hz\n",
+ "Ci = 0.01*10**-6 \n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "m = math.tan(math.pi/4)\n",
+ "Ri = m / (2*math.pi*f*Ci)\n",
+ "\n",
+ "#result\n",
+ "print\" Value of Ri = \",round(Ri/1000,1),\"kohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of Ri = 15.9 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.14 Page No 138"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "f = 10**3 \n",
+ "Ri = 100*10**3 \n",
+ "Ci = 0.01*10**-6\n",
+ "\n",
+ "#calculation\n",
+ "import math\n",
+ "phaseangle = 2*math.atan(2*math.pi*f*Ri*Ci)\n",
+ "\n",
+ "#result\n",
+ "print\" Phase angle =\", round(phaseangle*180/3.14,2),\"degree\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Phase angle = 162.0 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.15 Page no 143"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "#From fig 5-14(a) and b\n",
+ "Ei=2 #V, voltage\n",
+ "Vf=4 #Vf force\n",
+ "\n",
+ "#Calculation\n",
+ "Vo=-2*Ei #Vo forces\n",
+ "Vcap=3*Ei\n",
+ "\n",
+ "#Result\n",
+ "print\"Vo is\",Vo,\"V\"\n",
+ "print\"Vcap is\",Vcap,\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vo is -4 V\n",
+ "Vcap is 6 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.16 Page no 144"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ei=4 #V\n",
+ "Vo=8 #V\n",
+ "\n",
+ "#Calculation\n",
+ "Vr=-Vo\n",
+ "Vcap=Ei+Vo\n",
+ "\n",
+ "#Result\n",
+ "print\"Vcap is\",Vcap,\"V\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vcap is 12 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.17 Page no 144"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ri=1*10**5\n",
+ "C=10**-6\n",
+ "\n",
+ "#Calculation\n",
+ "T=3*Ri*C\n",
+ "Et=5*T\n",
+ "\n",
+ "#Result\n",
+ "print\"Equilibrium Time is\",Et,\"s\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Equilibrium Time is 1.5 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 5.18 Page no 146"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "Ci=0.1*10**-6 #capacitance, farady\n",
+ "Ci_=0.1 #microF\n",
+ "f=1000 #frequency\n",
+ "#Calculation\n",
+ "import math\n",
+ "Ri=1/(2*math.pi*f*Ci)\n",
+ "Rf=20/(2*math.pi*f*Ci)\n",
+ "Cf=1/(2*math.pi*f*Rf)\n",
+ "#a=0.4*math.sin(2*math.pi*1000*t)\n",
+ "#Vo=-Cf*Ci*a\n",
+ "\n",
+ "from sympy import *\n",
+ "import numpy as np\n",
+ "t = Symbol('t')\n",
+ "y = -Rf*Ci_/10**6*0.4*sin(2*math.pi*1000*t)\n",
+ "y_ = y.diff(t)\n",
+ "\n",
+ "#Reslt\n",
+ "print Ci_\n",
+ "print\"a)Rf is \",round(Rf/1000,1),\"kohm\"\n",
+ "print\"Cf is \",round(Cf*10**6,9),\"microF\"\n",
+ "print\"(b)Output voltage is \",y_,\"V\"\n",
+ "\n",
+ "#NOTE: Answer is same .In the book it is written 2*math.pi*1000 ."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0.1\n",
+ "a)Rf is 31.8 kohm\n",
+ "Cf is 0.005 microF\n",
+ "(b)Output voltage is -8.0*cos(6283.18530717959*t) V\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C6_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C6_1.ipynb
new file mode 100644
index 00000000..7bc13612
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C6_1.ipynb
@@ -0,0 +1,490 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Signal Generators"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.1 Page No 155"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "R1 = 100*10**3 \n",
+ "R2 = 86*10**3 \n",
+ "Vsatp = 15.0\n",
+ "Vsatm = -15.0 #Saturation voltages\n",
+ "\n",
+ "#calculation\n",
+ "Vut = (R2 * Vsatp)/(R1 + R2)\n",
+ "Vlt = (R2 * Vsatm)/(R1 + R2)\n",
+ "\n",
+ "#Result\n",
+ "print\" Upper Threshold Voltage = \",round(Vut,0),\"V\"\n",
+ "print\" Lower Threshold Voltage = \",round(Vlt,0),\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Upper Threshold Voltage = 7.0 V\n",
+ " Lower Threshold Voltage = -7.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.2 Page No 155"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Rf = 100*10**3 #Feedback Resistance\n",
+ "C = 0.1*10**-6 \n",
+ "\n",
+ "#calculation\n",
+ "T = 2 * Rf * C\n",
+ "\n",
+ "#result\n",
+ "print\" Period \", T,\"s or \",T*1000,\"ms\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Period 0.02 s or 20.0 ms\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.3 Page No 155"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "T = 20*10**-3 #Period \n",
+ "\n",
+ "#calculation\n",
+ "f = 1 / T\n",
+ "\n",
+ "#Result\n",
+ "print\" Frequency = \", f,\"Hz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Frequency = 50.0 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.5 Page No 159"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Rf = 100*10**3 #Feedback Resistance\n",
+ "C = 0.1*10**-6 \n",
+ "\n",
+ "#Calculation\n",
+ "t = (Rf * C)/ 5.0 \n",
+ "\n",
+ "#Result\n",
+ "print\" Duration of output pulse of one-shot = \", t ,\"sec or\",t*1000,\"ms\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Duration of output pulse of one-shot = 0.002 sec or 2.0 ms\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.6 Page No 162"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vsatm = -13.8 \n",
+ "Vut = 5.0 #Upper Threshold Voltage\n",
+ "R = 10*10**3 \n",
+ "f = 1000.0 #Frequency\n",
+ "C = 0.05*10**-6 \n",
+ "\n",
+ "#calculation\n",
+ "p = -Vsatm / Vut \n",
+ "pR = round(p,1) * R \n",
+ "Ri = p / (4*f*C) \n",
+ "\n",
+ "#Result\n",
+ "print\" Value of p = \", p \n",
+ "print\" Value of pR =\", pR/1000,\"kohm\"\n",
+ "print\" Value of Ri = \", round(Ri/1000,0),\"kohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of p = 2.76\n",
+ " Value of pR = 28.0 kohm\n",
+ " Value of Ri = 14.0 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.7 Page No 163"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "p = 2.8 \n",
+ "Vsatm = -13.8 \n",
+ "Ri = 28*10**3 \n",
+ "C = 0.05*10**-6\n",
+ "\n",
+ "#Calculation\n",
+ "Vut = - ((Vsatm+0.6)/p)\n",
+ "f = p / (2*Ri*C)\n",
+ "\n",
+ "#Result\n",
+ "print\" Peak Voltage = \", round(Vut,2),\"V\"\n",
+ "print\" frequency = \", f ,\"Hz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Peak Voltage = 4.71 V\n",
+ " frequency = 1000.0 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.8 Page No 167"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "#Checking Frequency value\n",
+ "Ri = 10*10**3 \n",
+ "Ci = 0.1*10**-6 \n",
+ "Ei = 1.0 \n",
+ "Vref = 10.0 \n",
+ "\n",
+ "#Calculation\n",
+ "f = Ei / (Ri*Ci*Vref) \n",
+ "\n",
+ "#Result\n",
+ "print\" Frequency is \", f,\"Hz\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Frequency is 100.0 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.9 Page No 168"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ri = 10*10**3 #Resistance\n",
+ "Ci = 0.1*10**-6 \n",
+ "Ei = 2.0 \n",
+ "Vref = 2.0 \n",
+ "\n",
+ "#Calculation\n",
+ "f = Ei / (Ri*Ci*Vref) \n",
+ "\n",
+ "#Result\n",
+ "print \" New Frequency of oscillation is \", f/1000 ,\"KHz\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Frequency is 200.0 Hz. So It means Frequency is doubled.\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.10 Page no 168"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vref1 = 10.0 \n",
+ "Vref2 = 5.0 \n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "f1 =1000/Vref1\n",
+ "f2 = 1000/Vref2 \n",
+ "\n",
+ "#Result\n",
+ "print\"For Vref=10V, frequency is\",f1,\"Hz and For Vref=5V, frequency is\",f2,\"Hz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For Vref=10V, frequency is 100.0 Hz and For Vref=5V, frequency is 200.0 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.11 Page no 172"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "V=5 #Peak voltage\n",
+ "f=1 #Khz frequency\n",
+ "Vref=5 #V\n",
+ "C=0.01*10**-6 #Capacitance\n",
+ "\n",
+ "#Calculation\n",
+ "Ri=1/(4*f*1000*C)\n",
+ "\n",
+ "#Result\n",
+ "print\"Value of Ri is\",Ri/1000,\"Kohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of Ri is 25.0 Kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.12 Page No 175"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ei = 1.0 \n",
+ "#Angle given in degree\n",
+ "t1 = 45.0 \n",
+ "t2 = 90.0\n",
+ "t3 = 225.0\n",
+ "t4 = 405.0\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "Vang1 = (20*10**-3)*t1 \n",
+ "Vang2 = (20*10**-3)*t2 \n",
+ "Vang3 = (20*10**-3)*t3 \n",
+ "Vang4 = (20*10**-3)*t4\n",
+ "Vo1 = Ei*math.sin(t1*3.14/180.0)\n",
+ "Vo2 = Ei*math.sin(t2*3.14/180.0)\n",
+ "Vo3 = Ei*math.sin(t3*3.14/180.0)\n",
+ "Vo4 = Ei*math.sin(t4*3.14/180.0)\n",
+ "\n",
+ "#Result\n",
+ "print\" Input Voltages are \", Vang1,\"V, \",Vang2,\"V ,\",Vang3,\"V,\",Vang4 , \"V\"\n",
+ "print\" Output Voltages are \", round(Vo1,3),\"V,\",round(Vo2,3),\"V,\",round(Vo3,3),\"V,\",round(Vo4,3),\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Input Voltages are 0.9 V, 1.8 V , 4.5 V, 8.1 V\n",
+ " Output Voltages are 0.707 V, 1.0 V, -0.706 V, 0.705 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.13 Page No 178"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "R1 = 10*10**3 \n",
+ "R2 = 100*10**3 \n",
+ "C = 0.025*10**-6\n",
+ "\n",
+ "#Calculation\n",
+ "f1 = 1 / (4*R1*C) \n",
+ "f2 = 1 / (4*R2*C) \n",
+ "\n",
+ "#Result\n",
+ "print\" Frequency when Ri is 10KiloOhm is \" , f1/1000.0,\"KHz\"\n",
+ "print\" Frequency when Ri is 100KiloOhm is \" , f2,\"Hz\"\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Frequency when Ri is 10KiloOhm is 1.0 KHz\n",
+ " Frequency when Ri is 100KiloOhm is 100.0 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C7_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C7_1.ipynb
new file mode 100644
index 00000000..5a018ea4
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C7_1.ipynb
@@ -0,0 +1,63 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7:Op Amps with diodes"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 7.1 Page no 205"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "V = 15.0 #V,Voltage\n",
+ "mR = 30*10**3 #, ohm, Resistance \n",
+ "R = 10*10**3 #ohm, 2nd resistor\n",
+ "Ei = -10 #V, Voltage supply\n",
+ "\n",
+ "#calculation\n",
+ "Vref = V / 3.0 \n",
+ "Voa = -Ei-Vref \n",
+ "Vob = Ei / 2.0 \n",
+ "\n",
+ "#Result\n",
+ "print\"Reference voltage is\",Vref,\"V\"\n",
+ "print\"Values of Voa =\",Voa,\"V\",\"and Vob \", Vob,\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reference voltage is 5.0 V\n",
+ "Values of Voa = 5.0 V and Vob -5.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C8_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C8_1.ipynb
new file mode 100644
index 00000000..c5da6d5b
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C8_1.ipynb
@@ -0,0 +1,544 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:eb16b5620fb956842995f8d06be59d7e1e1d7123054fdad5a84f667167801f94"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: Differential, Instrumentation and Bridge amplifiers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 8.1 Page No 218"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "m = 100.0 #Differential Gain\n",
+ "E1 = 10*10**-3\n",
+ "E2 = 10*10**-3 #input voltages\n",
+ "E3 = 0*10**-3 \n",
+ "E4 = -20*10**-3 #input voltages\n",
+ "\n",
+ "#Calculation\n",
+ "Vout1 = (m*E1)-(m*E2) \n",
+ "Vout2 = (m*E1)-(m*E3)\n",
+ "Vout3 = (m*E1)-(m*E4)\n",
+ "\n",
+ "#Result\n",
+ "print\" Output Voltages are \", Vout1,\"V, \",Vout2,\"V ,\",Vout3,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Output Voltages are 0.0 V, 1.0 V , 3.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 8.2 Page no. 220"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "V=5 #V\n",
+ "d=2 #mV\n",
+ "E1=V+d*10**-3\n",
+ "E2=V-d*10**-3\n",
+ "\n",
+ "#Calculation\n",
+ "Eds=E1-E2\n",
+ "Ecm=(E1+E2)/2.0\n",
+ "\n",
+ "#Result\n",
+ "print\"Input signal voltage is\",Eds*1000,\"mV\"\n",
+ "print\"Common mode voltage is\",Ecm,\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input signal voltage is 4.0 mV\n",
+ "Common mode voltage is 5.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 8.2 Page No 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "a = 2/9.0 #Differential Gain\n",
+ "E1 = 10*10**-3\n",
+ "E2 = 5*10**-3 #Input Voltages \n",
+ "\n",
+ "#Calculation\n",
+ "Vout = (E1 - E2)*(1+(2/a))\n",
+ "\n",
+ "#Result\n",
+ "print\" output voltage = \", Vout*1000,\"mV\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " output voltage = 50.0 mV\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 8.3 Page No 227"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "R = 25*10**3 \n",
+ "aR = 50.0 \n",
+ "\n",
+ "#Calculation\n",
+ "a = aR / R \n",
+ "Gain = 1 + (2/a) \n",
+ "\n",
+ "#Result\n",
+ "print\"Voltage Gain = \" , Gain "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage Gain = 1001.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 8.4 Page No 227"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "import numpy\n",
+ "a=numpy.inf\n",
+ "\n",
+ "#Calculation\n",
+ "Gain = 1+(2/a) \n",
+ "\n",
+ "#Result\n",
+ "print\" Voltage Gain = \", Gain"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Voltage Gain = 1.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 8.5 Page No 227"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "m = 1001.0 #Gain\n",
+ "E1 = 5.001\n",
+ "E2 = 5.002\n",
+ "E3 = 5.001 \n",
+ "E4 = 5.000 \n",
+ "E5 = -1.001 \n",
+ "E6 = -1.002 \n",
+ "\n",
+ "#Calculation\n",
+ "Vout1 = m*(E1-E2)\n",
+ "Vout2 = m*(E3-E4) \n",
+ "Vout3 = m*(E5-E6)\n",
+ "\n",
+ "#result\n",
+ "print\" Output Voltages are \", Vout1,\"V \",Vout2,\"V \",Vout3,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Output Voltages are -1.001 V 1.001 V 1.001 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 8.6 Page No 231"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vout = 5.0 #Output Voltage\n",
+ "\n",
+ "#Calculation\n",
+ "Vce = Vout \n",
+ "\n",
+ "#Result\n",
+ "print\" Vce=\",Vce,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Vce= 5.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 8.7 Page No 231"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vre = 1.2 \n",
+ "Re = 1*10**3 \n",
+ "Vce = 5\n",
+ "Vcc = 15 #Voltages in the circuit\n",
+ "\n",
+ "#Calculation\n",
+ "Ie = Vre / Re \n",
+ "Vcol = Vce + Vre \n",
+ "Vrl = Vcc - Vcol \n",
+ "\n",
+ "#Result\n",
+ "print\" Collector Voltage = \", Vcol,\"V\"\n",
+ "print\" Voltage across Rl =\", Vrl,\"V\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Collector Voltage = 6.2 V\n",
+ " Voltage across Rl = 8.8 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 8.8 Page No 232"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Rs = 1*10**3\n",
+ "E1 = 100*10**-3 \n",
+ "E2 = 0 \n",
+ "Rl = 5*10**3 \n",
+ "Gain = 10 \n",
+ "\n",
+ "#Calculation\n",
+ "Il = 10*((E1-E2)/Rs)\n",
+ "Vr = Il * Rs \n",
+ "Vref = Il * Rl \n",
+ "V9 = Vref + Gain*(E1 - E2)\n",
+ "\n",
+ "#Result\n",
+ "print\" Current across Load Resistor = \", Il*1000 ,\"mA\"\n",
+ "print\" Voltage across R = \", Vr,\"V\"\n",
+ "print\" Reference Voltage = \", Vref,\"V\" \n",
+ "print\" Voltage at terminal 9 =\", V9,\"V\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Current across Load Resistor = 1.0 mA\n",
+ " Voltage across R = 1.0 V\n",
+ " Reference Voltage = 5.0 V\n",
+ " Voltage at terminal 9 = 6.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 8.9 Page No 234"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "GF = 2.0 #Gage factor\n",
+ "DR = 0.001 \n",
+ "R = 120.0 \n",
+ "\n",
+ "#calculation\n",
+ "L = DR /(R*GF) \n",
+ "\n",
+ "#result\n",
+ "print\" Change in length is \",round(L*10**6,1),\"microinches per inch\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Change in length is 4.2 microinches per inch\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 8.10 Page No 236"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "E = 1.0 \n",
+ "DR = 0.001 \n",
+ "R = 120.0 #Resistance in Ohm\n",
+ "\n",
+ "#Calculation\n",
+ "Vout = (E*DR)/(4*R) \n",
+ "\n",
+ "#Result\n",
+ "print\" Output of the Bridge = \", round(Vout*10**6,1),\"micro voltage\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Output of the Bridge = 2.1 micro voltage\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 8.11 Page No 241"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vout = 100*10**-3 \n",
+ "E = 5.0\n",
+ "R = 120.0 \n",
+ "Gain = 1000.0 \n",
+ "E1 = 30 *10**6 \n",
+ "Gf = 2.0 #Gage factor\n",
+ "\n",
+ "#calculation\n",
+ "Vbridge = Vout / Gain \n",
+ "DL = 20*10**-6 \n",
+ "DR = (R * Vbridge)/E \n",
+ "Rratio = DR / R #Change in Resistance\n",
+ "Strain = DL / Gf #Change in Length \n",
+ "Stress = E1 * Strain \n",
+ "\n",
+ "#Result\n",
+ "print \" Change in Resistance = \", DR*1000 ,\"mohm\"\n",
+ "print \" Ratio of Resistance = \", Rratio,\"micro ohm/ohm\"\n",
+ "print \" Strain value = \", Strain ,\"micro inch/inch\"\n",
+ "print \" Stress value = \", Stress ,\"psi\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Change in Resistance = 2.4 mohm\n",
+ " Ratio of Resistance = 2e-05 micro ohm/ohm\n",
+ " Strain value = 1e-05 micro inch/inch\n",
+ " Stress value = 300.0 psi\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 8.12 Page No 245\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "T1=25 #C Temprature\n",
+ "T2=50\n",
+ "Tref=25 #C Reference temprature\n",
+ "Rref=10000\n",
+ "Rtrans=3603 #ohm, at 50 C\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "dR=Rtrans-Rref\n",
+ "R1=10 #Kohm say\n",
+ "E=1 #V trial choice\n",
+ "I=E/(R1+Rref/1000.0)\n",
+ "Vo=-I*dR\n",
+ "\n",
+ "#result\n",
+ "print\"The value of dR for each temprature is\",dR,\"ohm\"\n",
+ "print\"The current is\",I,\"mA\"\n",
+ "print\"Vo for each value of R\",Vo,\"mV\"\n",
+ "#NOTE: In the book the value of Vo is calculated wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of dR for each temprature is -6397 ohm\n",
+ "The current is 0.05 mA\n",
+ "Vo for each value of R 319.85 mV\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/C9_1.ipynb b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C9_1.ipynb
new file mode 100644
index 00000000..e0e0173e
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/C9_1.ipynb
@@ -0,0 +1,297 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9:DC Performance :Bias,Offsets and Drift"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Exampme 9.1 Page No. 256"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Ibplus=0.4 #MicroA\n",
+ "Ibminus=0.3 #MicroA\n",
+ "\n",
+ "#calculation\n",
+ "Ib=(Ibplus+Ibminus)/2.0\n",
+ "Ios=Ibplus-Ibminus\n",
+ "\n",
+ "#Result\n",
+ "print\"The average bias current is\",Ib,\"microA\"\n",
+ "print\"The offset current is\",Ios,\"microA\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The average bias current is 0.35 microA\n",
+ "The offset current is 0.1 microA\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Exampme 9.2 Page No. 257"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vo=0.4 #A\n",
+ "Rf=1*10**6 #ohm\n",
+ "\n",
+ "#Calculation\n",
+ "Ibminus=Vo/Rf\n",
+ "\n",
+ "#Result\n",
+ "print\"The Ibminus is\",Ibminus*10**6,\"microA\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Ibminus is 0.4 microA\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Exampme 9.3 Page No.258"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vo=-0.3 #A\n",
+ "Rf=1*10**6 #ohm\n",
+ "\n",
+ "#Calculation\n",
+ "Ibplus=-Vo/Rf\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print\"The Ibplus is\",Ibplus*10**6,\"microA\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Ibplus is 0.3 microA\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Exampme 9.4 Page No. 260"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Rf=100.0 #kohm\n",
+ "Ri1=10.0 #kohm\n",
+ "Ri2=100.0 #kohm\n",
+ "\n",
+ "#Calculation\n",
+ "R1=Rf*Ri1/(Rf+Ri1)\n",
+ "R2=Rf*Ri2/(Rf+Ri2)\n",
+ "\n",
+ "#Result\n",
+ "print\"(a) The value of resistance is\",round(R1,1),\"ohm\"\n",
+ "print\"(b) The value of resistance is\",R2,\"ohm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The value of resistance is 9.1 ohm\n",
+ "(b) The value of resistance is 50.0 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Exampme 9.5 Page No. 262"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "Vio=1 #mV\n",
+ "Rf=1 #kohm\n",
+ "Ri=10 #ohm\n",
+ "\n",
+ "#calculation\n",
+ "Vo=(Vio+(Rf*1000/Ri)*Vio)\n",
+ "\n",
+ "#result\n",
+ "print\"The value of Vo is\",Vo,\"mV\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of Vo is 101 mV\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Exampme 9.6 Page No. 268"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "T1=75.0 #Temprature ,C\n",
+ "T2=25.0 #Temprature ,C\n",
+ "Viomax=20.0 #microV, Voltage\n",
+ "Ioschange=0.1 #nm\n",
+ "Rf=10**6 #ohm\n",
+ "Ri=10*10**3 #ohm\n",
+ "\n",
+ "#Calculation\n",
+ "Vio=Viomax*(T1-T2)\n",
+ "change=Vio*(1+Rf/Ri)\n",
+ "Ioschange=Ioschange*(T1-T2)\n",
+ "Vochange=Ioschange*Rf\n",
+ "\n",
+ "#Result\n",
+ "print\"The change in Vo due to change in Vio is\",change/10**3,\"mV\"\n",
+ "print\"The change in Vo due to change in Ios is\",Vochange/10**6,\"mV\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The change in Vo due to change in Vio is 101.0 mV\n",
+ "The change in Vo due to change in Ios is 5.0 mV\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Exampme 9.7 Page No. 270"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "Vo=0.421 #V,\n",
+ "Vo1=0.097\n",
+ "Vo2=-0.082\n",
+ "Rf1=5000 #from fig 9-10(a)\n",
+ "Ri=50\n",
+ "Rf2=1.0 #Mohm fig 9-10 (b)\n",
+ "\n",
+ "#calculation\n",
+ "Vio=Vo/(1+Rf1/Ri)\n",
+ "Ibminus=(Vo1*1000-Vio*1000)/Rf2\n",
+ "Ibplus=-(Vo2*1000-0.0041*1000)/Rf2\n",
+ "\n",
+ "#Result\n",
+ "print\"The value of Vio is\",round(Vio*1000,1),\"mV\"\n",
+ "print\"Ibminus is\",round(Ibminus,0),\"nA\"\n",
+ "print\"Ibplus is\",round(Ibplus,0),\"nA\"\n",
+ "print\"Ios calculated as\",round(Ibplus-Ibminus,0),\"nA\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of Vio is 4.2 mV\n",
+ "Ibminus is 93.0 nA\n",
+ "Ibplus is 86.0 nA\n",
+ "Ios calculated as -7.0 nA\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/README.txt b/Operational_Amplifiers_and_Linear_Integrated_Circuit/README.txt
new file mode 100644
index 00000000..39ab128f
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Rahul garg
+Course: btech
+College/Institute/Organization: MDU,Rohtak
+Department/Designation: ECE
+Book Title: Operational Amplifiers and Linear Integrated Circuit
+Author: R F Coughline anf F F Driscoll
+Publisher: Prentice Hall, United states
+Year of publication: 2000
+Isbn: 978-0130149916
+Edition: 6 \ No newline at end of file
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/2_2.png b/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/2_2.png
new file mode 100644
index 00000000..5dcd3d82
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/2_2.png
Binary files differ
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/2_2_(1).png b/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/2_2_(1).png
new file mode 100644
index 00000000..5dcd3d82
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/2_2_(1).png
Binary files differ
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/3_4.png b/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/3_4.png
new file mode 100644
index 00000000..b1de058b
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/3_4.png
Binary files differ
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/3_4_(1).png b/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/3_4_(1).png
new file mode 100644
index 00000000..b1de058b
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/3_4_(1).png
Binary files differ
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/4_1.png b/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/4_1.png
new file mode 100644
index 00000000..97c0dd2f
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/4_1.png
Binary files differ
diff --git a/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/4_1_(1).png b/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/4_1_(1).png
new file mode 100644
index 00000000..97c0dd2f
--- /dev/null
+++ b/Operational_Amplifiers_and_Linear_Integrated_Circuit/screenshots/4_1_(1).png
Binary files differ
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter1.ipynb
deleted file mode 100755
index 76fe396c..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter1.ipynb
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_1"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 1 :- Introduction"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "# Theortical Chapter",
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter10_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter10_1.ipynb
deleted file mode 100755
index 077ac9f5..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter10_1.ipynb
+++ /dev/null
@@ -1,104 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_10"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 10 : Optical amplification, wavelength conversion and regeneration\n"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 10.1, page 555"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh=1.5*10**-6 #peak gain wavelength\ndelt=10**-9 #mode spacing\nl=300*10**-6 #length\nc=2.998*10**8 #speed of light\nr=0.09 #facet reflectivities\ngs=3.020\n\n#Calculation\nn=(h**2)/(2*delt*l) #refractive index\na=c/(math.pi*n*l)\nd=1-(math.sqrt(r)*gs)\nf=2*math.sqrt(math.sqrt(r)*gs)\nB=a*math.asin(d/f) #spectral bandwidth\n#Result\nprint'Refractive index of a medium = %.2f'%n\nprint'3dB spectral bandwidth = %.1f GHz'%(B*10**-9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Refractive index of a medium = 3.75\n3dB spectral bandwidth = 4.2 GHz\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 10.3, page 562"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ngs=30 #gain in dB\ng=200 #net gain\nloge=0.434 #log(e)\ngs1=1000\nm=2.2 #mode no\nnsp=4 #spontaneous emission factor\nh1=6.626*10**-34 #plancks constant\nf=1.94*10**14\nB=1.0*10**12 #bandwidth\n\n#Calculation\nL=gs/(10*g*loge) #length of the device\nP=m*nsp*(gs1-1)*h1*f*B #noise power spectral density\n\n#Result\nprint'(a) Length of the device = %.2f mm'%(L*10**3)\nprint'(b) Noise power spectral density = %.2f mW'%(P*10**3)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Length of the device = 34.56 mm\n(b) Noise power spectral density = 1.13 mW\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 10.4, page 580"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nGp=62.2 #parametric peak gain in dB\nlog=10*math.log10(0.25)\nPp=1.4 #signal power in watt\nL=500 #length in meter\nlog2=20*math.log10(2.7182818284)\n\n\n#Calculation\ny=(Gp-log)/(Pp*L*log2) #fiber nonlinear coefficient\nGp2=10*math.log10((y*Pp*L)**2) #parametric gain\n \n#Result\nprint'(a) Fiber nonlinear coefficient = %.2f x 10^-3 W^-1 km^-1'%(y*1000)\nprint'(b) Quadratic gain, Gp = %.2f dB'%(Gp2)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Fiber nonlinear coefficient = 11.22 x 10^-3 W^-1 km^-1\n(b) Quadratic gain, Gp = 17.90 dB\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 10.5, page 589 "
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npt=0.5*10**-3 #input signal power\ndpt=0.01*10**-6 #input signal power variation\nh=1.55*10**-6 #signal wavelength\na=-1 #linewidth enhancement factor\ndn=-1.2*10**-26 #differential refractive index\n\n#Calculation\ndelt=(-a*dpt)/(4*math.pi*pt) #frequency chirp\ndg=(4*math.pi*dn)/(h*a) #differential gain\n \n#Result\nprint'(a) Frequency chirp variation = %.2f MHz'%(delt*10**6)\nprint'(b) Differential gain = %.2f x10^-20 m^2'%(dg*10**20)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Frequency chirp variation = 1.59 MHz\n(b) Differential gain = 9.73 x10^-20 m^2\n"
- }
- ],
- "prompt_number": 4
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter10_2.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter10_2.ipynb
deleted file mode 100755
index 077ac9f5..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter10_2.ipynb
+++ /dev/null
@@ -1,104 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_10"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 10 : Optical amplification, wavelength conversion and regeneration\n"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 10.1, page 555"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh=1.5*10**-6 #peak gain wavelength\ndelt=10**-9 #mode spacing\nl=300*10**-6 #length\nc=2.998*10**8 #speed of light\nr=0.09 #facet reflectivities\ngs=3.020\n\n#Calculation\nn=(h**2)/(2*delt*l) #refractive index\na=c/(math.pi*n*l)\nd=1-(math.sqrt(r)*gs)\nf=2*math.sqrt(math.sqrt(r)*gs)\nB=a*math.asin(d/f) #spectral bandwidth\n#Result\nprint'Refractive index of a medium = %.2f'%n\nprint'3dB spectral bandwidth = %.1f GHz'%(B*10**-9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Refractive index of a medium = 3.75\n3dB spectral bandwidth = 4.2 GHz\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 10.3, page 562"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ngs=30 #gain in dB\ng=200 #net gain\nloge=0.434 #log(e)\ngs1=1000\nm=2.2 #mode no\nnsp=4 #spontaneous emission factor\nh1=6.626*10**-34 #plancks constant\nf=1.94*10**14\nB=1.0*10**12 #bandwidth\n\n#Calculation\nL=gs/(10*g*loge) #length of the device\nP=m*nsp*(gs1-1)*h1*f*B #noise power spectral density\n\n#Result\nprint'(a) Length of the device = %.2f mm'%(L*10**3)\nprint'(b) Noise power spectral density = %.2f mW'%(P*10**3)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Length of the device = 34.56 mm\n(b) Noise power spectral density = 1.13 mW\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 10.4, page 580"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nGp=62.2 #parametric peak gain in dB\nlog=10*math.log10(0.25)\nPp=1.4 #signal power in watt\nL=500 #length in meter\nlog2=20*math.log10(2.7182818284)\n\n\n#Calculation\ny=(Gp-log)/(Pp*L*log2) #fiber nonlinear coefficient\nGp2=10*math.log10((y*Pp*L)**2) #parametric gain\n \n#Result\nprint'(a) Fiber nonlinear coefficient = %.2f x 10^-3 W^-1 km^-1'%(y*1000)\nprint'(b) Quadratic gain, Gp = %.2f dB'%(Gp2)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Fiber nonlinear coefficient = 11.22 x 10^-3 W^-1 km^-1\n(b) Quadratic gain, Gp = 17.90 dB\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 10.5, page 589 "
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npt=0.5*10**-3 #input signal power\ndpt=0.01*10**-6 #input signal power variation\nh=1.55*10**-6 #signal wavelength\na=-1 #linewidth enhancement factor\ndn=-1.2*10**-26 #differential refractive index\n\n#Calculation\ndelt=(-a*dpt)/(4*math.pi*pt) #frequency chirp\ndg=(4*math.pi*dn)/(h*a) #differential gain\n \n#Result\nprint'(a) Frequency chirp variation = %.2f MHz'%(delt*10**6)\nprint'(b) Differential gain = %.2f x10^-20 m^2'%(dg*10**20)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Frequency chirp variation = 1.59 MHz\n(b) Differential gain = 9.73 x10^-20 m^2\n"
- }
- ],
- "prompt_number": 4
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter11.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter11.ipynb
deleted file mode 100755
index 77cd82ac..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter11.ipynb
+++ /dev/null
@@ -1,62 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_11"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 1 : Integrated optics and photonics"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 11.1, page 624"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh=1.3*10**-6 #wavlength\nd=25*10**-6 #distance between the electrodes\nn1=2.1 #refractive index\nr=30.8*10**-12 #electro-optic coefficient\nl=2*10**-2 #length\n\n\n#Calculation\nV=(h*d)/(n1**3*r*l) #voltage\n\n#Result\nprint'Voltage = %.1f V'%V",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Voltage = 5.7 V\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 11.2, page 629"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nn1=3.1 #refractive index\nthet=1 #angle in degree\nh=1.52*10**-6 #wavelength\nl=10**-2 #length\n\n#Calculation\nne=n1*math.sin(2*thet*math.pi/180) #effective refractive index\nD=h/(2*ne) #Corrugation period\ns=D*h/l #filter bandwidth\n\n\n#Result\nprint'Corrugation period = %.1f um'%(D*10**6)\nprint'Filter 3 dB bandwidth = %.1f \u00c5 '%(s*10**10)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Corrugation period = 7.0 um\nFilter 3 dB bandwidth = 10.7 \u00c5 \n"
- }
- ],
- "prompt_number": 2
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter11_2.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter11_2.ipynb
deleted file mode 100755
index 77cd82ac..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter11_2.ipynb
+++ /dev/null
@@ -1,62 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_11"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 1 : Integrated optics and photonics"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 11.1, page 624"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh=1.3*10**-6 #wavlength\nd=25*10**-6 #distance between the electrodes\nn1=2.1 #refractive index\nr=30.8*10**-12 #electro-optic coefficient\nl=2*10**-2 #length\n\n\n#Calculation\nV=(h*d)/(n1**3*r*l) #voltage\n\n#Result\nprint'Voltage = %.1f V'%V",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Voltage = 5.7 V\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 11.2, page 629"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nn1=3.1 #refractive index\nthet=1 #angle in degree\nh=1.52*10**-6 #wavelength\nl=10**-2 #length\n\n#Calculation\nne=n1*math.sin(2*thet*math.pi/180) #effective refractive index\nD=h/(2*ne) #Corrugation period\ns=D*h/l #filter bandwidth\n\n\n#Result\nprint'Corrugation period = %.1f um'%(D*10**6)\nprint'Filter 3 dB bandwidth = %.1f \u00c5 '%(s*10**10)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Corrugation period = 7.0 um\nFilter 3 dB bandwidth = 10.7 \u00c5 \n"
- }
- ],
- "prompt_number": 2
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter12_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter12_1.ipynb
deleted file mode 100755
index 288c514a..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter12_1.ipynb
+++ /dev/null
@@ -1,488 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_12"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 12 :- Optical fiber systems 1: Intensity modulation/direct detection\n"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.1, page 706"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nn=8 #bits in a time slot\nt=32 #bits in a frame\nf=8*10**3 #frequency\nm=16 #bits in a multiframe\n\n#Calculation\nnb=n*t #number of bits in a frame\nfr=nb*f #transmission rate\ntr=fr**-1 #bit duration\nts=tr*n #duration of a time slot\ntf=ts*t #duration of a frame\ntm=tf*m #duration of a multiframe\n\n#Result\nprint'(a) Bit rate for the system = %.3f Mbit s^-1'%(fr*10**-6)\nprint'(b) Duration of the time slot = %.1f \u03bcs'%(ts*10**6)\nprint'(c) Duration of a frame = %d \u03bcs' %(tf*10**6)\nprint'Duration of a multiframe = %d ms' %(tm*10**3)\n\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Bit rate for the system = 2.048 Mbit s^-1\n(b) Duration of the time slot = 3.9 \u03bcs\n(c) Duration of a frame = 125 \u03bcs\nDuration of a multiframe = 2 ms\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.2, page 720"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nm=4.24 #erfc = 2*10^9\na=2*math.sqrt(2)\n\n#Calculation\nsn=m*a #root of S/N = optical\nsn1=10*math.log10(sn) #in dB\nisq=sn**2 #S/N = electrical \nisq1=10*math.log10(isq) #in dB\n#Result\nprint'Optical SNR = %.1f'%sn\nprint' = %.1f dB'%sn1\nprint'Electrical SNR = %.1f'%round(isq)\nprint' = %.1f dB'%isq1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Optical SNR = 12.0\n = 10.8 dB\nElectrical SNR = 144.0\n = 21.6 dB\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.3, page 723"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nm=100 #multiplication factor\nk=0.02 #ratio of carrier ionization rates \nsn=144 #electrical SNR\nn=0.8 #quantum efficiency\nB=0.6\n\n#Calculation\nfm=(k*m)+(2-(1/m))*(1-k) #avalanche noise factor\nzm=2*B*round(fm)*sn/n #average number of photons\n\n#Result\nprint'Average no of photons = %d photons'%round(zm)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Average no of photons = 864 photons\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.4, page 724"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nzm=864 #average no of photons\nh=6.626*10**-34 #plancks constant\nc=2.998*10**8 #velocity of light\nl1=10**-6 #wavelength\nl2=10**-14 #wavelength\nbt=10**7 \nn=14\n\n\n#Calculation\npo1=(zm*h*c*bt)/(2*l1) #At 10 Mbit s^-1\npo2=(zm*h*c*n*bt)/(2*l2) #At 140 Mbit s^-1\n\n#Result\nprint'Incident optical power (10 Mbit s^-l) = %.1f pW'%(po1*10**12)\nprint'Incident optical power (140 Mbit s^-l) = %.3f W'%po2 #value given in a textbook is incorrect",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Incident optical power (10 Mbit s^-l) = 858.2 pW\nIncident optical power (140 Mbit s^-l) = 1.201 W\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.5, page 726"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nafc=5 #fibre cable attenuation\nai=2 #splice losses\nl=4 #length in Km\naf=3.5+2.5 #connector losses at source and detector resp\n\n#Calculation\nCl=(afc+ai)*l+af #total channel loss\n\n#Result\nprint'Total channel loss = %d dB'%Cl",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total channel loss = 34 dB\n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.6, page 727"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ns=0.6*10**-9 #rms pulse broadening\nL=8 #length in km\nbt=25*10**6 #bit rates\nbt1=150*10**6 #bit rates\n\n#Calculation\nst=s*L #total rms pulse broadening\ndl1=2*(2*st*bt*math.sqrt(2))**4 #without mode coupling\nst1=s*math.sqrt(L) #total rms pulse broadening\ndl2=2*(2*st1*bt*math.sqrt(2))**4 #with mode coupling\ndl3=2*(2*st*bt1*math.sqrt(2))**4 #without mode coupling\ndl4=2*(2*st1*bt1*math.sqrt(2))**4 #with mode coupling\n\n#Result\nprint'(a) For 25 Mbit per sec'\nprint'dispersion\u2013equalization penalty (without mode coupling) = %.2f dB'%dl1\nprint'dispersion\u2013equalization penalty (with mode coupling) = %.2f x 10^-4 dB\\n'%(dl2*10**4)\nprint'(b) For 150 Mbit per sec'\nprint'dispersion\u2013equalization penalty (without mode coupling) = %.2f dB'%dl3\nprint'dispersion\u2013equalization penalty (with mode coupling) = %.2f dB'%dl4",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) For 25 Mbit per sec\ndispersion\u2013equalization penalty (without mode coupling) = 0.03 dB\ndispersion\u2013equalization penalty (with mode coupling) = 4.15 x 10^-4 dB\n\n(b) For 150 Mbit per sec\ndispersion\u2013equalization penalty (without mode coupling) = 34.40 dB\ndispersion\u2013equalization penalty (with mode coupling) = 0.54 dB\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.7, page 731"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nts=8 #rise time for source in ns\ntn=5*ts #for fiber intermodal\ntc=1*ts #for pulse broadening\ntd=6 #for detector\n\n#Calculation\ntsys=1.1*(ts**2+tn**2+tc**2+td**2)**0.5 #total system rise time\nBt=0.7/(tsys*10**-9) #max bit rate\n\n\n#Result\nprint'Bt (Max) = %.1f Mbit per sec'%(Bt/10**6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Bt (Max) = 15.2 Mbit per sec\n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.8, page 732"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npo=-55 #mean power required at the APD receiver at 35 Mbit s^-1\npo1=-44 #mean power required at the APD receiver at 400 Mbit s^-1\npi=-3 #mean power launched from the laser transmitter\nl1=0.4 #cable fiber loss\nl2=0.1 #splice losses\nl3=1 #connector loss \nma=7 #safety margin\na=0.5 \nacr=2\ndl=1.5\n\n#Calculation \nL1=(pi-po-acr-ma)/a #for 35 Mbit s^-1\nL2=(pi-po1-acr-ma)/a #for 400 Mbit s^-1\nL3=(pi-po1-acr-dl-ma)/a #reduction in the maximum possible link\n\n#Result\nprint'(a) Maximum possible link length (operating at 35 Mbit s^-1) = %d km'%L1\nprint'(b) Maximum possible link length (operating at 400 Mbit s^-1) = %d km'%L2\nprint'(c) Reduction in the maximum possible link length = %d km'%L3",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Maximum possible link length (operating at 35 Mbit s^-1) = 86 km\n(b) Maximum possible link length (operating at 400 Mbit s^-1) = 64 km\n(c) Reduction in the maximum possible link length = 61 km\n"
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.9, page 734"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npo=-10 #mean optical power launched into the fiber from the transmitter (100 \u03bcm)\nrs=-41 #receiver sensitivity at 20 Mbit s^-1\nl1=7*2.6 #cabled fiber loss\nl2=6*0.5 #splice losses\nl3=1*1.5 #connector loss \nms=6 #safety margin\n\n#Calculation\nts=po-rs #Total system margin\ntsl=l1+l2+l3+ms #Total system loss\npm=ts-tsl #Excess power margin \n\n#Result\nprint'Total system margin = %d dB'%ts\nprint'Total system loss = %.1f dB'%tsl\nprint'Excess power margin = %.1f dB'%pm\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total system margin = 31 dB\nTotal system loss = 28.7 dB\nExcess power margin = 2.3 dB\n"
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.10, page 740"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nv=5 #output voltage\nh=6.626*10**-34 #plancks constant\nc=2.998*10**8 #velocity of light\nk=1.385*10**-23 #boltzman constant\nt=290 #tempreture in kelvin\nzo=100 #cable impedance\nn=0.7 #quantum efficiency\npi=10**-3 #optical power\nlam=0.85*10**-6 #wavelength\n\n#Calculation\nratio=(v**2*h*c)/(2*k*t*zo*n*pi*lam) #ratio\nratio1=10*math.log10(ratio) #ration in dB\n\n#Result\nprint'Ratio = %d dB'%ratio1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Ratio = 40 dB\n"
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.11, page 744"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nma=0.8 #modulation index\nR=0.5 #responsivity\nb=0.7 #ratio of luminance to composite video\nsnr=3.162*10**5 #SNR\ne=1.602*10**-19 #electron volt\nB=5*10**6 #bandwidth\nK=1.385*10**-23 #boltzman constant \nT=293 #tempreture in kelvin\nFn=1.413\nRl=10**6\n\n#Calculation\na=(2*ma*R*b)**2\nc=snr*2*e*B*R\nd=snr*4*K*T*B*Fn/Rl\nf = (c**2)+(4*a*d)\npo=(c+math.sqrt(f))/(2*a) #average incident optical power \npo1=10*math.log10(po*1000) #in dB\n\n#Result\nprint'Average incident optical power = %.2f uW'%(po*10**6)\nprint' = %.1f dB m'%po1\n\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Average incident optical power = 0.93 uW\n = -30.3 dB m\n"
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.12, page 747"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh=6.626*10**-34 #plancks constant\nc=2.998*10**8 #velocity of light\ne=1.602*10**-19 #1 electron volt\nn=0.6 #p\u2013i\u2013n photodiode quantum efficiency\nma=0.5 #modulation index\nlam=10**-6 #wavelength\nk=1.385*10**-23 #boltzman constant \nt=300 #tempreture in kelvin\nf=4 #amplifier noise figure\nrl=50*10**3 #effective load impedance\nsn=3.162*10**4 #signal to noise ratio\nB=10**7 #bandwidth\n\n#Calculation\na=h*c/(e*n*ma**2*lam)\nb=math.sqrt((8*k*t*f)/rl)\nc=math.sqrt(sn*B)\npo=a*b*c #optical power\npo1=10*math.log10(po*1000) #optical power in dB\n\n#Result\nprint'Optical power, Po = %.2f uW'%(po*10**6)\nprint' = %.1f dBm'%po1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Optical power, Po = 7.58 uW\n = -21.2 dBm\n"
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.13, page 748"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npo=-10 #mean optical power launched into the fiber from the transmitter (100 \u03bcm)\nrs=-25 #receiver sensitivity \nl1=2*3.5 #cable fiber loss\nl2=2*0.7 #splice losses\nl3=1.6 #connector loss \nms=4.0 #safety margin\nafc=3.5\nai=0.7\nacr=1.6\nma=7\n\n#Calculation\nts=po-rs #Total system margi\ntsl=l1+l2+l3+ms #Total system loss\npm=ts-tsl #Excess power margin \nL=((0-rs)-(acr+ma))/(afc+ai)\n\n#Result\nprint'(a) Total system margin = %d dB'%ts\nprint' Total system loss = %.1f dB'%tsl\nprint' Excess power margin = %.1f dB'%pm\nprint'\\n(b) Increase in link length = %.1f Km'%(L)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Total system margin = 15 dB\n Total system loss = 14.0 dB\n Excess power margin = 1.0 dB\n\n(b) Increase in link length = 3.9 Km\n"
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.14, page 750"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nBop=6*10**6\nts=10 #rise time for source in ns\ntn=5*9 #for fiber intermodal\ntc=5*2 #for pulse broadening\ntd=3 #for detector\n\n\n#Calculation\ntsys=0.35/Bop\ntsys1=1.1*(ts**2+tn**2+tc**2+td**2)**0.5 #total system rise time\n\n#Result\nprint'Maximum permitted system rise time = %.1f ns'%(tsys*10**9)\nprint'Total system rise time = %.1f ns'%(tsys1)\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum permitted system rise time = 58.3 ns\nTotal system rise time = 52.0 ns\n"
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.15, page 755"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nfd=400*10**3 #peak frequency deviation\nBa=4*10**3 #bandwidth\n\n#Calculation\nDf=fd/Ba #frequency deviation ratio\nsnr=1.76+(20*math.log10(Df)) #SNR improvement\nBm=2*(Df+1)*Ba #bandwidth of the FM\u2013IM signal \n \n#Result\nprint'(a) SNR improvement = %.2f dB'%snr\nprint'(b) Frequency deviation ratio = %d'%Df\nprint' Bandwidth of FM-IM signal = %d kHz'%(Bm/1000)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) SNR improvement = 41.76 dB\n(b) Frequency deviation ratio = 100\n Bandwidth of FM-IM signal = 808 kHz\n"
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.16, page 757"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nfm=3 #output FM ratio\npm=1 #output PM ratio\n\n#Calculation\nratio=fm/pm #SNR ratio\nratio1=10*math.log10(ratio) #SNR ratio in dB\n\n#Result\nprint'Ratio of output SNR = %.2f dB'%(ratio1)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Ratio of output SNR = 4.77 dB\n"
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.17, page 759"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nto=5*10**-8 #nominal pulse period\nfd=5*10**6 #Peak-to-peak frequency deviation\nM=60 #A PD multiplication factor\nR=0.7 #A PD responsivity\npo=10**-7 #peak optical power at receiver\ntr=12*10**-9 #Total system 10\u201390% rise time\nB=6*10**6 #baseband noise bandwidth\ni=10**-17 #Receiver mean square noise current\n\n\n#Calculation\nsnp=(3*(to*fd*M*R*po)**2)/(i*(2*math.pi*tr*B)**2) #peak-to-peak signal to rms noise ratio\nsnp1=10*math.log10(snp) #in dB\n\n#Result\nprint'Peak-to-peak signal to rms noise ratio = %.1f dB'%snp1\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Peak-to-peak signal to rms noise ratio = 62.1 dB\n"
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.18, page 763"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "%pylab inline\nimport math\nfrom pylab import *\nfrom numpy import *\n\n#Variable declaration\nacr=1 #connector loss in dB\nafc=5 #loss per kilometer in dB\nLbu=0.1 #fiber length between each of the access couplers\nLac=1 #insertion loss\nLtr=10 #loss due to the tap ratio\nLsp=3 #splitting loss\n \n#Calculating, we get two equation in terms of N, no of nodes, i.e C(1,N-1)=(3.5*N)+8.5 and C(star)=4.5+(10*log10(N)) \n\n#For Bus distribution system\n\nfor N in range(1,13,1):\n C=(3.5*N)+8.5;\n a=plot(N,C,'.r')\n \n \n#for Star distribution system\n \nfor N in range(1,30,1):\n C1=4.5+(10*log10(N));\n b=plot(N,C1,'.g')\n \n \n#To show plot in same graph\n#Graphical comparison showing total channel loss against number of nodes\n\nxlabel(\"Number of nodes $N$\")\nylabel(\"Total channel loss $CL$ (dB)\")\ngrid()\nshow(a)\nshow(b)\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Populating the interactive namespace from numpy and matplotlib\n"
- },
- {
- "metadata": {},
- "output_type": "display_data",
- "png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEOCAYAAABmVAtTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XtcVHX6B/DPqCgpJWgxmPprfJmoXIRREbdCpxAsTUQU\nq/UCarLpul1Nrd2Ktq1w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QsX74c\n3t7eKCgowODBgwE0LB4WEBCgvOemm25q9rao27dvR0JCghJfQkICtm3bhrCwsBZz69WrFwYMGAAA\nGDRoEEpKSnD8+PHLPis/Px/19fVISEiAt7c3vL29ERcXByEEtmzZcsWYBwwYgLlz52LBggW4++67\ncdttt7UYz6RJk7B27VqEhoZi+PDhLb6WPBOLArmFhx9+GAMHDsS0adMAAO3atVNaJACU1g8AdOjQ\nQfm5TZs2aN++vfJzbW2t8ruLe/JCCJhMJgghkJSUhBdeeKHZODp16tTs843vvfTzrubiWNu2bavk\ncelntfRzSzH36dMHRUVF+Pe//40//elPiI6OxlNPPdXkNWVlZbjxxhsBAOPHj8fQoUMREhJy1djJ\nM3GmQG7Bz88PEydOxKpVq2AymWA2m3H06FFUVFTg3Llz+Pjjj1UPXo8cOYIdO3YAADIyMhAVFYXo\n6Gi8//77OHbsGICGG5sfOXLkqp8VFRWFrKwsnD17FqdPn0ZWVhaioqLUJ3qFzxo2bBiGDRuGrKws\n1NTUoLq6Wsm5pZhLS0vh7e2NSZMmYe7cuSgsLLzs+3bt2oWBAwcCaDgqCwkJUT6L6FI8UiCXunhH\n/9hjj+HVV18F0HCk8PTTT2PIkCHo3r07goKCmn3PpY8v/rlv37547bXXMH36dAQHB2PWrFnw9vbG\nX/7yF8TGxqK+vh5eXl54/fXX8X//93/NfnYjq9WK5ORkpbU0c+ZMpXXUUrFqLtaWPuuee+5BWFgY\n/P39ld/379//ijF/8803ePzxx5UjpjfeeKPJ923ZsgWpqak4d+4cJkyYAKChlda1a9crxkyejUtn\nExGRgu0jIiJSsCgQEZGCRYGIiBQsCkREpGBRICIiBYsCEREpWBSIiEjBokBERIr/B5KTkPe2LreW\nAAAAAElFTkSuQmCC\n",
- "text": "<matplotlib.figure.Figure at 0x3f7ea90>"
- }
- ],
- "prompt_number": 27
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.19, page 782"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nh=6.626*10**-34 #plancks constant\nc=2.998*10**8 #velocity of light\nlam=1.55*10**-6 #wavelength\nL=100*10**3 #length\nK=4 \nB=1.2*10**9 #bandwidth\nsnr=50 #SNR\na=10**-2.5\npi=10**-3\n\n#Calculation\nLt=(pi*lam*a*L)/(K*h*c*B*snr) #link with a large number of cascaded amplifiers\n\n#Result\nprint'Maximum system length = %d x 10^4 km'%(Lt/10**7)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum system length = 1 x 10^4 km\n"
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.21, page 791"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nb=17 #second-order dispersion coefficient for the latter path\nL2=20 #path length in km\nL1=160.00 #path length in km\ns1=-0.075 #dispersion slope\n\n#Calculation\na=-b*L2\nG=a/L1 #second-order dispersion coefficient\ns2=s1*L1/L2 #chromatic dispersion slope\n\n#Result\nprint'(a) Second-order dispersion coefficient = %.3f ps nm^-1 km^-1'%G \nprint'(b) chromatic dispersion slope = %.1f ps nm^-2 km^-1'%s2",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Second-order dispersion coefficient = -2.125 ps nm^-1 km^-1\n(b) chromatic dispersion slope = -0.6 ps nm^-2 km^-1\n"
- }
- ],
- "prompt_number": 20
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.22, page 798"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nto=70*10**-12 #bit period\nt=6*10**-12 #RZ pulse width\nB2=50*10**-12*10**-12*10**-3 #second-order dispersion coefficient\nL=50*10**3 #amplifier spacing\n\n#Calculation\nqo=0.5*to/t #separation of the soliton pulses \nBt=(2*qo*math.sqrt(B2*L))**-1 #transmission bit rate \n\n#Result\nprint'(a) Separation = %.1f'%qo\nprint'(b) Transmission bit rate = %.2f x 10^9'%(Bt*10**-8)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Separation = 5.8\n(b) Transmission bit rate = 17.14 x 10^9\n"
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.23, page 799"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nto=40*10**-12 #bit period\nt=4*10**-12 #RZ pulse width\na=0.2*10**-3 #attenuation coefficient\nB2=1.25*10**-12*10**-12*10**-3 #second-order dispersion coefficient\n\n#Calculation\nqo=0.5*to/t #separation of the soliton pulses \nb=1/(2*qo)\nc=math.sqrt(a/B2)\nBt=b*c #transmission bit rate \n\n#Result\nprint'(a) Separation = %.1f'%qo\nprint'(b) Transmission bit rate = %.2f x 10^10 bit s^-1'%(Bt*10**-10)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Separation = 5.0\n(b) Transmission bit rate = 4.00 x 10^10 bit s^-1\n"
- }
- ],
- "prompt_number": 22
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter12_2.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter12_2.ipynb
deleted file mode 100755
index 288c514a..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter12_2.ipynb
+++ /dev/null
@@ -1,488 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_12"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 12 :- Optical fiber systems 1: Intensity modulation/direct detection\n"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.1, page 706"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nn=8 #bits in a time slot\nt=32 #bits in a frame\nf=8*10**3 #frequency\nm=16 #bits in a multiframe\n\n#Calculation\nnb=n*t #number of bits in a frame\nfr=nb*f #transmission rate\ntr=fr**-1 #bit duration\nts=tr*n #duration of a time slot\ntf=ts*t #duration of a frame\ntm=tf*m #duration of a multiframe\n\n#Result\nprint'(a) Bit rate for the system = %.3f Mbit s^-1'%(fr*10**-6)\nprint'(b) Duration of the time slot = %.1f \u03bcs'%(ts*10**6)\nprint'(c) Duration of a frame = %d \u03bcs' %(tf*10**6)\nprint'Duration of a multiframe = %d ms' %(tm*10**3)\n\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Bit rate for the system = 2.048 Mbit s^-1\n(b) Duration of the time slot = 3.9 \u03bcs\n(c) Duration of a frame = 125 \u03bcs\nDuration of a multiframe = 2 ms\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.2, page 720"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nm=4.24 #erfc = 2*10^9\na=2*math.sqrt(2)\n\n#Calculation\nsn=m*a #root of S/N = optical\nsn1=10*math.log10(sn) #in dB\nisq=sn**2 #S/N = electrical \nisq1=10*math.log10(isq) #in dB\n#Result\nprint'Optical SNR = %.1f'%sn\nprint' = %.1f dB'%sn1\nprint'Electrical SNR = %.1f'%round(isq)\nprint' = %.1f dB'%isq1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Optical SNR = 12.0\n = 10.8 dB\nElectrical SNR = 144.0\n = 21.6 dB\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.3, page 723"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nm=100 #multiplication factor\nk=0.02 #ratio of carrier ionization rates \nsn=144 #electrical SNR\nn=0.8 #quantum efficiency\nB=0.6\n\n#Calculation\nfm=(k*m)+(2-(1/m))*(1-k) #avalanche noise factor\nzm=2*B*round(fm)*sn/n #average number of photons\n\n#Result\nprint'Average no of photons = %d photons'%round(zm)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Average no of photons = 864 photons\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.4, page 724"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nzm=864 #average no of photons\nh=6.626*10**-34 #plancks constant\nc=2.998*10**8 #velocity of light\nl1=10**-6 #wavelength\nl2=10**-14 #wavelength\nbt=10**7 \nn=14\n\n\n#Calculation\npo1=(zm*h*c*bt)/(2*l1) #At 10 Mbit s^-1\npo2=(zm*h*c*n*bt)/(2*l2) #At 140 Mbit s^-1\n\n#Result\nprint'Incident optical power (10 Mbit s^-l) = %.1f pW'%(po1*10**12)\nprint'Incident optical power (140 Mbit s^-l) = %.3f W'%po2 #value given in a textbook is incorrect",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Incident optical power (10 Mbit s^-l) = 858.2 pW\nIncident optical power (140 Mbit s^-l) = 1.201 W\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.5, page 726"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nafc=5 #fibre cable attenuation\nai=2 #splice losses\nl=4 #length in Km\naf=3.5+2.5 #connector losses at source and detector resp\n\n#Calculation\nCl=(afc+ai)*l+af #total channel loss\n\n#Result\nprint'Total channel loss = %d dB'%Cl",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total channel loss = 34 dB\n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.6, page 727"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ns=0.6*10**-9 #rms pulse broadening\nL=8 #length in km\nbt=25*10**6 #bit rates\nbt1=150*10**6 #bit rates\n\n#Calculation\nst=s*L #total rms pulse broadening\ndl1=2*(2*st*bt*math.sqrt(2))**4 #without mode coupling\nst1=s*math.sqrt(L) #total rms pulse broadening\ndl2=2*(2*st1*bt*math.sqrt(2))**4 #with mode coupling\ndl3=2*(2*st*bt1*math.sqrt(2))**4 #without mode coupling\ndl4=2*(2*st1*bt1*math.sqrt(2))**4 #with mode coupling\n\n#Result\nprint'(a) For 25 Mbit per sec'\nprint'dispersion\u2013equalization penalty (without mode coupling) = %.2f dB'%dl1\nprint'dispersion\u2013equalization penalty (with mode coupling) = %.2f x 10^-4 dB\\n'%(dl2*10**4)\nprint'(b) For 150 Mbit per sec'\nprint'dispersion\u2013equalization penalty (without mode coupling) = %.2f dB'%dl3\nprint'dispersion\u2013equalization penalty (with mode coupling) = %.2f dB'%dl4",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) For 25 Mbit per sec\ndispersion\u2013equalization penalty (without mode coupling) = 0.03 dB\ndispersion\u2013equalization penalty (with mode coupling) = 4.15 x 10^-4 dB\n\n(b) For 150 Mbit per sec\ndispersion\u2013equalization penalty (without mode coupling) = 34.40 dB\ndispersion\u2013equalization penalty (with mode coupling) = 0.54 dB\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.7, page 731"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nts=8 #rise time for source in ns\ntn=5*ts #for fiber intermodal\ntc=1*ts #for pulse broadening\ntd=6 #for detector\n\n#Calculation\ntsys=1.1*(ts**2+tn**2+tc**2+td**2)**0.5 #total system rise time\nBt=0.7/(tsys*10**-9) #max bit rate\n\n\n#Result\nprint'Bt (Max) = %.1f Mbit per sec'%(Bt/10**6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Bt (Max) = 15.2 Mbit per sec\n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.8, page 732"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npo=-55 #mean power required at the APD receiver at 35 Mbit s^-1\npo1=-44 #mean power required at the APD receiver at 400 Mbit s^-1\npi=-3 #mean power launched from the laser transmitter\nl1=0.4 #cable fiber loss\nl2=0.1 #splice losses\nl3=1 #connector loss \nma=7 #safety margin\na=0.5 \nacr=2\ndl=1.5\n\n#Calculation \nL1=(pi-po-acr-ma)/a #for 35 Mbit s^-1\nL2=(pi-po1-acr-ma)/a #for 400 Mbit s^-1\nL3=(pi-po1-acr-dl-ma)/a #reduction in the maximum possible link\n\n#Result\nprint'(a) Maximum possible link length (operating at 35 Mbit s^-1) = %d km'%L1\nprint'(b) Maximum possible link length (operating at 400 Mbit s^-1) = %d km'%L2\nprint'(c) Reduction in the maximum possible link length = %d km'%L3",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Maximum possible link length (operating at 35 Mbit s^-1) = 86 km\n(b) Maximum possible link length (operating at 400 Mbit s^-1) = 64 km\n(c) Reduction in the maximum possible link length = 61 km\n"
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.9, page 734"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npo=-10 #mean optical power launched into the fiber from the transmitter (100 \u03bcm)\nrs=-41 #receiver sensitivity at 20 Mbit s^-1\nl1=7*2.6 #cabled fiber loss\nl2=6*0.5 #splice losses\nl3=1*1.5 #connector loss \nms=6 #safety margin\n\n#Calculation\nts=po-rs #Total system margin\ntsl=l1+l2+l3+ms #Total system loss\npm=ts-tsl #Excess power margin \n\n#Result\nprint'Total system margin = %d dB'%ts\nprint'Total system loss = %.1f dB'%tsl\nprint'Excess power margin = %.1f dB'%pm\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total system margin = 31 dB\nTotal system loss = 28.7 dB\nExcess power margin = 2.3 dB\n"
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.10, page 740"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nv=5 #output voltage\nh=6.626*10**-34 #plancks constant\nc=2.998*10**8 #velocity of light\nk=1.385*10**-23 #boltzman constant\nt=290 #tempreture in kelvin\nzo=100 #cable impedance\nn=0.7 #quantum efficiency\npi=10**-3 #optical power\nlam=0.85*10**-6 #wavelength\n\n#Calculation\nratio=(v**2*h*c)/(2*k*t*zo*n*pi*lam) #ratio\nratio1=10*math.log10(ratio) #ration in dB\n\n#Result\nprint'Ratio = %d dB'%ratio1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Ratio = 40 dB\n"
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.11, page 744"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nma=0.8 #modulation index\nR=0.5 #responsivity\nb=0.7 #ratio of luminance to composite video\nsnr=3.162*10**5 #SNR\ne=1.602*10**-19 #electron volt\nB=5*10**6 #bandwidth\nK=1.385*10**-23 #boltzman constant \nT=293 #tempreture in kelvin\nFn=1.413\nRl=10**6\n\n#Calculation\na=(2*ma*R*b)**2\nc=snr*2*e*B*R\nd=snr*4*K*T*B*Fn/Rl\nf = (c**2)+(4*a*d)\npo=(c+math.sqrt(f))/(2*a) #average incident optical power \npo1=10*math.log10(po*1000) #in dB\n\n#Result\nprint'Average incident optical power = %.2f uW'%(po*10**6)\nprint' = %.1f dB m'%po1\n\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Average incident optical power = 0.93 uW\n = -30.3 dB m\n"
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.12, page 747"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh=6.626*10**-34 #plancks constant\nc=2.998*10**8 #velocity of light\ne=1.602*10**-19 #1 electron volt\nn=0.6 #p\u2013i\u2013n photodiode quantum efficiency\nma=0.5 #modulation index\nlam=10**-6 #wavelength\nk=1.385*10**-23 #boltzman constant \nt=300 #tempreture in kelvin\nf=4 #amplifier noise figure\nrl=50*10**3 #effective load impedance\nsn=3.162*10**4 #signal to noise ratio\nB=10**7 #bandwidth\n\n#Calculation\na=h*c/(e*n*ma**2*lam)\nb=math.sqrt((8*k*t*f)/rl)\nc=math.sqrt(sn*B)\npo=a*b*c #optical power\npo1=10*math.log10(po*1000) #optical power in dB\n\n#Result\nprint'Optical power, Po = %.2f uW'%(po*10**6)\nprint' = %.1f dBm'%po1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Optical power, Po = 7.58 uW\n = -21.2 dBm\n"
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.13, page 748"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npo=-10 #mean optical power launched into the fiber from the transmitter (100 \u03bcm)\nrs=-25 #receiver sensitivity \nl1=2*3.5 #cable fiber loss\nl2=2*0.7 #splice losses\nl3=1.6 #connector loss \nms=4.0 #safety margin\nafc=3.5\nai=0.7\nacr=1.6\nma=7\n\n#Calculation\nts=po-rs #Total system margi\ntsl=l1+l2+l3+ms #Total system loss\npm=ts-tsl #Excess power margin \nL=((0-rs)-(acr+ma))/(afc+ai)\n\n#Result\nprint'(a) Total system margin = %d dB'%ts\nprint' Total system loss = %.1f dB'%tsl\nprint' Excess power margin = %.1f dB'%pm\nprint'\\n(b) Increase in link length = %.1f Km'%(L)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Total system margin = 15 dB\n Total system loss = 14.0 dB\n Excess power margin = 1.0 dB\n\n(b) Increase in link length = 3.9 Km\n"
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.14, page 750"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nBop=6*10**6\nts=10 #rise time for source in ns\ntn=5*9 #for fiber intermodal\ntc=5*2 #for pulse broadening\ntd=3 #for detector\n\n\n#Calculation\ntsys=0.35/Bop\ntsys1=1.1*(ts**2+tn**2+tc**2+td**2)**0.5 #total system rise time\n\n#Result\nprint'Maximum permitted system rise time = %.1f ns'%(tsys*10**9)\nprint'Total system rise time = %.1f ns'%(tsys1)\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum permitted system rise time = 58.3 ns\nTotal system rise time = 52.0 ns\n"
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.15, page 755"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nfd=400*10**3 #peak frequency deviation\nBa=4*10**3 #bandwidth\n\n#Calculation\nDf=fd/Ba #frequency deviation ratio\nsnr=1.76+(20*math.log10(Df)) #SNR improvement\nBm=2*(Df+1)*Ba #bandwidth of the FM\u2013IM signal \n \n#Result\nprint'(a) SNR improvement = %.2f dB'%snr\nprint'(b) Frequency deviation ratio = %d'%Df\nprint' Bandwidth of FM-IM signal = %d kHz'%(Bm/1000)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) SNR improvement = 41.76 dB\n(b) Frequency deviation ratio = 100\n Bandwidth of FM-IM signal = 808 kHz\n"
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.16, page 757"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nfm=3 #output FM ratio\npm=1 #output PM ratio\n\n#Calculation\nratio=fm/pm #SNR ratio\nratio1=10*math.log10(ratio) #SNR ratio in dB\n\n#Result\nprint'Ratio of output SNR = %.2f dB'%(ratio1)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Ratio of output SNR = 4.77 dB\n"
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.17, page 759"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nto=5*10**-8 #nominal pulse period\nfd=5*10**6 #Peak-to-peak frequency deviation\nM=60 #A PD multiplication factor\nR=0.7 #A PD responsivity\npo=10**-7 #peak optical power at receiver\ntr=12*10**-9 #Total system 10\u201390% rise time\nB=6*10**6 #baseband noise bandwidth\ni=10**-17 #Receiver mean square noise current\n\n\n#Calculation\nsnp=(3*(to*fd*M*R*po)**2)/(i*(2*math.pi*tr*B)**2) #peak-to-peak signal to rms noise ratio\nsnp1=10*math.log10(snp) #in dB\n\n#Result\nprint'Peak-to-peak signal to rms noise ratio = %.1f dB'%snp1\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Peak-to-peak signal to rms noise ratio = 62.1 dB\n"
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.18, page 763"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "%pylab inline\nimport math\nfrom pylab import *\nfrom numpy import *\n\n#Variable declaration\nacr=1 #connector loss in dB\nafc=5 #loss per kilometer in dB\nLbu=0.1 #fiber length between each of the access couplers\nLac=1 #insertion loss\nLtr=10 #loss due to the tap ratio\nLsp=3 #splitting loss\n \n#Calculating, we get two equation in terms of N, no of nodes, i.e C(1,N-1)=(3.5*N)+8.5 and C(star)=4.5+(10*log10(N)) \n\n#For Bus distribution system\n\nfor N in range(1,13,1):\n C=(3.5*N)+8.5;\n a=plot(N,C,'.r')\n \n \n#for Star distribution system\n \nfor N in range(1,30,1):\n C1=4.5+(10*log10(N));\n b=plot(N,C1,'.g')\n \n \n#To show plot in same graph\n#Graphical comparison showing total channel loss against number of nodes\n\nxlabel(\"Number of nodes $N$\")\nylabel(\"Total channel loss $CL$ (dB)\")\ngrid()\nshow(a)\nshow(b)\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Populating the interactive namespace from numpy and matplotlib\n"
- },
- {
- "metadata": {},
- "output_type": "display_data",
- "png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEOCAYAAABmVAtTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XtcVHX6B/DPqCgpJWgxmPprfJmoXIRREbdCpxAsTUQU\nq/UCarLpul1Nrd2Ktq1wU1O77UvXTUqp2LYIWzE1QbEyFbDLamIpWi2gCSheUIHv7w/irCjinMOc\nmTnf+bxfr14xw1yep7N7Hs7znPM9JiGEABEREYA2rg6AiIjcB4sCEREpWBSIiEjBokBERAoWBSIi\nUrAoEBGRwqlFoaqqChMmTED//v0RFBSEL7/8EhUVFYiJiUFg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DhLb6WPBOLArmFhx9+GAMHDsS0adMAAO3atVNaJACU1g8AdOjQ\nQfm5TZs2aN++vfJzbW2t8ruLe/JCCJhMJgghkJSUhBdeeKHZODp16tTs843vvfTzrubiWNu2bavk\ncelntfRzSzH36dMHRUVF+Pe//40//elPiI6OxlNPPdXkNWVlZbjxxhsBAOPHj8fQoUMREhJy1djJ\nM3GmQG7Bz88PEydOxKpVq2AymWA2m3H06FFUVFTg3Llz+Pjjj1UPXo8cOYIdO3YAADIyMhAVFYXo\n6Gi8//77OHbsGICGG5sfOXLkqp8VFRWFrKwsnD17FqdPn0ZWVhaioqLUJ3qFzxo2bBiGDRuGrKws\n1NTUoLq6Wsm5pZhLS0vh7e2NSZMmYe7cuSgsLLzs+3bt2oWBAwcCaDgqCwkJUT6L6FI8UiCXunhH\n/9hjj+HVV18F0HCk8PTTT2PIkCHo3r07goKCmn3PpY8v/rlv37547bXXMH36dAQHB2PWrFnw9vbG\nX/7yF8TGxqK+vh5eXl54/fXX8X//93/NfnYjq9WK5ORkpbU0c+ZMpXXUUrFqLtaWPuuee+5BWFgY\n/P39ld/379//ijF/8803ePzxx5UjpjfeeKPJ923ZsgWpqak4d+4cJkyYAKChlda1a9crxkyejUtn\nExGRgu0jIiJSsCgQEZGCRYGIiBQsCkREpGBRICIiBYsCEREpWBSIiEjBokBERIr/B5KTkPe2LreW\nAAAAAElFTkSuQmCC\n",
- "text": "<matplotlib.figure.Figure at 0x3f7ea90>"
- }
- ],
- "prompt_number": 27
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.19, page 782"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nh=6.626*10**-34 #plancks constant\nc=2.998*10**8 #velocity of light\nlam=1.55*10**-6 #wavelength\nL=100*10**3 #length\nK=4 \nB=1.2*10**9 #bandwidth\nsnr=50 #SNR\na=10**-2.5\npi=10**-3\n\n#Calculation\nLt=(pi*lam*a*L)/(K*h*c*B*snr) #link with a large number of cascaded amplifiers\n\n#Result\nprint'Maximum system length = %d x 10^4 km'%(Lt/10**7)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum system length = 1 x 10^4 km\n"
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.21, page 791"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nb=17 #second-order dispersion coefficient for the latter path\nL2=20 #path length in km\nL1=160.00 #path length in km\ns1=-0.075 #dispersion slope\n\n#Calculation\na=-b*L2\nG=a/L1 #second-order dispersion coefficient\ns2=s1*L1/L2 #chromatic dispersion slope\n\n#Result\nprint'(a) Second-order dispersion coefficient = %.3f ps nm^-1 km^-1'%G \nprint'(b) chromatic dispersion slope = %.1f ps nm^-2 km^-1'%s2",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Second-order dispersion coefficient = -2.125 ps nm^-1 km^-1\n(b) chromatic dispersion slope = -0.6 ps nm^-2 km^-1\n"
- }
- ],
- "prompt_number": 20
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.22, page 798"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nto=70*10**-12 #bit period\nt=6*10**-12 #RZ pulse width\nB2=50*10**-12*10**-12*10**-3 #second-order dispersion coefficient\nL=50*10**3 #amplifier spacing\n\n#Calculation\nqo=0.5*to/t #separation of the soliton pulses \nBt=(2*qo*math.sqrt(B2*L))**-1 #transmission bit rate \n\n#Result\nprint'(a) Separation = %.1f'%qo\nprint'(b) Transmission bit rate = %.2f x 10^9'%(Bt*10**-8)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Separation = 5.8\n(b) Transmission bit rate = 17.14 x 10^9\n"
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 12.23, page 799"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nto=40*10**-12 #bit period\nt=4*10**-12 #RZ pulse width\na=0.2*10**-3 #attenuation coefficient\nB2=1.25*10**-12*10**-12*10**-3 #second-order dispersion coefficient\n\n#Calculation\nqo=0.5*to/t #separation of the soliton pulses \nb=1/(2*qo)\nc=math.sqrt(a/B2)\nBt=b*c #transmission bit rate \n\n#Result\nprint'(a) Separation = %.1f'%qo\nprint'(b) Transmission bit rate = %.2f x 10^10 bit s^-1'%(Bt*10**-10)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Separation = 5.0\n(b) Transmission bit rate = 4.00 x 10^10 bit s^-1\n"
- }
- ],
- "prompt_number": 22
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter13_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter13_1.ipynb
deleted file mode 100755
index 3392b3ce..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter13_1.ipynb
+++ /dev/null
@@ -1,146 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_13"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 13: Optical fiber systems 2: coherent and phase-modulated"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 13.1, page 832"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nf1=150*10**6 #reciever IF\nf2=19*10**9 #output frequency change\n\n\n#Calculation\nm=f1*f2**-1 #maximum tempreture change\n\n#Result\nprint'Maximum tempreture change = %d \u00d7 10^-3 \u00b0C '%round(m*10**3)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum tempreture change = 8 \u00d7 10^-3 \u00b0C \n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 13.2, page 834"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\np=-85.45/10\nn=0.86 #quantum efficiency\nh1=1.54*10**-6 #homodyne receiver operating wavelength\nsn=10**-1.2 #SNR\nh=6.626*10**-34 #plancks constant\nc=2.998*10**8 #velocity of light\n\n\n#Calculation\nps=10**(p) #incoming signal power in dB\nB=(n*ps*sn*h1)/(h*c) #Bandwidth\n\n#Result\nprint'Incoming signal power, Ps = %f nW'%(ps*10**9)\nprint'Operating bandwidth, B = %.1f GHz'%(B*10**-9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Incoming signal power, Ps = 2.851018 nW\nOperating bandwidth, B = 1.2 GHz\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 13.3, page 878"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\npe=4.24 #probability error function\npe2=20 #probability exponential function\n\n\n#Calculation\nNp=pe**2*4 #no of photons\nNp2=pe2*4\nNp3=pe**2/2\n\n#Result\nprint'(a) ASK heterodyne synchronous detection = %d photons'%round(Np)\nprint'(b) ASK heterodyne asynchronous detection = %d photons'%round(Np2)\nprint'(c) pSK homodyne detection = %d photons'%round(Np3)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) ASK heterodyne synchronous detection = 72 photons\n(b) ASK heterodyne asynchronous detection = 80 photons\n(c) pSK homodyne detection = 9 photons\n"
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 13.4, page 881"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\nBt=400*10**6 #FSK signal bit rate\nh=1.55*10**-6 #wavelength\n\n#Calculation\nps=(36*h1*c*Bt)/(h) #optical power\n\n#Result\nprint'Minimum incoming optical power level = %.1f nW'%(ps*10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Minimum incoming optical power level = 1.8 nW\n"
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 13.5, page 883"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nNp=36 #average photons\nNp2=9 #average photons\nh=6.63*10**-34 #plancks constant\nf=3*10**8 #frequency\nBt=50*10**6 #bit rates\nBt2=10**9 #bit rates\nh1=1.55*10**-6 #operating wavelength\na=0.2 #connector loss\n\n\n#Calculation\nPs=Np*h*f*Bt/h1 #in watt\nPs1=10*math.log10(Ps*10**3) #in dB\nma=4-Ps1 #Max. system margin\nmar=ma/a #Max. repeater spacing \n \nPs2=Np*h*f*Bt2/h1 #in watt\nPs3=10*math.log10(Ps2*10**3) #in dB\nma1=4-Ps3 #Max. system margin\nmar1=ma1/a #Max. repeater spacing \n\nPs4=Np2*h*f*Bt/h1 #in watt\nPs5=10*math.log10(Ps4*10**3) #in dB\nma2=4-Ps5 #Max. system margin\nmar2=ma2/a #Max. repeater spacing \n\nPs6=Np2*h*f*Bt2/h1 #in watt\nPs7=10*math.log10(Ps6*10**3) #in dB\nma3=4-Ps7 #Max. system margin\nmar3=ma3/a #Max. repeater spacing \n\n\n#Result\nprint'(a)Max. repeater spacing (50 Mbit s^-1) = %.1f km'%round(mar)\nprint' (1 Gbit s^-1) = %.1f km'%round(mar1)\nprint'\\n(b)Max. repeater spacing (50 Mbit s^-1) = %.1f km'%round(mar2)\nprint' (1 Gbit s^-1) = %.1f km'%round(mar3)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a)Max. repeater spacing (50 Mbit s^-1) = 352.0 km\n (1 Gbit s^-1) = 287.0 km\n\n(b)Max. repeater spacing (50 Mbit s^-1) = 382.0 km\n (1 Gbit s^-1) = 317.0 km\n"
- }
- ],
- "prompt_number": 37
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 13.6, page 888"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nnp=150\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\nbf=20*10**12 #optical bandwidth\nh=1.3*10**-6 #wavelength\n\n#Calculation\ntx=(np*h1*c*bf)/h #transmitter power\n\n#Result\nprint'Minimum transmitter power = %.1f mW' %(tx*1000)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Minimum transmitter power = 0.5 mW\n"
- }
- ],
- "prompt_number": 26
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter13_2.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter13_2.ipynb
deleted file mode 100755
index 3392b3ce..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter13_2.ipynb
+++ /dev/null
@@ -1,146 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_13"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 13: Optical fiber systems 2: coherent and phase-modulated"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 13.1, page 832"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nf1=150*10**6 #reciever IF\nf2=19*10**9 #output frequency change\n\n\n#Calculation\nm=f1*f2**-1 #maximum tempreture change\n\n#Result\nprint'Maximum tempreture change = %d \u00d7 10^-3 \u00b0C '%round(m*10**3)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum tempreture change = 8 \u00d7 10^-3 \u00b0C \n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 13.2, page 834"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\np=-85.45/10\nn=0.86 #quantum efficiency\nh1=1.54*10**-6 #homodyne receiver operating wavelength\nsn=10**-1.2 #SNR\nh=6.626*10**-34 #plancks constant\nc=2.998*10**8 #velocity of light\n\n\n#Calculation\nps=10**(p) #incoming signal power in dB\nB=(n*ps*sn*h1)/(h*c) #Bandwidth\n\n#Result\nprint'Incoming signal power, Ps = %f nW'%(ps*10**9)\nprint'Operating bandwidth, B = %.1f GHz'%(B*10**-9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Incoming signal power, Ps = 2.851018 nW\nOperating bandwidth, B = 1.2 GHz\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 13.3, page 878"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\npe=4.24 #probability error function\npe2=20 #probability exponential function\n\n\n#Calculation\nNp=pe**2*4 #no of photons\nNp2=pe2*4\nNp3=pe**2/2\n\n#Result\nprint'(a) ASK heterodyne synchronous detection = %d photons'%round(Np)\nprint'(b) ASK heterodyne asynchronous detection = %d photons'%round(Np2)\nprint'(c) pSK homodyne detection = %d photons'%round(Np3)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) ASK heterodyne synchronous detection = 72 photons\n(b) ASK heterodyne asynchronous detection = 80 photons\n(c) pSK homodyne detection = 9 photons\n"
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 13.4, page 881"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\nBt=400*10**6 #FSK signal bit rate\nh=1.55*10**-6 #wavelength\n\n#Calculation\nps=(36*h1*c*Bt)/(h) #optical power\n\n#Result\nprint'Minimum incoming optical power level = %.1f nW'%(ps*10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Minimum incoming optical power level = 1.8 nW\n"
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 13.5, page 883"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nNp=36 #average photons\nNp2=9 #average photons\nh=6.63*10**-34 #plancks constant\nf=3*10**8 #frequency\nBt=50*10**6 #bit rates\nBt2=10**9 #bit rates\nh1=1.55*10**-6 #operating wavelength\na=0.2 #connector loss\n\n\n#Calculation\nPs=Np*h*f*Bt/h1 #in watt\nPs1=10*math.log10(Ps*10**3) #in dB\nma=4-Ps1 #Max. system margin\nmar=ma/a #Max. repeater spacing \n \nPs2=Np*h*f*Bt2/h1 #in watt\nPs3=10*math.log10(Ps2*10**3) #in dB\nma1=4-Ps3 #Max. system margin\nmar1=ma1/a #Max. repeater spacing \n\nPs4=Np2*h*f*Bt/h1 #in watt\nPs5=10*math.log10(Ps4*10**3) #in dB\nma2=4-Ps5 #Max. system margin\nmar2=ma2/a #Max. repeater spacing \n\nPs6=Np2*h*f*Bt2/h1 #in watt\nPs7=10*math.log10(Ps6*10**3) #in dB\nma3=4-Ps7 #Max. system margin\nmar3=ma3/a #Max. repeater spacing \n\n\n#Result\nprint'(a)Max. repeater spacing (50 Mbit s^-1) = %.1f km'%round(mar)\nprint' (1 Gbit s^-1) = %.1f km'%round(mar1)\nprint'\\n(b)Max. repeater spacing (50 Mbit s^-1) = %.1f km'%round(mar2)\nprint' (1 Gbit s^-1) = %.1f km'%round(mar3)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a)Max. repeater spacing (50 Mbit s^-1) = 352.0 km\n (1 Gbit s^-1) = 287.0 km\n\n(b)Max. repeater spacing (50 Mbit s^-1) = 382.0 km\n (1 Gbit s^-1) = 317.0 km\n"
- }
- ],
- "prompt_number": 37
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 13.6, page 888"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nnp=150\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\nbf=20*10**12 #optical bandwidth\nh=1.3*10**-6 #wavelength\n\n#Calculation\ntx=(np*h1*c*bf)/h #transmitter power\n\n#Result\nprint'Minimum transmitter power = %.1f mW' %(tx*1000)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Minimum transmitter power = 0.5 mW\n"
- }
- ],
- "prompt_number": 26
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter14_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter14_1.ipynb
deleted file mode 100755
index 80d85c26..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter14_1.ipynb
+++ /dev/null
@@ -1,188 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_14"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 14 : Optical fiber measurements"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.1, page 912"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nv2=10.7 #increased voltage\nv1=2.1 #voltage\nl1=2 #length in Km\nl2=0.002 #length in Km\n\n\n\n#Calculation\na=(10/(l1-l2))*math.log10(v2/v1) #Attenuation\nu=0.2/(l1-l2) #incertainty\n\n#Result\nprint'Attenuation per Km = %.1f dB Km^-1'%a\nprint'Uncertainty = \u00b1 %.1f dB'%u",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Attenuation per Km = 3.5 dB Km^-1\nUncertainty = \u00b1 0.1 dB\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.2, page 917"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nt2=100 #time in sec\nt1=10 #time in sec\nti=0.525 #micro voltage\nto=0.021 #micro voltage\nC=1.64*10**4 #thermal capacity\ntin=4.3*10**-4 #maximum temperature rise\npop=98*10**-3 #optical power\n\n\n#Calculation\ntc=(t2-t1)/(math.log(ti)-math.log(to)) #time constant for the calorimeter\na=(C*tin)/(pop*tc) #absortion loss\n\n#Result\nprint'Absorption loss in dB = %.1f dB Km^-1'%a",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Absorption loss in dB = 2.6 dB Km^-1\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.3, page 919"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nVsc=6.14*10**-9 #voltage\nVop=153.38*10**-6 #voltage without scattering\nl=2.92 #length of fibre in cm\n\n\n#Calculation\na=4.343*10**5*Vsc/(l*Vop) #scattering loss\n\n#Result\nprint'Scattering loss in dB = %.1f dB Km^-1'%a",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Scattering loss in dB = 6.0 dB Km^-1\n"
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.4, page 922"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nt1=12.6*10**-9 #time in sec\nt2=0.3*10**-9 #time in sec\n\n\n\n#Calculation\nt=math.sqrt(t1**2-t2**2)/1.2 #pulse broadening \nBop=0.44/t #bandwidth length product\n\n#Result\nprint'(a) 3dB pulse broadening = %.1f ns km^-1'%(t*10**9)\nprint'(b) Fiber bandwidth\u2013length product = %.1f MHz km'%(Bop*10**-6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) 3dB pulse broadening = 10.5 ns km^-1\n(b) Fiber bandwidth\u2013length product = 41.9 MHz km\n"
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.5, page 940"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nA=6.2 #output pattern size\nD=10 #screen position\n\n#Calculation\nNA=A/math.sqrt(A**2+(4*D**2)) #numerical aperture\n\n#Result\nprint'Numerical aperture = %.2f'%NA",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Numerical aperture = 0.30\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.6, page 942"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nphi=4 #angular velocity\nl=0.1 #length in meter\nwe=300*10**-6 #shadow pulse width\n\n#Calculation\ns=l*phi #shadow velocity\nd=we*s #fibre diameter\n\n#Result\nprint'Outer fibre diameter = %.1f um'%(d*10**6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Outer fibre diameter = 120.0 um\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.7, page 950"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\na=5*10**-3 #optical signal power\nb=20*10**-6 #optical signal power\nc=0.3*10**-3 #optical signal power\nd=800*10**-9 #optical signal power\n\n#Calculation\nadb=10*math.log10(a*10**3) #in dBm\nbdb=10*math.log10(b*10**3) #in dBm\ncdb=10*math.log10(c*10**6) #in dBu\nddb=10*math.log10(d*10**6) #in dBu\n\n#Result\nprint'(a) For a 1 mW reference power level'\nprint' optical signal power of 5 mW = %.2f dBm'%adb\nprint' optical signal power of 20 uW = %.2f dBm'%bdb\nprint'\\n(b) For a 1 \u03bcW reference power level'\nprint' optical signal power of 0.3 mW = %.2f dBu'%cdb #value given in a textbook is incorrect\nprint' optical signal power of 800 nW = %.2f dBu'%ddb",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) For a 1 mW reference power level\n optical signal power of 5 mW = 6.99 dBm\n optical signal power of 20 uW = -16.99 dBm\n\n(b) For a 1 \u03bcW reference power level\n optical signal power of 0.3 mW = 24.77 dBu\n optical signal power of 800 nW = -0.97 dBu\n"
- }
- ],
- "prompt_number": 35
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.8, page 953"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nNA=0.02 #numerical aperture\nyr=0.7*10**-3 #Rayleigh scattering coefficient\nc=2.998*10**8 #speed of light\nwo=50*10**-9 #pulse time\nn1=1.5\n\n#Calculation\np=0.5*(((NA**2)*yr*wo*c)/(4*(n1**3))) #power ratio\npdb=10*math.log10(p*10**3) #in dB\n\n#Result\nprint'Power ratio = %.3f X 10^-7'%(p*10**7) #value given in a textbook is incorrect\nprint'Power ratio in dB = %.1f dB'%pdb #value given in a textbook is incorrect",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Power ratio = 1.555 X 10^-7\nPower ratio in dB = -38.1 dB\n"
- }
- ],
- "prompt_number": 19
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter14_2.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter14_2.ipynb
deleted file mode 100755
index 80d85c26..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter14_2.ipynb
+++ /dev/null
@@ -1,188 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_14"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 14 : Optical fiber measurements"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.1, page 912"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nv2=10.7 #increased voltage\nv1=2.1 #voltage\nl1=2 #length in Km\nl2=0.002 #length in Km\n\n\n\n#Calculation\na=(10/(l1-l2))*math.log10(v2/v1) #Attenuation\nu=0.2/(l1-l2) #incertainty\n\n#Result\nprint'Attenuation per Km = %.1f dB Km^-1'%a\nprint'Uncertainty = \u00b1 %.1f dB'%u",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Attenuation per Km = 3.5 dB Km^-1\nUncertainty = \u00b1 0.1 dB\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.2, page 917"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nt2=100 #time in sec\nt1=10 #time in sec\nti=0.525 #micro voltage\nto=0.021 #micro voltage\nC=1.64*10**4 #thermal capacity\ntin=4.3*10**-4 #maximum temperature rise\npop=98*10**-3 #optical power\n\n\n#Calculation\ntc=(t2-t1)/(math.log(ti)-math.log(to)) #time constant for the calorimeter\na=(C*tin)/(pop*tc) #absortion loss\n\n#Result\nprint'Absorption loss in dB = %.1f dB Km^-1'%a",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Absorption loss in dB = 2.6 dB Km^-1\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.3, page 919"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nVsc=6.14*10**-9 #voltage\nVop=153.38*10**-6 #voltage without scattering\nl=2.92 #length of fibre in cm\n\n\n#Calculation\na=4.343*10**5*Vsc/(l*Vop) #scattering loss\n\n#Result\nprint'Scattering loss in dB = %.1f dB Km^-1'%a",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Scattering loss in dB = 6.0 dB Km^-1\n"
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.4, page 922"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nt1=12.6*10**-9 #time in sec\nt2=0.3*10**-9 #time in sec\n\n\n\n#Calculation\nt=math.sqrt(t1**2-t2**2)/1.2 #pulse broadening \nBop=0.44/t #bandwidth length product\n\n#Result\nprint'(a) 3dB pulse broadening = %.1f ns km^-1'%(t*10**9)\nprint'(b) Fiber bandwidth\u2013length product = %.1f MHz km'%(Bop*10**-6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) 3dB pulse broadening = 10.5 ns km^-1\n(b) Fiber bandwidth\u2013length product = 41.9 MHz km\n"
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.5, page 940"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nA=6.2 #output pattern size\nD=10 #screen position\n\n#Calculation\nNA=A/math.sqrt(A**2+(4*D**2)) #numerical aperture\n\n#Result\nprint'Numerical aperture = %.2f'%NA",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Numerical aperture = 0.30\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.6, page 942"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nphi=4 #angular velocity\nl=0.1 #length in meter\nwe=300*10**-6 #shadow pulse width\n\n#Calculation\ns=l*phi #shadow velocity\nd=we*s #fibre diameter\n\n#Result\nprint'Outer fibre diameter = %.1f um'%(d*10**6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Outer fibre diameter = 120.0 um\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.7, page 950"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\na=5*10**-3 #optical signal power\nb=20*10**-6 #optical signal power\nc=0.3*10**-3 #optical signal power\nd=800*10**-9 #optical signal power\n\n#Calculation\nadb=10*math.log10(a*10**3) #in dBm\nbdb=10*math.log10(b*10**3) #in dBm\ncdb=10*math.log10(c*10**6) #in dBu\nddb=10*math.log10(d*10**6) #in dBu\n\n#Result\nprint'(a) For a 1 mW reference power level'\nprint' optical signal power of 5 mW = %.2f dBm'%adb\nprint' optical signal power of 20 uW = %.2f dBm'%bdb\nprint'\\n(b) For a 1 \u03bcW reference power level'\nprint' optical signal power of 0.3 mW = %.2f dBu'%cdb #value given in a textbook is incorrect\nprint' optical signal power of 800 nW = %.2f dBu'%ddb",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) For a 1 mW reference power level\n optical signal power of 5 mW = 6.99 dBm\n optical signal power of 20 uW = -16.99 dBm\n\n(b) For a 1 \u03bcW reference power level\n optical signal power of 0.3 mW = 24.77 dBu\n optical signal power of 800 nW = -0.97 dBu\n"
- }
- ],
- "prompt_number": 35
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 14.8, page 953"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nNA=0.02 #numerical aperture\nyr=0.7*10**-3 #Rayleigh scattering coefficient\nc=2.998*10**8 #speed of light\nwo=50*10**-9 #pulse time\nn1=1.5\n\n#Calculation\np=0.5*(((NA**2)*yr*wo*c)/(4*(n1**3))) #power ratio\npdb=10*math.log10(p*10**3) #in dB\n\n#Result\nprint'Power ratio = %.3f X 10^-7'%(p*10**7) #value given in a textbook is incorrect\nprint'Power ratio in dB = %.1f dB'%pdb #value given in a textbook is incorrect",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Power ratio = 1.555 X 10^-7\nPower ratio in dB = -38.1 dB\n"
- }
- ],
- "prompt_number": 19
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter15.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter15.ipynb
deleted file mode 100755
index 06ca7e54..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter15.ipynb
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_15"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 15:- Optical networks"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Theoretical chapter",
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter15_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter15_1.ipynb
deleted file mode 100755
index 06ca7e54..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter15_1.ipynb
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_15"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 15:- Optical networks"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Theoretical chapter",
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter15_2.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter15_2.ipynb
deleted file mode 100755
index 06ca7e54..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter15_2.ipynb
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_15"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 15:- Optical networks"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Theoretical chapter",
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter1_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter1_1.ipynb
deleted file mode 100755
index 76fe396c..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter1_1.ipynb
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_1"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 1 :- Introduction"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "# Theortical Chapter",
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter1_2.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter1_2.ipynb
deleted file mode 100755
index 76fe396c..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter1_2.ipynb
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_1"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 1 :- Introduction"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "# Theortical Chapter",
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter2_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter2_1.ipynb
deleted file mode 100755
index 81d67649..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter2_1.ipynb
+++ /dev/null
@@ -1,251 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_2"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 2 : Optical fiber waveguides\n"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.1, page 19"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nn1=1.50 #core refractive index\nn2=1.47 #cladding refractive index\n\n#Calculation\nphic=math.asin(n2/n1)*180/(math.pi) #critical angle at core cladding\nNA=math.sqrt(n1**2-n2**2) #numerical aperture\nphia=math.asin(NA)*180/math.pi #acceptance angle in air\n\n#Result\nprint'(a) Critical angle at the core-cladding = %.1f\u00b0'%phic\nprint'(b) NA for the fiber = %.2f'%NA\nprint'(c) Acceptance angle in air for the fiber = %.1f\u00b0'%phia",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Critical angle at the core-cladding = 78.5\u00b0\n(b) NA for the fiber = 0.30\n(c) Acceptance angle in air for the fiber = 17.4\u00b0\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.2, page 20"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ndelta=0.01 #relative refractive index = 1%\nn1=1.46 #core index\n\n#Calculation\nNA=n1*math.sqrt(2*delta) #numerical aperture\nzeta=math.pi*(NA)**2 #solid acceptance angle\nn12=1-delta #ratio of(n2/n1)\nphic=math.asin(n12)*180/math.pi #critical angle\n\n#Result\nprint'Numerical aperture (NA) = %.2f'%NA\nprint'Solid acceptance angle = ',round((zeta),2),'rad'\nprint'Critical angle at core-cladding = %.1f\u00b0'%phic",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Numerical aperture (NA) = 0.21\nSolid acceptance angle = 0.13 rad\nCritical angle at core-cladding = 81.9\u00b0\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.3, page 23"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#variable declaration\nNA=0.4 #numerical aperture\ny=50*math.pi/180 #angle between projection of the ray and radius of fibre of core (radians)\n\n#Calculation\nphia1=math.asin(NA)*180/math.pi #acceptance angle for meridional rays\nphia2=math.asin(NA/(math.cos(y)))*180/math.pi #acceptance angle for skew rays\n\n#Result\nprint'Acceptance angle for meridional rays = %.1f\u00b0'%phia1\nprint'Acceptance angle for skew rays = %.1f\u00b0'%phia2\nprint\"Therefore, acceptance angle for the skew rays is about 15\u00b0 greater thanthe corresponding angle for meridional rays\"",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Acceptance angle for meridional rays = 23.6\u00b0\nAcceptance angle for skew rays = 38.5\u00b0\nTherefore, acceptance angle for the skew rays is about 15\u00b0 greater thanthe corresponding angle for meridional rays\n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.4, page 45"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#variable declaration\nn1=1.48 #core index\na=40*10**-6 #radius of core\ndelta=1.5/100 #relative refractive index = 1.5%\nh=0.85*10**-6 #operating wavelength\n\n#Calculation \nV=(2*math.pi*a*n1*math.sqrt(2*delta))/h #normalized frequency for the fiber\nMs=(V**2)/2 #no of guided modes\n\n#Result\nprint 'Normalised frequency, V = %.1f'%V\nprint'Total number of guided modes, Ms = %d'%round(Ms)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Normalised frequency, V = 75.8\nTotal number of guided modes, Ms = 2872\n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.5, page 54"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#variable declaration\nNA=0.2 #numerical aperture\na=25*10**-6 #radius of core\nh=1*10**-6 #operating wavelength\n\n#Calculation \nV=(2*math.pi*a*NA)/h #normalized frequency for the fiber\nMg=(V**2)/4 #no of guided modes gor parabolic profile\n\n#Result\nprint 'Normalised frequency, V = %.1f'%V\nprint'Total number of guided modes, Mg = %d'%round(Mg)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Normalised frequency, V = 31.4\nTotal number of guided modes, Mg = 247\n"
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.6, page 55"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n#variable declaration\nn1=1.48 #core index \nh=0.85*10**-6 #operating wavelength\nV=2.4 #normalized frequency for the fiber\ndelta=1.5/100 #relative refractive index (RRI)= 1.5%\ndelta1=delta/10 #RRI difference reduced by 10\n\n#Calculation\na=(V*h)/(2*math.pi*n1*math.sqrt(2*delta)) #radius of core\nd=2*a\na1=(V*h)/(2*math.pi*n1*math.sqrt(2*delta1)) #new radius of core\nd1=2*a1\n\n#Result\nprint 'Maximum core diameter for relative refractive index of 1.5 percent = ',round((d*10**6),2),\"um\"\nprint \"Maximum core diameter for relative refractive index = \",round(d1*10**6),\"um\"",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum core diameter for relative refractive index of 1.5 percent = 2.53 um\nMaximum core diameter for relative refractive index = 8.0 um\n"
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.7, page 2.7"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n#variable declaration\nn1=1.5 #core index \ndelta=0.01 #relative refractive index (RRI)= 1%\nh=1.3*10**-6 #operating wavelength\nalph=2\n\n#Calculation\nV=(2.4)*math.sqrt(1+(2/alph)) #normalized frequency for the fiber\na=(V*h)/(2*math.pi*n1*math.sqrt(2*delta)) #radius of core\nd=2*a\n\n#Result\nprint \"Maximum core diameter for relative refractive index = \",round(d*10**6,1),\"um\"",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum core diameter for relative refractive index = 6.6 um\n"
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.8, page 60"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n#Variable declaration\na=4.5*10**-6 #radius of core\nn1=1.46 #core index \ndelta=0.25/100 #relative refractive index (RRI)= 0.25%\n\n\n#Calculation \nhc=(2*math.pi*a*n1*math.sqrt(2*delta))/2.405 #cutoff wavelength\n\n\n#Result\nprint 'Fibre is single moded to a wavelength = ',round(hc*10**9),'nm'",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Fibre is single moded to a wavelength = 1214.0 nm\n"
- }
- ],
- "prompt_number": 24
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.10, page 69"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n#Variable declaration\nwo=5.8*10**-6 #spot size \nV=2.2 #normalized frequency\n\n#Calculation \na=wo/((0.65+1.619*V**(-1.5))+(2.879*V**-6)) #radius of the core\nd=2*a\n\n#Result\nprint'Fibre core diameter = ',round(d*10**6,1),\"um\"\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Fibre core diameter = 9.9 um\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.11, page 73"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n#Variable declaration\nh=1.30*10**-6 #operating wavelength \nhc=1.08*10**-6 #cutoff wavelength\ntheta=12 #in angle (degree)\n\n#Calculation \naeff=3.832*h/(2*math.pi*math.sin(theta)) #effective core radius\nVeff=2.405*hc/h #effective normalised frequency\nwo=3.81*10**-6*(0.6043+(1.755*Veff**-1.5)+(2.78*Veff**-6)) #spot size\n\n#Result\nprint 'Spot size = ',round(wo*10**6,2),'um'",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Spot size = 4.84 um\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.12, page 74"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nwo=5.2*10**-6 #spot size\nn1=1.485 #core index\nhc=1.190*10**-6 #cutoff wavelength\n\n#Calculation \naesi=1.820*wo #ESI core radius\nD=(0.293/n1**2)*(hc/aesi)**2 #ESI relative index difference\n\n#Result\nprint'ESI relative refractive index difference = ',round(D*10**2,2),'%'",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "ESI relative refractive index difference = 0.21 %\n"
- }
- ],
- "prompt_number": 22
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter2_2.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter2_2.ipynb
deleted file mode 100755
index 81d67649..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter2_2.ipynb
+++ /dev/null
@@ -1,251 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_2"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 2 : Optical fiber waveguides\n"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.1, page 19"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nn1=1.50 #core refractive index\nn2=1.47 #cladding refractive index\n\n#Calculation\nphic=math.asin(n2/n1)*180/(math.pi) #critical angle at core cladding\nNA=math.sqrt(n1**2-n2**2) #numerical aperture\nphia=math.asin(NA)*180/math.pi #acceptance angle in air\n\n#Result\nprint'(a) Critical angle at the core-cladding = %.1f\u00b0'%phic\nprint'(b) NA for the fiber = %.2f'%NA\nprint'(c) Acceptance angle in air for the fiber = %.1f\u00b0'%phia",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Critical angle at the core-cladding = 78.5\u00b0\n(b) NA for the fiber = 0.30\n(c) Acceptance angle in air for the fiber = 17.4\u00b0\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.2, page 20"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ndelta=0.01 #relative refractive index = 1%\nn1=1.46 #core index\n\n#Calculation\nNA=n1*math.sqrt(2*delta) #numerical aperture\nzeta=math.pi*(NA)**2 #solid acceptance angle\nn12=1-delta #ratio of(n2/n1)\nphic=math.asin(n12)*180/math.pi #critical angle\n\n#Result\nprint'Numerical aperture (NA) = %.2f'%NA\nprint'Solid acceptance angle = ',round((zeta),2),'rad'\nprint'Critical angle at core-cladding = %.1f\u00b0'%phic",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Numerical aperture (NA) = 0.21\nSolid acceptance angle = 0.13 rad\nCritical angle at core-cladding = 81.9\u00b0\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.3, page 23"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#variable declaration\nNA=0.4 #numerical aperture\ny=50*math.pi/180 #angle between projection of the ray and radius of fibre of core (radians)\n\n#Calculation\nphia1=math.asin(NA)*180/math.pi #acceptance angle for meridional rays\nphia2=math.asin(NA/(math.cos(y)))*180/math.pi #acceptance angle for skew rays\n\n#Result\nprint'Acceptance angle for meridional rays = %.1f\u00b0'%phia1\nprint'Acceptance angle for skew rays = %.1f\u00b0'%phia2\nprint\"Therefore, acceptance angle for the skew rays is about 15\u00b0 greater thanthe corresponding angle for meridional rays\"",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Acceptance angle for meridional rays = 23.6\u00b0\nAcceptance angle for skew rays = 38.5\u00b0\nTherefore, acceptance angle for the skew rays is about 15\u00b0 greater thanthe corresponding angle for meridional rays\n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.4, page 45"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#variable declaration\nn1=1.48 #core index\na=40*10**-6 #radius of core\ndelta=1.5/100 #relative refractive index = 1.5%\nh=0.85*10**-6 #operating wavelength\n\n#Calculation \nV=(2*math.pi*a*n1*math.sqrt(2*delta))/h #normalized frequency for the fiber\nMs=(V**2)/2 #no of guided modes\n\n#Result\nprint 'Normalised frequency, V = %.1f'%V\nprint'Total number of guided modes, Ms = %d'%round(Ms)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Normalised frequency, V = 75.8\nTotal number of guided modes, Ms = 2872\n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.5, page 54"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#variable declaration\nNA=0.2 #numerical aperture\na=25*10**-6 #radius of core\nh=1*10**-6 #operating wavelength\n\n#Calculation \nV=(2*math.pi*a*NA)/h #normalized frequency for the fiber\nMg=(V**2)/4 #no of guided modes gor parabolic profile\n\n#Result\nprint 'Normalised frequency, V = %.1f'%V\nprint'Total number of guided modes, Mg = %d'%round(Mg)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Normalised frequency, V = 31.4\nTotal number of guided modes, Mg = 247\n"
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.6, page 55"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n#variable declaration\nn1=1.48 #core index \nh=0.85*10**-6 #operating wavelength\nV=2.4 #normalized frequency for the fiber\ndelta=1.5/100 #relative refractive index (RRI)= 1.5%\ndelta1=delta/10 #RRI difference reduced by 10\n\n#Calculation\na=(V*h)/(2*math.pi*n1*math.sqrt(2*delta)) #radius of core\nd=2*a\na1=(V*h)/(2*math.pi*n1*math.sqrt(2*delta1)) #new radius of core\nd1=2*a1\n\n#Result\nprint 'Maximum core diameter for relative refractive index of 1.5 percent = ',round((d*10**6),2),\"um\"\nprint \"Maximum core diameter for relative refractive index = \",round(d1*10**6),\"um\"",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum core diameter for relative refractive index of 1.5 percent = 2.53 um\nMaximum core diameter for relative refractive index = 8.0 um\n"
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.7, page 2.7"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n#variable declaration\nn1=1.5 #core index \ndelta=0.01 #relative refractive index (RRI)= 1%\nh=1.3*10**-6 #operating wavelength\nalph=2\n\n#Calculation\nV=(2.4)*math.sqrt(1+(2/alph)) #normalized frequency for the fiber\na=(V*h)/(2*math.pi*n1*math.sqrt(2*delta)) #radius of core\nd=2*a\n\n#Result\nprint \"Maximum core diameter for relative refractive index = \",round(d*10**6,1),\"um\"",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum core diameter for relative refractive index = 6.6 um\n"
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.8, page 60"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n#Variable declaration\na=4.5*10**-6 #radius of core\nn1=1.46 #core index \ndelta=0.25/100 #relative refractive index (RRI)= 0.25%\n\n\n#Calculation \nhc=(2*math.pi*a*n1*math.sqrt(2*delta))/2.405 #cutoff wavelength\n\n\n#Result\nprint 'Fibre is single moded to a wavelength = ',round(hc*10**9),'nm'",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Fibre is single moded to a wavelength = 1214.0 nm\n"
- }
- ],
- "prompt_number": 24
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.10, page 69"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n#Variable declaration\nwo=5.8*10**-6 #spot size \nV=2.2 #normalized frequency\n\n#Calculation \na=wo/((0.65+1.619*V**(-1.5))+(2.879*V**-6)) #radius of the core\nd=2*a\n\n#Result\nprint'Fibre core diameter = ',round(d*10**6,1),\"um\"\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Fibre core diameter = 9.9 um\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.11, page 73"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n#Variable declaration\nh=1.30*10**-6 #operating wavelength \nhc=1.08*10**-6 #cutoff wavelength\ntheta=12 #in angle (degree)\n\n#Calculation \naeff=3.832*h/(2*math.pi*math.sin(theta)) #effective core radius\nVeff=2.405*hc/h #effective normalised frequency\nwo=3.81*10**-6*(0.6043+(1.755*Veff**-1.5)+(2.78*Veff**-6)) #spot size\n\n#Result\nprint 'Spot size = ',round(wo*10**6,2),'um'",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Spot size = 4.84 um\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2.12, page 74"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nwo=5.2*10**-6 #spot size\nn1=1.485 #core index\nhc=1.190*10**-6 #cutoff wavelength\n\n#Calculation \naesi=1.820*wo #ESI core radius\nD=(0.293/n1**2)*(hc/aesi)**2 #ESI relative index difference\n\n#Result\nprint'ESI relative refractive index difference = ',round(D*10**2,2),'%'",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "ESI relative refractive index difference = 0.21 %\n"
- }
- ],
- "prompt_number": 22
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter3.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter3.ipynb
deleted file mode 100755
index 3778a224..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter3.ipynb
+++ /dev/null
@@ -1,322 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_3"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 3 : Transmission characteristics of\noptical fibers"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.1, page 89"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nPi=120*10**-6 #mean i/p power in uW\nPo=3*10**-6 #mean o/p power in uW\nL=8 #length of fibre in Km\na1=2 #loss in dB\nL1=10 #length of fibre in Km\nloss=9 #loss in dB\n\n#Calculation \nSA=10*math.log10(Pi/Po) #overall signal attenuation\na=SA/L #signal attenuation per kilometer\nal=a1*L1\nSA1=al+loss #signal attenuation for the 10KM link\nP=10**(2.9) #i/o power ratio, 2.9 is numeric value\n\n\n#Result\nprint'Overall signal attenuation = ',round(SA),'dB'\nprint'Signal attenuation per kilometer = ',round(a),'per KM'\nprint'Overall signal attenuation for the 10KM link = ',round(SA1),'dB'\nprint'Numeric value for i/o power ratio = %.1f' %P",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Overall signal attenuation = 16.0 dB\nSignal attenuation per kilometer = 2.0 per KM\nOverall signal attenuation for the 10KM link = 29.0 dB\nNumeric value for i/o power ratio = 794.3\n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.2, page 96"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nTf=1400 #tempreture in kelvin\nK=1.381*10**-23 #Boltzmann\u2019s constant\nBc=7*10**-11 #isothermal compressibility\nn=1.46 #refractive index\np=0.286 #refractive index\nh1=0.63*10**-6 #wavelength\nh2=10**-6 #wavelength\nh3=1.3*10**-6 #wavelength\nL=10**3 #length in km\n\n#Calculation \na=(8*math.pi**3*n**8*p**2*Bc*K*Tf)/3\nyr=a/h1**4 #Rayleigh scattering coefficient \nLk=math.exp(-yr*L) #transmission loss factor\nAt=10*math.log10(Lk**-1) #attenuation due to Rayleigh scattering\nyr1=a/h2**4 #Rayleigh scattering coefficient \nLk1=math.exp(-yr1*L) #transmission loss factor\nAt1=10*math.log10(Lk1**-1) #attenuation due to Rayleigh scattering\nyr2=a/h3**4 #Rayleigh scattering coefficient \nLk2=math.exp(-yr2*L) #transmission loss factor\nAt2=10*math.log10(Lk2**-1) #attenuation due to Rayleigh scattering\n\n#Result\nprint'Attenuation due to Rayleigh scattering (in 0.63 \u03bcm)= %.1f dB km^-1'%(At)\nprint'Attenuation due to Rayleigh scattering (in 1.0 \u03bcm)= %.1f dB km^-1'%(At1)\nprint'Attenuation due to Rayleigh scattering (in 1.30 \u03bcm)= %.1f dB km^-1'%(At2)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Attenuation due to Rayleigh scattering (in 0.63 \u03bcm)= 5.2 dB\nAttenuation due to Rayleigh scattering (in 1.0 \u03bcm)= 0.8 dB\nAttenuation due to Rayleigh scattering (in 1.30 \u03bcm)= 0.3 dB\n"
- }
- ],
- "prompt_number": 20
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.3, page 99"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nd=6 #diameter in \u03bcm\nh=1.3 #wavelength in \u03bcm\nadb=0.5 #attenuation in dB\nv=0.6\n\n#Calculation \nPb=4.4*10**-3*d**2*h**2*adb*v #for SBS\nPr=5.9*10**-2*d**2*h*adb #for SRS\n\n#result\nprint'Threshold optical power for SBS = %.1f mW'%(Pb*1000)\nprint 'Threshold optical power for SRS = %.2f W'%Pr\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Threshold optical power for SBS = 80.3 mW\nThreshold optical power for SRS = 1.38 W\n"
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.4, page 101"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration \nn1=1.5 #refractive index\nh=0.82*10**-6 #operating wavelength\ndelta=0.03 #relative refractive index difference \ndelta1=0.003 #relative refractive index difference\nh1=1.55*10**-6 #operating wavelength\na=4*10**-6 #radius of core\n\n#Calculation\nn2=(n1**2)-(2*delta*n1**2) #refractive index\nRc=(3*n1**2*h)/(4*math.pi*(n1**2-n2)**0.5) #multimode fiber critical radius of curvature\nn21=(n1**2)-(2*delta1*n1**2) #refractive index \nhc=(2*math.pi*a*n1*math.sqrt(2*delta1))/(2.405) #cutoff wavelength for the single-mode fiber\nb=20*h1/math.sqrt(0.043)\nc=(2.748-(0.996*h1/hc))**-3\nRcs=b*c #critical radius of curvature for the single-mode\n\n#Result\nprint'Multimode fiber critical radius of curvature = %.2f um'%(Rc*10**6) #value given in the textbook is wrong \nprint'Single-mode fiber critical radius of curvature = %.2f um'%(Rcs*10**3) #value given in the textbook is wrong",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Multimode fiber critical radius of curvature = 1.20 um\nSingle-mode fiber critical radius of curvature = 0.05 um\n"
- }
- ],
- "prompt_number": 36
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.5, page 109"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration \nt=0.1*10**-6 #total pulse time \nd=15 #distance in Km\n\n#Calculation\nBt=1/(2*t) #Maximum Bandwidth\nD=t/d #Pulse Dispersion\nBop=Bt*d #Bandwidth-length product\n\n#Result\nprint'Maximum Bandwidth = %d Mhz'%(Bt/10**6)\nprint'Pulse Dispersion = %.2f ns per Km'%(D*10**9)\nprint'Bandwidth-length product = %d Mhz Km'%(Bop/10**6)\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum Bandwidth = 5 Mhz\nPulse Dispersion = 6.67 ns per Km\nBandwidth-length product = 75 Mhz Km\n"
- }
- ],
- "prompt_number": 51
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.6, page 111"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nb=0.025 #material dispersion \nc=2.998 #speed of light (x 10^8)\nh=85*10**6 #wavelength dispersion parameter\n\n\n#Calculation\nM=b/(c*h) #Material dispersion parameter\ns=M*20 #RMS pulse broadening (1 Km)\n\n#Result\nprint'Material dispersion parameter = %.1f ps n/m K/m'%(M*10**12)\nprint'RMS pulse broadening (1 Km) = %.2f ns K/m'%(s*10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Material dispersion parameter = 98.1 ps n/m K/m\nRMS pulse broadening (1 Km) = 1.96 ns K/m\n"
- }
- ],
- "prompt_number": 55
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.7, page 112"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh=0.85*10**-6 #wavelength \nb=0.0012 #relative spectral width\nM=98.1*10**-12 #material dispersion parameter\n\n#Calculation\nsh=b*h #relative spectral width\nsm=sh*M*10**9 #RMS pulse braodening\n\n#Result\nprint'RMS pulse braodening (1 Km) = %.2f ns K/m'%(sm*10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "RMS pulse braodening (1 Km) = 0.10 ns K/m\n"
- }
- ],
- "prompt_number": 66
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.8, page 117"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nL=6000 #optical link\nn1=1.5 #core refractive index\ndelt=0.01 #relative refractive index difference\nc=2.998*10**8 #speed of light\n\n\n#Calculation\nTs=(L*n1*delt)/c #Delay difference\nsc=(L*n1*delt)/(2*math.sqrt(3)*c) #RMS pulse broadening\nBt=1/(2*Ts)\nBtm=0.2/sc #Maximum bit rate using RMS pulse broadening\nBop=Btm*L #Bandwidth-length product\n\n#Result\nprint'(a) Delay difference = %d ns' %(Ts*10**9)\nprint'(b) RMS pulse broadening = %.1f ns' %(sc*10**9)\nprint'(c) Maximum bit rate using RMS pulse broadening = %.1f Mbit/s'%(Btm/10**6)\nprint'(d) Bandwidth-length product = %.1f Mhz km'%(Bop/10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Delay difference = 300 ns\n(b) RMS pulse broadening = 86.7 ns\n(c) Maximum bit rate using RMS pulse broadening = 2.3 Mbit/s\n(d) Bandwidth-length product = 13.8 Mhz km\n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.9, page 121"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nsc=86.7 #RMS pulse broadening\nL1=6 #optical link\nL=10**3 #for 1 Km\nn1=1.5 #core refractive index\ndelt=0.01 #relative refractive index difference\nc=3*10**8 #speed of light\n\n#Calculation\nd=sc/L1 #for multimode step index fiber\nsg=(L*n1*delt**2)/(20*math.sqrt(3)*c) #gradient index fiber\n\n#Result\nprint'RMS pulse broadening for multimode step index fiber = %.1f ns K/m'%(d)\nprint'RMS pulse broadening for gradient index fiber = %.1f ps K/m'%(sg*10**12)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "RMS pulse broadening for multimode step index fiber = 14.5 ns K/m\nRMS pulse broadening for gradient index fiber = 14.4 ps K/m\n"
- }
- ],
- "prompt_number": 18
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.10, page 125"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nsh=50 #rms spectral width\nL=1 #1 Km\nM=250*10**-12 #material dispersion parameter\nL1=10**3 \nNA=0.3 #numerical aperture\nn1=1.45 #refractive index\nc=2.998*10**8 #speed of light\n\n#Calculation\nsm=sh*L*M #rms pulse broadening\nss=(L1*NA**2)/(4*math.sqrt(3)*n1*c) #rms pulse broadening per kilometer\nst=math.sqrt(sm**2+ss**2) #total rms pulse broadening per kilometer\nBop=0.2/st #bandwidth\u2013length product\n\n#Result\nprint'(a) Total RMS pulse broadening per Km = %.1f ns K/m'%(st*10**9)\nprint'(b) Bandwidth length product = %.1f Mhz Km'%(Bop*10**-6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Total RMS pulse broadening per Km = 32.4 ns K/m\n(b) Bandwidth length product = 6.2 Mhz Km\n"
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.11, page 131"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "\n#Variable declaration\nh=1280 #wavelength in nm\nS0=0.09*10**-12 #dispersion slope\nh0=1310 #zero dispersion wavlength in nm\nh1=1550 #wavelength in nm\nDm=13.5*10**-12 #material dispersion wavelength in m\nDp=0.4*10**-12 #profile dispersion wavelength in m\n\n#Calculation\na=h*S0/4\nb=1-((h0*h**-1)**4)\nDt=a*b\nDt1=(h1*S0/4)*(1-(h0*h1**-1)**4)\nDw=Dt1-(Dm+Dp)\n\n#Result\nprint'Total first order dispersion (1280 nm) = %.1f nm^-1 km^-1'%(Dt*10**12)\nprint'Total first order dispersion (1550 nm) = %.1f ps n/m K/m'%(Dt1*10**12)\nprint'Waveguide dispersion at wavelength 1.55um = %.1f ps n/m K/m'%(Dw*10**12)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total first order dispersion (1280 nm) = -2.8 nm^-1 km^-1\nTotal first order dispersion (1550 nm) = 17.1 ps n/m K/m\nWaveguide dispersion at wavelength 1.55um = 3.2 ps n/m K/m\n"
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.12, page 143"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh=0.9*10**-6 #peak wavelength \nLb=0.09 #beat length\ns=10**-9 #spectral linewidth\n\n\n#Calculation\nBf=h/Lb #modal birefringence\nLbc=h**2/(Bf*s) #coherence length\nBxy=(2*math.pi)/Lb #difference between propagation constant\n\n#Result\nprint'Modal birefringence, Bf = %.1f x 10^-5' %(Bf*10**5)\nprint'Coherence length, Lf = %.1f m' %Lbc\nprint'Difference between propagation constant = %.1f' %Bxy",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Modal birefringence, Bf = 1.0 x 10^-5\nCoherence length, Lf = 81.0 m\nDifference between propagation constant = 69.8\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.13, page 144"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nh=1.3*10**-6 #fibers operating wavelength\nLs=0.7*10**-3 #beat length\nL=80 #beat length\n\n#Calculation\nBf=h/Ls #Fiber birefringence (0.7mm)\nBf1=h/L #Fiber birefringence (80m)\n\n#Result\nprint'Fiber birefringence (0.7mm) = %.2f x 10^-3'%(Bf*1000)\nprint'Fiber birefringence (80m) = %.2f x 10^-8'%(Bf1*10**8)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Fiber birefringence (0.7mm) = 1.86 x 10^-3\nFiber birefringence (80m) = 1.62 x 10^-8\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.14, page 150"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nL=3.5*10**3 #length of fiber\na=2*10**-3 #tanh(h*L)\n\n\n#Calculation\nh=a/L #mode coupling parameter \n\n#Result\nprint'Mode coupling parameter = %.1f x 10^-7 m^-1'%(h*10**7)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Mode coupling parameter = 5.7 x 10^-7 m^-1\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "",
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter3_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter3_1.ipynb
deleted file mode 100755
index 3778a224..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter3_1.ipynb
+++ /dev/null
@@ -1,322 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_3"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 3 : Transmission characteristics of\noptical fibers"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.1, page 89"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nPi=120*10**-6 #mean i/p power in uW\nPo=3*10**-6 #mean o/p power in uW\nL=8 #length of fibre in Km\na1=2 #loss in dB\nL1=10 #length of fibre in Km\nloss=9 #loss in dB\n\n#Calculation \nSA=10*math.log10(Pi/Po) #overall signal attenuation\na=SA/L #signal attenuation per kilometer\nal=a1*L1\nSA1=al+loss #signal attenuation for the 10KM link\nP=10**(2.9) #i/o power ratio, 2.9 is numeric value\n\n\n#Result\nprint'Overall signal attenuation = ',round(SA),'dB'\nprint'Signal attenuation per kilometer = ',round(a),'per KM'\nprint'Overall signal attenuation for the 10KM link = ',round(SA1),'dB'\nprint'Numeric value for i/o power ratio = %.1f' %P",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Overall signal attenuation = 16.0 dB\nSignal attenuation per kilometer = 2.0 per KM\nOverall signal attenuation for the 10KM link = 29.0 dB\nNumeric value for i/o power ratio = 794.3\n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.2, page 96"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nTf=1400 #tempreture in kelvin\nK=1.381*10**-23 #Boltzmann\u2019s constant\nBc=7*10**-11 #isothermal compressibility\nn=1.46 #refractive index\np=0.286 #refractive index\nh1=0.63*10**-6 #wavelength\nh2=10**-6 #wavelength\nh3=1.3*10**-6 #wavelength\nL=10**3 #length in km\n\n#Calculation \na=(8*math.pi**3*n**8*p**2*Bc*K*Tf)/3\nyr=a/h1**4 #Rayleigh scattering coefficient \nLk=math.exp(-yr*L) #transmission loss factor\nAt=10*math.log10(Lk**-1) #attenuation due to Rayleigh scattering\nyr1=a/h2**4 #Rayleigh scattering coefficient \nLk1=math.exp(-yr1*L) #transmission loss factor\nAt1=10*math.log10(Lk1**-1) #attenuation due to Rayleigh scattering\nyr2=a/h3**4 #Rayleigh scattering coefficient \nLk2=math.exp(-yr2*L) #transmission loss factor\nAt2=10*math.log10(Lk2**-1) #attenuation due to Rayleigh scattering\n\n#Result\nprint'Attenuation due to Rayleigh scattering (in 0.63 \u03bcm)= %.1f dB km^-1'%(At)\nprint'Attenuation due to Rayleigh scattering (in 1.0 \u03bcm)= %.1f dB km^-1'%(At1)\nprint'Attenuation due to Rayleigh scattering (in 1.30 \u03bcm)= %.1f dB km^-1'%(At2)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Attenuation due to Rayleigh scattering (in 0.63 \u03bcm)= 5.2 dB\nAttenuation due to Rayleigh scattering (in 1.0 \u03bcm)= 0.8 dB\nAttenuation due to Rayleigh scattering (in 1.30 \u03bcm)= 0.3 dB\n"
- }
- ],
- "prompt_number": 20
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.3, page 99"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nd=6 #diameter in \u03bcm\nh=1.3 #wavelength in \u03bcm\nadb=0.5 #attenuation in dB\nv=0.6\n\n#Calculation \nPb=4.4*10**-3*d**2*h**2*adb*v #for SBS\nPr=5.9*10**-2*d**2*h*adb #for SRS\n\n#result\nprint'Threshold optical power for SBS = %.1f mW'%(Pb*1000)\nprint 'Threshold optical power for SRS = %.2f W'%Pr\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Threshold optical power for SBS = 80.3 mW\nThreshold optical power for SRS = 1.38 W\n"
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.4, page 101"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration \nn1=1.5 #refractive index\nh=0.82*10**-6 #operating wavelength\ndelta=0.03 #relative refractive index difference \ndelta1=0.003 #relative refractive index difference\nh1=1.55*10**-6 #operating wavelength\na=4*10**-6 #radius of core\n\n#Calculation\nn2=(n1**2)-(2*delta*n1**2) #refractive index\nRc=(3*n1**2*h)/(4*math.pi*(n1**2-n2)**0.5) #multimode fiber critical radius of curvature\nn21=(n1**2)-(2*delta1*n1**2) #refractive index \nhc=(2*math.pi*a*n1*math.sqrt(2*delta1))/(2.405) #cutoff wavelength for the single-mode fiber\nb=20*h1/math.sqrt(0.043)\nc=(2.748-(0.996*h1/hc))**-3\nRcs=b*c #critical radius of curvature for the single-mode\n\n#Result\nprint'Multimode fiber critical radius of curvature = %.2f um'%(Rc*10**6) #value given in the textbook is wrong \nprint'Single-mode fiber critical radius of curvature = %.2f um'%(Rcs*10**3) #value given in the textbook is wrong",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Multimode fiber critical radius of curvature = 1.20 um\nSingle-mode fiber critical radius of curvature = 0.05 um\n"
- }
- ],
- "prompt_number": 36
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.5, page 109"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration \nt=0.1*10**-6 #total pulse time \nd=15 #distance in Km\n\n#Calculation\nBt=1/(2*t) #Maximum Bandwidth\nD=t/d #Pulse Dispersion\nBop=Bt*d #Bandwidth-length product\n\n#Result\nprint'Maximum Bandwidth = %d Mhz'%(Bt/10**6)\nprint'Pulse Dispersion = %.2f ns per Km'%(D*10**9)\nprint'Bandwidth-length product = %d Mhz Km'%(Bop/10**6)\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum Bandwidth = 5 Mhz\nPulse Dispersion = 6.67 ns per Km\nBandwidth-length product = 75 Mhz Km\n"
- }
- ],
- "prompt_number": 51
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.6, page 111"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nb=0.025 #material dispersion \nc=2.998 #speed of light (x 10^8)\nh=85*10**6 #wavelength dispersion parameter\n\n\n#Calculation\nM=b/(c*h) #Material dispersion parameter\ns=M*20 #RMS pulse broadening (1 Km)\n\n#Result\nprint'Material dispersion parameter = %.1f ps n/m K/m'%(M*10**12)\nprint'RMS pulse broadening (1 Km) = %.2f ns K/m'%(s*10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Material dispersion parameter = 98.1 ps n/m K/m\nRMS pulse broadening (1 Km) = 1.96 ns K/m\n"
- }
- ],
- "prompt_number": 55
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.7, page 112"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh=0.85*10**-6 #wavelength \nb=0.0012 #relative spectral width\nM=98.1*10**-12 #material dispersion parameter\n\n#Calculation\nsh=b*h #relative spectral width\nsm=sh*M*10**9 #RMS pulse braodening\n\n#Result\nprint'RMS pulse braodening (1 Km) = %.2f ns K/m'%(sm*10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "RMS pulse braodening (1 Km) = 0.10 ns K/m\n"
- }
- ],
- "prompt_number": 66
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.8, page 117"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nL=6000 #optical link\nn1=1.5 #core refractive index\ndelt=0.01 #relative refractive index difference\nc=2.998*10**8 #speed of light\n\n\n#Calculation\nTs=(L*n1*delt)/c #Delay difference\nsc=(L*n1*delt)/(2*math.sqrt(3)*c) #RMS pulse broadening\nBt=1/(2*Ts)\nBtm=0.2/sc #Maximum bit rate using RMS pulse broadening\nBop=Btm*L #Bandwidth-length product\n\n#Result\nprint'(a) Delay difference = %d ns' %(Ts*10**9)\nprint'(b) RMS pulse broadening = %.1f ns' %(sc*10**9)\nprint'(c) Maximum bit rate using RMS pulse broadening = %.1f Mbit/s'%(Btm/10**6)\nprint'(d) Bandwidth-length product = %.1f Mhz km'%(Bop/10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Delay difference = 300 ns\n(b) RMS pulse broadening = 86.7 ns\n(c) Maximum bit rate using RMS pulse broadening = 2.3 Mbit/s\n(d) Bandwidth-length product = 13.8 Mhz km\n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.9, page 121"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nsc=86.7 #RMS pulse broadening\nL1=6 #optical link\nL=10**3 #for 1 Km\nn1=1.5 #core refractive index\ndelt=0.01 #relative refractive index difference\nc=3*10**8 #speed of light\n\n#Calculation\nd=sc/L1 #for multimode step index fiber\nsg=(L*n1*delt**2)/(20*math.sqrt(3)*c) #gradient index fiber\n\n#Result\nprint'RMS pulse broadening for multimode step index fiber = %.1f ns K/m'%(d)\nprint'RMS pulse broadening for gradient index fiber = %.1f ps K/m'%(sg*10**12)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "RMS pulse broadening for multimode step index fiber = 14.5 ns K/m\nRMS pulse broadening for gradient index fiber = 14.4 ps K/m\n"
- }
- ],
- "prompt_number": 18
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.10, page 125"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nsh=50 #rms spectral width\nL=1 #1 Km\nM=250*10**-12 #material dispersion parameter\nL1=10**3 \nNA=0.3 #numerical aperture\nn1=1.45 #refractive index\nc=2.998*10**8 #speed of light\n\n#Calculation\nsm=sh*L*M #rms pulse broadening\nss=(L1*NA**2)/(4*math.sqrt(3)*n1*c) #rms pulse broadening per kilometer\nst=math.sqrt(sm**2+ss**2) #total rms pulse broadening per kilometer\nBop=0.2/st #bandwidth\u2013length product\n\n#Result\nprint'(a) Total RMS pulse broadening per Km = %.1f ns K/m'%(st*10**9)\nprint'(b) Bandwidth length product = %.1f Mhz Km'%(Bop*10**-6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Total RMS pulse broadening per Km = 32.4 ns K/m\n(b) Bandwidth length product = 6.2 Mhz Km\n"
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.11, page 131"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "\n#Variable declaration\nh=1280 #wavelength in nm\nS0=0.09*10**-12 #dispersion slope\nh0=1310 #zero dispersion wavlength in nm\nh1=1550 #wavelength in nm\nDm=13.5*10**-12 #material dispersion wavelength in m\nDp=0.4*10**-12 #profile dispersion wavelength in m\n\n#Calculation\na=h*S0/4\nb=1-((h0*h**-1)**4)\nDt=a*b\nDt1=(h1*S0/4)*(1-(h0*h1**-1)**4)\nDw=Dt1-(Dm+Dp)\n\n#Result\nprint'Total first order dispersion (1280 nm) = %.1f nm^-1 km^-1'%(Dt*10**12)\nprint'Total first order dispersion (1550 nm) = %.1f ps n/m K/m'%(Dt1*10**12)\nprint'Waveguide dispersion at wavelength 1.55um = %.1f ps n/m K/m'%(Dw*10**12)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total first order dispersion (1280 nm) = -2.8 nm^-1 km^-1\nTotal first order dispersion (1550 nm) = 17.1 ps n/m K/m\nWaveguide dispersion at wavelength 1.55um = 3.2 ps n/m K/m\n"
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.12, page 143"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh=0.9*10**-6 #peak wavelength \nLb=0.09 #beat length\ns=10**-9 #spectral linewidth\n\n\n#Calculation\nBf=h/Lb #modal birefringence\nLbc=h**2/(Bf*s) #coherence length\nBxy=(2*math.pi)/Lb #difference between propagation constant\n\n#Result\nprint'Modal birefringence, Bf = %.1f x 10^-5' %(Bf*10**5)\nprint'Coherence length, Lf = %.1f m' %Lbc\nprint'Difference between propagation constant = %.1f' %Bxy",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Modal birefringence, Bf = 1.0 x 10^-5\nCoherence length, Lf = 81.0 m\nDifference between propagation constant = 69.8\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.13, page 144"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nh=1.3*10**-6 #fibers operating wavelength\nLs=0.7*10**-3 #beat length\nL=80 #beat length\n\n#Calculation\nBf=h/Ls #Fiber birefringence (0.7mm)\nBf1=h/L #Fiber birefringence (80m)\n\n#Result\nprint'Fiber birefringence (0.7mm) = %.2f x 10^-3'%(Bf*1000)\nprint'Fiber birefringence (80m) = %.2f x 10^-8'%(Bf1*10**8)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Fiber birefringence (0.7mm) = 1.86 x 10^-3\nFiber birefringence (80m) = 1.62 x 10^-8\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3.14, page 150"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nL=3.5*10**3 #length of fiber\na=2*10**-3 #tanh(h*L)\n\n\n#Calculation\nh=a/L #mode coupling parameter \n\n#Result\nprint'Mode coupling parameter = %.1f x 10^-7 m^-1'%(h*10**7)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Mode coupling parameter = 5.7 x 10^-7 m^-1\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "",
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter4_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter4_1.ipynb
deleted file mode 100755
index 7a8733a2..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter4_1.ipynb
+++ /dev/null
@@ -1,35 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_4"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 4 : Optical fibers and cables"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 4.1, page 196"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nl=0.16*10**-9 #bond distance\nSt=2.6*10**6 #cohesive strength\npsi=6894.76\nE=9*10**10 #Young modulus of silica\nC=10**-8\n\n#Calculation\nYp=4*l*St**2/E\nSf=math.sqrt((2*E*Yp)/(math.pi*C)) #Fracture stress for elliptical crack\nStr=Sf/E #Strain\n\n#Result\nprint'Fracture stress for elliptical crack = %.2f x 10^5 psi'%(Sf*10**-5)\nprint'Strain in percentage = %d percent'%(Str*6894.76*100)",
- "language": "python",
- "metadata": {},
- "outputs": [],
- "prompt_number": "*"
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter4_2.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter4_2.ipynb
deleted file mode 100755
index 7a8733a2..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter4_2.ipynb
+++ /dev/null
@@ -1,35 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_4"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 4 : Optical fibers and cables"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 4.1, page 196"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nl=0.16*10**-9 #bond distance\nSt=2.6*10**6 #cohesive strength\npsi=6894.76\nE=9*10**10 #Young modulus of silica\nC=10**-8\n\n#Calculation\nYp=4*l*St**2/E\nSf=math.sqrt((2*E*Yp)/(math.pi*C)) #Fracture stress for elliptical crack\nStr=Sf/E #Strain\n\n#Result\nprint'Fracture stress for elliptical crack = %.2f x 10^5 psi'%(Sf*10**-5)\nprint'Strain in percentage = %d percent'%(Str*6894.76*100)",
- "language": "python",
- "metadata": {},
- "outputs": [],
- "prompt_number": "*"
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter5.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter5.ipynb
deleted file mode 100755
index 0c445b62..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter5.ipynb
+++ /dev/null
@@ -1,239 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_5"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Chapter 5 : Optical fiber connection: joints, couplers and isolators"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.1, page 220"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nn1=1.5 #core refractive index\nn=1.0 #refractive index of medium\n\n#Calculation\nr=((n1-n)/(n1+n))**2 #magnitude of the Fresnel reflection at the fiber\u2013air interface\nLoss=-10*math.log10(1-r) #loss in decibels at the single interface\nLoss1=2*Loss #total loss\n\n#Result\nprint'Total loss due to Fresnel reflection = %.2f dB'%Loss1 #loss due to fresnel resolution = 0.18X2 dB\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total loss due to Fresnel reflection = 0.35 dB\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.2, page 224"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nn1=1.5 #refractive index\ny=5 #lateral offset of the fiber core axes in um\na=25 #radius in um\n\n#Calculation\nb=(16*n1**2)/(math.pi*(1+n1)**4)\nc=math.acos(y*(2*a)**-1)\ne=(y*a**-1)\nf=math.sqrt(1-(y*(2*a)**-1)**2)\nn=b*((2*c)-(e*f)) #coupling efficiency \nLoss=-10*math.log10(n) #insertion loss\nna=(math.pi**-1)*((2*c)-(e*f))\nLoss1=-10*math.log10(na) \n\n#Result\nprint'(a) Insertion loss = %.3f dB'%Loss\nprint'(b) Insertion loss = %.2f dB'%Loss1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Insertion loss = 0.945 dB\n(b) Insertion loss = 0.59 dB\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.3, page 226"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ny=3 #lateral misalignment in um\na=25 #core radius in um\n\n#Calculation\nLt=0.85*(y*a**-1) #misalignment loss for guided modes\nn=1-Lt #coupling efficiency\nLoss=-10*math.log10(n) #insertion loss\nLt1=0.75*(y*a**-1) #both guided and leaky modes \nn1=1-Lt1 #coupling efficiency\nLoss1=-10*math.log10(n1) #insertion loss\n\n#Result\nprint'(a) Uniform illumination of all guided modes only = %.2f dB'%Loss\nprint'(b) Uniform illumination of all guided and leaky modes = %.2f dB'%Loss1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Uniform illumination of all guided modes only = 0.47 dB\n(b) Uniform illumination of all guided and leaky modes = 0.41 dB\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.4, page 227"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nNA=0.2 #numerical aperture\nn1=1.48 #core refractive index\nang=(5*math.pi)/180 #angular misalignment (radians)\nNA1=0.4 #numerical aperture\n\n#Calculation\nna=((16*(n1)**2)/((1+n1)**4))*(1-(ang/(math.pi*NA))) #angular coupling efficiency\nLoss=-10*math.log10(na) #insertion loss\nna1=((16*(n1)**2)/((1+n1)**4))*(1-(ang/(math.pi*NA1))) #angular coupling efficiency\nLoss1=-10*math.log10(na1) #insertion loss\n\n#Result\nprint'Insertion loss at a joint (NA = 0.2) = %.2f dB'%Loss\nprint'Insertion loss at a joint (NA = 0.4) = %.2f dB'%Loss1 #in textbook, value is not calculated",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Insertion loss at a joint (NA = 0.2) = 0.98 dB\nInsertion loss at a joint (NA = 0.4) = 0.64 dB\n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.5, page 231"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nV=2.4 #normalized frequency\na=4 #core radius in um\nNA=0.1 #numerical aperture \nn1=1.46 #core refractive index\ny=1 #lateral misalignment in um\nteta=math.pi/180 #angular misalignment in rad\n\n#Calculation\nw=a*(0.65+(1.62/V**1.5)+(2.88/V**6))/(2**0.5) #normalized spot size\nTl=2.17*(y/w)**2 #loss due to the lateral offset\nTa=2.17*((teta*w*n1*V)/(a*NA))**2 #loss due to angular misalignment\nTt=Tl+Ta #total insertion loss\n\n#Result\nprint'Total insertion loss = %.2f dB'%Tt",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total insertion loss = 0.72 dB\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.6, page 232"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nw01=5.6 #mode-field radius in um\nw02=4.2 #mode-field radius in um\n\n#Calculation\nLoss=-10*math.log10(4*((w02/w01)+(w01/w02))**(-2)) #intrinsic loss \n\n#Result\nprint'Intrinsic loss = %.2f dB'%Loss",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Intrinsic loss = 0.35 dB\n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.7, page 262"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\np1=60 #input port power\np2=0.004 #output port power\np3=26 #output port power\np4=27.5 #output port power\n\n\n#Calculation\nxloss=10*math.log10(p1/(p3+p4)) #Excess Loss\niloss1=10*math.log10(p1*p3**-1) #Insertion Loss at input\niloss2=10*math.log10(p1/p4) #Insertion Loss at output\ncross=10*math.log10(p2/p1) #Crosstalk ratio\nsrat=((p3/(p3+p4))*100) #Split ratio\n\n#Result\nprint'Excess Loss = %.1f dB'%xloss\nprint'Insertion Loss at input = %.2f dB'%iloss1\nprint'Insertion Loss at output = %.2f dB'%iloss2\nprint'Crosstalk ratio = %.1f dB'%cross\nprint'Split ratio = %.1f percent'%srat",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Excess Loss = 0.5 dB\nInsertion Loss at input = 3.63 dB\nInsertion Loss at output = 3.39 dB\nCrosstalk ratio = -41.8 dB\nSplit ratio = 48.6 percent\n"
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.8, page 266"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nN=32 #total no of ports\npi=10**3 #optical power at input in micro-watt\npj=14 #optical power at input in micro-watt\n\n\n#Calculation\nsloss=10*math.log10(N) #splitting loss\nxloss=10*math.log10(pi*(pj*N)**-1) #excess loss\ntloss=sloss+xloss #total loss\niloss=10*math.log10(pi*pj**-1) #insertion loss\n\n#Result\nprint'Total loss = %.2f dB'%tloss\nprint'Insertion loss = %.2f dB'%iloss\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total loss = 18.54 dB\nInsertion loss = 18.54 dB\n"
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.9, page 268"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\np=16 #output ports\nl=0.2 #excess loss with split ratio of 50%\nl1=0.1 #splice loss\n\n#Calculation\nm=math.log(p)/math.log(2) #no of stages\nxloss=(4*l)+(3*l1) #excess loss\nsloss=10*math.log10(p) #split loss\niloss=sloss+xloss #insertion loss\n\n#Result\nprint'Insertion loss = %.2f dB'%iloss",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Insertion loss = 13.14 dB\n"
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.10, page 277"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nh=1.55*10**-6 #optical signal wavelength\nN=1.46 #refractive index\n\n\n#Calculation\nv=h/(2*N) #grating period of the FBG\n\n#Result\nprint'Grating period of FBG = %.2f um'%(v*10**6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Grating period of FBG = 0.53 um\n"
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "",
- "language": "python",
- "metadata": {},
- "outputs": [],
- "prompt_number": 11
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter5_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter5_1.ipynb
deleted file mode 100755
index 0c445b62..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter5_1.ipynb
+++ /dev/null
@@ -1,239 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_5"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Chapter 5 : Optical fiber connection: joints, couplers and isolators"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.1, page 220"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nn1=1.5 #core refractive index\nn=1.0 #refractive index of medium\n\n#Calculation\nr=((n1-n)/(n1+n))**2 #magnitude of the Fresnel reflection at the fiber\u2013air interface\nLoss=-10*math.log10(1-r) #loss in decibels at the single interface\nLoss1=2*Loss #total loss\n\n#Result\nprint'Total loss due to Fresnel reflection = %.2f dB'%Loss1 #loss due to fresnel resolution = 0.18X2 dB\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total loss due to Fresnel reflection = 0.35 dB\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.2, page 224"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nn1=1.5 #refractive index\ny=5 #lateral offset of the fiber core axes in um\na=25 #radius in um\n\n#Calculation\nb=(16*n1**2)/(math.pi*(1+n1)**4)\nc=math.acos(y*(2*a)**-1)\ne=(y*a**-1)\nf=math.sqrt(1-(y*(2*a)**-1)**2)\nn=b*((2*c)-(e*f)) #coupling efficiency \nLoss=-10*math.log10(n) #insertion loss\nna=(math.pi**-1)*((2*c)-(e*f))\nLoss1=-10*math.log10(na) \n\n#Result\nprint'(a) Insertion loss = %.3f dB'%Loss\nprint'(b) Insertion loss = %.2f dB'%Loss1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Insertion loss = 0.945 dB\n(b) Insertion loss = 0.59 dB\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.3, page 226"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ny=3 #lateral misalignment in um\na=25 #core radius in um\n\n#Calculation\nLt=0.85*(y*a**-1) #misalignment loss for guided modes\nn=1-Lt #coupling efficiency\nLoss=-10*math.log10(n) #insertion loss\nLt1=0.75*(y*a**-1) #both guided and leaky modes \nn1=1-Lt1 #coupling efficiency\nLoss1=-10*math.log10(n1) #insertion loss\n\n#Result\nprint'(a) Uniform illumination of all guided modes only = %.2f dB'%Loss\nprint'(b) Uniform illumination of all guided and leaky modes = %.2f dB'%Loss1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Uniform illumination of all guided modes only = 0.47 dB\n(b) Uniform illumination of all guided and leaky modes = 0.41 dB\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.4, page 227"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nNA=0.2 #numerical aperture\nn1=1.48 #core refractive index\nang=(5*math.pi)/180 #angular misalignment (radians)\nNA1=0.4 #numerical aperture\n\n#Calculation\nna=((16*(n1)**2)/((1+n1)**4))*(1-(ang/(math.pi*NA))) #angular coupling efficiency\nLoss=-10*math.log10(na) #insertion loss\nna1=((16*(n1)**2)/((1+n1)**4))*(1-(ang/(math.pi*NA1))) #angular coupling efficiency\nLoss1=-10*math.log10(na1) #insertion loss\n\n#Result\nprint'Insertion loss at a joint (NA = 0.2) = %.2f dB'%Loss\nprint'Insertion loss at a joint (NA = 0.4) = %.2f dB'%Loss1 #in textbook, value is not calculated",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Insertion loss at a joint (NA = 0.2) = 0.98 dB\nInsertion loss at a joint (NA = 0.4) = 0.64 dB\n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.5, page 231"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nV=2.4 #normalized frequency\na=4 #core radius in um\nNA=0.1 #numerical aperture \nn1=1.46 #core refractive index\ny=1 #lateral misalignment in um\nteta=math.pi/180 #angular misalignment in rad\n\n#Calculation\nw=a*(0.65+(1.62/V**1.5)+(2.88/V**6))/(2**0.5) #normalized spot size\nTl=2.17*(y/w)**2 #loss due to the lateral offset\nTa=2.17*((teta*w*n1*V)/(a*NA))**2 #loss due to angular misalignment\nTt=Tl+Ta #total insertion loss\n\n#Result\nprint'Total insertion loss = %.2f dB'%Tt",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total insertion loss = 0.72 dB\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.6, page 232"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nw01=5.6 #mode-field radius in um\nw02=4.2 #mode-field radius in um\n\n#Calculation\nLoss=-10*math.log10(4*((w02/w01)+(w01/w02))**(-2)) #intrinsic loss \n\n#Result\nprint'Intrinsic loss = %.2f dB'%Loss",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Intrinsic loss = 0.35 dB\n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.7, page 262"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\np1=60 #input port power\np2=0.004 #output port power\np3=26 #output port power\np4=27.5 #output port power\n\n\n#Calculation\nxloss=10*math.log10(p1/(p3+p4)) #Excess Loss\niloss1=10*math.log10(p1*p3**-1) #Insertion Loss at input\niloss2=10*math.log10(p1/p4) #Insertion Loss at output\ncross=10*math.log10(p2/p1) #Crosstalk ratio\nsrat=((p3/(p3+p4))*100) #Split ratio\n\n#Result\nprint'Excess Loss = %.1f dB'%xloss\nprint'Insertion Loss at input = %.2f dB'%iloss1\nprint'Insertion Loss at output = %.2f dB'%iloss2\nprint'Crosstalk ratio = %.1f dB'%cross\nprint'Split ratio = %.1f percent'%srat",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Excess Loss = 0.5 dB\nInsertion Loss at input = 3.63 dB\nInsertion Loss at output = 3.39 dB\nCrosstalk ratio = -41.8 dB\nSplit ratio = 48.6 percent\n"
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.8, page 266"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nN=32 #total no of ports\npi=10**3 #optical power at input in micro-watt\npj=14 #optical power at input in micro-watt\n\n\n#Calculation\nsloss=10*math.log10(N) #splitting loss\nxloss=10*math.log10(pi*(pj*N)**-1) #excess loss\ntloss=sloss+xloss #total loss\niloss=10*math.log10(pi*pj**-1) #insertion loss\n\n#Result\nprint'Total loss = %.2f dB'%tloss\nprint'Insertion loss = %.2f dB'%iloss\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total loss = 18.54 dB\nInsertion loss = 18.54 dB\n"
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.9, page 268"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\np=16 #output ports\nl=0.2 #excess loss with split ratio of 50%\nl1=0.1 #splice loss\n\n#Calculation\nm=math.log(p)/math.log(2) #no of stages\nxloss=(4*l)+(3*l1) #excess loss\nsloss=10*math.log10(p) #split loss\niloss=sloss+xloss #insertion loss\n\n#Result\nprint'Insertion loss = %.2f dB'%iloss",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Insertion loss = 13.14 dB\n"
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 5.10, page 277"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nh=1.55*10**-6 #optical signal wavelength\nN=1.46 #refractive index\n\n\n#Calculation\nv=h/(2*N) #grating period of the FBG\n\n#Result\nprint'Grating period of FBG = %.2f um'%(v*10**6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Grating period of FBG = 0.53 um\n"
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "",
- "language": "python",
- "metadata": {},
- "outputs": [],
- "prompt_number": 11
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter6_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter6_1.ipynb
deleted file mode 100755
index fa4189b4..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter6_1.ipynb
+++ /dev/null
@@ -1,188 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_6"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 6 - Optical sources 1: the laser\n"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.1, page 301"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nc=2.998*10**8 #speed of light in m/s\nh=0.5*10**-6 #operating wavelength in um\nt=1000 #tempreture in K\n\n#Calculation\nf=c/h #operating frequency\nr=1/math.exp((6.626*10**-34*f)/(1.381*10**-23*t)) #ratio\n\n#Result\nprint'Ratio = %.1f x 10^-13 '%(r*10**13)\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Ratio = 3.2 x 10^-13 \n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.2, page 306"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nn=1.78 #refractive index\nL=0.04 #length in meter\nh=0.55*10**-6 #peak emission wavelength in um\nc=2.998*10**8 #speed of light in meter\n\n#Calculation\nq=2*n*L/h #no of longitudinal modes\nsf=c/(2*n*L) #frequency separation modes\n\n#Result\nprint'No of longitudinal modes = %.1f x 10^5'%(q/10**5)\nprint'Frequency separation modes = %.1f GHz'%(sf/10**9)\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "No of longitudinal modes = 2.6 x 10^5\nFrequency separation modes = 2.1 GHz\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.3, page 308"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\na=30 #active cavity losses\nL=0.06 #length in meter\nr=0.3 #reflectivity\n\n\n#Calculation\ngm=a+(1/L)+(1/r) #laser gain coefficient\n\n\n#Result\nprint'Laser gain coefficient = %.1f cm^-1'%gm",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Laser gain coefficient = 50.0 cm^-1\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.4, page 315"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nBt1=7.21*10**-10 #recombination coefficient of GaAs\nBt2=1.79*10**-15 #recombination coefficient of Si\nN=10**18 #hole concentration \n\n#Calculation\ntr1=(Bt1*N)**-1 #radiative carrier lifetime of GaAs\ntr2=(Bt2*N)**-1 #radiative carrier lifetime of Si\n\n#Result\nprint'Radiative carrier lifetime of silicon = %.2f ms'%(tr2*1000)\nprint'Radiative carrier lifetime of gallium arsenide = %.2f ns'%(tr1*10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Radiative carrier lifetime of silicon = 0.56 ms\nRadiative carrier lifetime of gallium arsenide = 1.39 ns\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.5, page 322"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nn=3.6 #refractive index\nB=21*10**-3 #gain factor\na=10 #loss coefficient per cm\nL=250*10**-4 #optical cavity length\nw=100*10**-4 #optical cavity width\n\n#Calculation\nr=((n-1)/(n+1))**2 #reflectivity\njth=(1/B)*(a+math.log(1/r)/L) #threshold current density\narea=L*w #area\nith=jth*area #threshold current\n \n#Result\nprint'Threshold current = %.1f mA'%(ith*1000)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Threshold current = 662.4 mA\n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.6, page 330"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nnt=0.18 #total efficiency\nE=1.43 #bandgap energy\nV=2.5 #voltage\n\n\n#Calculation\nnep=nt*(E/V)*100 #external power efficiency\n\n#Result\nprint'External power efficiency = %d percent'%nep",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "External power efficiency = 10 percent\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.7, page 352"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nt1=20+273 #tempreture 20 \u00b0C convert to kelvin\nt2=80+273 #tempreture 80 \u00b0C convert to kelvin\nL1=160 #tempreture 160K\nL2=55 #tempreture 55K\n\n#Calculation\na=t1*L1**-1 \nb=t2*L1**-1\nc=t1*L2**-1\nd=t2*L2**-1\nJa1=math.exp(a) #For the AlGaAs device\nJa2=math.exp(b) #For the AlGaAs device\nJa=Ja2/Ja1 #ratio of the current densities\nJb1=math.exp(c) #For the InGaAsP device\nJb2=math.exp(d) #For the InGaAsP device\nJb=Jb2/Jb1 #ratio of the current densities\n\n#Result\nprint'Threshold current density at 20 \u00b0C = %.2f'%Ja\nprint' at 80 \u00b0C = %.2f' %Jb\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Threshold current density at 20 \u00b0C = 1.45\n at 80 \u00b0C = 2.98\n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.8, page 359"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ns=10**-15 #RIN value \nf=100*10**6 #bandwidth\ne=1.602*10**-19 #1 electron volt\nn=0.6 #quantum efficiency\nh=1.55*10**-6 #wavelength in um\npe=2*10**-3 #power incident\nB=100*10**6 #bandwidth\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\n\n#Calculation\nsr=s*f \nrin=math.sqrt(sr) #RMS value of power fluctuation\nirn=e*n*h*rin*pe*math.sqrt(B)*10**-4/(h1*c) #RMS noise current\n\n#Result\nprint'(a) RMS value of power fluctuation = %.2f x 10^-4 W'%(rin*10**4)\nprint'(b) RMS noise current = %.2f x 10^-7 A'%(irn*10**7)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) RMS value of power fluctuation = 3.16 x 10^-4 W\n(b) RMS noise current = 4.74 x 10^-7 A\n"
- }
- ],
- "prompt_number": 8
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter6_2.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter6_2.ipynb
deleted file mode 100755
index fa4189b4..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter6_2.ipynb
+++ /dev/null
@@ -1,188 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_6"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 6 - Optical sources 1: the laser\n"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.1, page 301"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nc=2.998*10**8 #speed of light in m/s\nh=0.5*10**-6 #operating wavelength in um\nt=1000 #tempreture in K\n\n#Calculation\nf=c/h #operating frequency\nr=1/math.exp((6.626*10**-34*f)/(1.381*10**-23*t)) #ratio\n\n#Result\nprint'Ratio = %.1f x 10^-13 '%(r*10**13)\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Ratio = 3.2 x 10^-13 \n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.2, page 306"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nn=1.78 #refractive index\nL=0.04 #length in meter\nh=0.55*10**-6 #peak emission wavelength in um\nc=2.998*10**8 #speed of light in meter\n\n#Calculation\nq=2*n*L/h #no of longitudinal modes\nsf=c/(2*n*L) #frequency separation modes\n\n#Result\nprint'No of longitudinal modes = %.1f x 10^5'%(q/10**5)\nprint'Frequency separation modes = %.1f GHz'%(sf/10**9)\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "No of longitudinal modes = 2.6 x 10^5\nFrequency separation modes = 2.1 GHz\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.3, page 308"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\na=30 #active cavity losses\nL=0.06 #length in meter\nr=0.3 #reflectivity\n\n\n#Calculation\ngm=a+(1/L)+(1/r) #laser gain coefficient\n\n\n#Result\nprint'Laser gain coefficient = %.1f cm^-1'%gm",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Laser gain coefficient = 50.0 cm^-1\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.4, page 315"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nBt1=7.21*10**-10 #recombination coefficient of GaAs\nBt2=1.79*10**-15 #recombination coefficient of Si\nN=10**18 #hole concentration \n\n#Calculation\ntr1=(Bt1*N)**-1 #radiative carrier lifetime of GaAs\ntr2=(Bt2*N)**-1 #radiative carrier lifetime of Si\n\n#Result\nprint'Radiative carrier lifetime of silicon = %.2f ms'%(tr2*1000)\nprint'Radiative carrier lifetime of gallium arsenide = %.2f ns'%(tr1*10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Radiative carrier lifetime of silicon = 0.56 ms\nRadiative carrier lifetime of gallium arsenide = 1.39 ns\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.5, page 322"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nn=3.6 #refractive index\nB=21*10**-3 #gain factor\na=10 #loss coefficient per cm\nL=250*10**-4 #optical cavity length\nw=100*10**-4 #optical cavity width\n\n#Calculation\nr=((n-1)/(n+1))**2 #reflectivity\njth=(1/B)*(a+math.log(1/r)/L) #threshold current density\narea=L*w #area\nith=jth*area #threshold current\n \n#Result\nprint'Threshold current = %.1f mA'%(ith*1000)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Threshold current = 662.4 mA\n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.6, page 330"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nnt=0.18 #total efficiency\nE=1.43 #bandgap energy\nV=2.5 #voltage\n\n\n#Calculation\nnep=nt*(E/V)*100 #external power efficiency\n\n#Result\nprint'External power efficiency = %d percent'%nep",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "External power efficiency = 10 percent\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.7, page 352"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nt1=20+273 #tempreture 20 \u00b0C convert to kelvin\nt2=80+273 #tempreture 80 \u00b0C convert to kelvin\nL1=160 #tempreture 160K\nL2=55 #tempreture 55K\n\n#Calculation\na=t1*L1**-1 \nb=t2*L1**-1\nc=t1*L2**-1\nd=t2*L2**-1\nJa1=math.exp(a) #For the AlGaAs device\nJa2=math.exp(b) #For the AlGaAs device\nJa=Ja2/Ja1 #ratio of the current densities\nJb1=math.exp(c) #For the InGaAsP device\nJb2=math.exp(d) #For the InGaAsP device\nJb=Jb2/Jb1 #ratio of the current densities\n\n#Result\nprint'Threshold current density at 20 \u00b0C = %.2f'%Ja\nprint' at 80 \u00b0C = %.2f' %Jb\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Threshold current density at 20 \u00b0C = 1.45\n at 80 \u00b0C = 2.98\n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 6.8, page 359"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ns=10**-15 #RIN value \nf=100*10**6 #bandwidth\ne=1.602*10**-19 #1 electron volt\nn=0.6 #quantum efficiency\nh=1.55*10**-6 #wavelength in um\npe=2*10**-3 #power incident\nB=100*10**6 #bandwidth\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\n\n#Calculation\nsr=s*f \nrin=math.sqrt(sr) #RMS value of power fluctuation\nirn=e*n*h*rin*pe*math.sqrt(B)*10**-4/(h1*c) #RMS noise current\n\n#Result\nprint'(a) RMS value of power fluctuation = %.2f x 10^-4 W'%(rin*10**4)\nprint'(b) RMS noise current = %.2f x 10^-7 A'%(irn*10**7)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) RMS value of power fluctuation = 3.16 x 10^-4 W\n(b) RMS noise current = 4.74 x 10^-7 A\n"
- }
- ],
- "prompt_number": 8
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter7_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter7_1.ipynb
deleted file mode 100755
index 7150478c..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter7_1.ipynb
+++ /dev/null
@@ -1,167 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_7"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 2 - Optical sources 2: the light-emitting diode\n"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.1, page 401"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ntr=60*10**-9 #radiative ecombination lifetime\ntnr=100*10**-9 #nonradiative ecombination lifetime\nh=6.626*10**-34 #plancks const\nc=2.998*10**8 #speed of light\ni=40*10**-3 #drive current\ne=1.602*10**-19 #1 electron volt\nh1=0.87*10**-6 #wavelength\n\n#Calculation\nt=(tr*tnr)/(tr+tnr) #total carrier recombination lifetime\nn=t/tr #quantum efficiency \npin=n*h*c*i/(e*h1) #internal power generated\n\n#Result\nprint'Total carrier recombination lifetime = %.1f ns'%(t*10**9)\nprint'Power internally generated = %.1f mW'%(pin*10**3)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total carrier recombination lifetime = 37.5 ns\nPower internally generated = 35.6 mW\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.2, page 402"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nF=0.68 #crystal\u2013air interface\nn=1 #refractive index of air\nnx=3.6 #refractive index of Ga\n\n\n#Calculation\npe=(F*n**2)/(4*nx**2) #Optical power emitted\nn1=pe*100/2 #External power efficiency\n\n#Result\nprint'Optical power emitted = %.3f *Pint'%(pe)\nprint'External power efficiency = %.2f percent'%n1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Optical power emitted = 0.013 *Pint\nExternal power efficiency = 0.66 percent\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.3, page 404"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nNA=0.2 #numerical aperture\npe=0.013 #optical power emitted\n\n#Calculation\nnc=NA**2 #coupling efficiency\nLoss=-10*math.log10(nc) #optical loss\npc=nc*pe #coupling power\nLoss1=-10*math.log10(pc) #internal power relative loss\n\n#Result\nprint'Coupling efficiency = %.2f'%nc\nprint'Optical loss = %.1f dB'%Loss\nprint'Loss due internal optical power = %.1f dB'%Loss1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Coupling efficiency = 0.04\nOptical loss = 14.0 dB\nLoss due internal optical power = 32.8 dB\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.4, page 409"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nr=0.01 #fresnel reflection coefficient \nRd=30 #radiance\nNA=0.15 #numerical aperture\na=25*10**-4 \n\n#Calculation\nA=math.pi*a**2 #emission area\npc=math.pi*(1-r)*A*Rd*NA**2 #optical power\n\n#Result\nprint'Optical power = %.1f uW'%(pc*10**6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Optical power = 41.2 uW\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.5, page 421"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npc=190*10**-6 #optical power\np=25*10**-3 #forward current\nv=1.5 #voltage\n\n\n#Calculation\nn=(pc/(p*v))*100 #power efficiency\n\n#Result\nprint'Overall power efficiency = %.1f percent'%n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Overall power efficiency = 0.5 percent\n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.7, page 430"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npdc=300*10**-6 #optical output power\nf=20*10**6 #frequency in hertz\nti=5*10**-9 #minority carrier recombination lifetime\nf2=100*10**6 #frequency in hertz\nt=10**-8\nw=math.sqrt(3)\n\n#Calculation\npe1=pdc/math.sqrt(1+(2*math.pi*f*ti)**2) #Optical output power (f=20 MHz)\npe2=pdc/math.sqrt(1+(2*math.pi*f2*ti)**2) #Optical output power (f=100 MHz)\nf=w/(math.pi*t)\nB=f/math.sqrt(2)\n\n#Result\nprint'(a) Optical output power (f=20 MHz) = %.2f uW'%(pe1*10**6)\nprint'(b) Optical output power (f=100 MHz) = %.2f uW'%(pe2*10**6)\nprint'Electrical bandwidth = %.1f MHz'%(B*10**-6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Optical output power (f=20 MHz) = 254.02 uW\n(b) Optical output power (f=100 MHz) = 90.99 uW\nElectrical bandwidth = 39.0 MHz\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.8, page 435"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nbo=1.84*10**7 #proportionality constant\ne=-1.602*10**-19 #charge of electron\nk=1.38*10**-23 #boltzman constant\nt1=290 #tempreture in kelvin\nexp=0.67\n\n\n\n#Calculation\nbt=bo*math.exp(e/(k*t1)) #degradation rate\nt=-math.log(exp)/bt #operating lifetime\n\n#Result\nprint'CW operating lifetime = %.1f x 10^9 h'%(t*10**-9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "CW operating lifetime = 5.3 x 10^9 h\n"
- }
- ],
- "prompt_number": 7
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter7_2.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter7_2.ipynb
deleted file mode 100755
index 7150478c..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter7_2.ipynb
+++ /dev/null
@@ -1,167 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_7"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 2 - Optical sources 2: the light-emitting diode\n"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.1, page 401"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ntr=60*10**-9 #radiative ecombination lifetime\ntnr=100*10**-9 #nonradiative ecombination lifetime\nh=6.626*10**-34 #plancks const\nc=2.998*10**8 #speed of light\ni=40*10**-3 #drive current\ne=1.602*10**-19 #1 electron volt\nh1=0.87*10**-6 #wavelength\n\n#Calculation\nt=(tr*tnr)/(tr+tnr) #total carrier recombination lifetime\nn=t/tr #quantum efficiency \npin=n*h*c*i/(e*h1) #internal power generated\n\n#Result\nprint'Total carrier recombination lifetime = %.1f ns'%(t*10**9)\nprint'Power internally generated = %.1f mW'%(pin*10**3)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Total carrier recombination lifetime = 37.5 ns\nPower internally generated = 35.6 mW\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.2, page 402"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nF=0.68 #crystal\u2013air interface\nn=1 #refractive index of air\nnx=3.6 #refractive index of Ga\n\n\n#Calculation\npe=(F*n**2)/(4*nx**2) #Optical power emitted\nn1=pe*100/2 #External power efficiency\n\n#Result\nprint'Optical power emitted = %.3f *Pint'%(pe)\nprint'External power efficiency = %.2f percent'%n1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Optical power emitted = 0.013 *Pint\nExternal power efficiency = 0.66 percent\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.3, page 404"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nNA=0.2 #numerical aperture\npe=0.013 #optical power emitted\n\n#Calculation\nnc=NA**2 #coupling efficiency\nLoss=-10*math.log10(nc) #optical loss\npc=nc*pe #coupling power\nLoss1=-10*math.log10(pc) #internal power relative loss\n\n#Result\nprint'Coupling efficiency = %.2f'%nc\nprint'Optical loss = %.1f dB'%Loss\nprint'Loss due internal optical power = %.1f dB'%Loss1",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Coupling efficiency = 0.04\nOptical loss = 14.0 dB\nLoss due internal optical power = 32.8 dB\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.4, page 409"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nr=0.01 #fresnel reflection coefficient \nRd=30 #radiance\nNA=0.15 #numerical aperture\na=25*10**-4 \n\n#Calculation\nA=math.pi*a**2 #emission area\npc=math.pi*(1-r)*A*Rd*NA**2 #optical power\n\n#Result\nprint'Optical power = %.1f uW'%(pc*10**6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Optical power = 41.2 uW\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.5, page 421"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npc=190*10**-6 #optical power\np=25*10**-3 #forward current\nv=1.5 #voltage\n\n\n#Calculation\nn=(pc/(p*v))*100 #power efficiency\n\n#Result\nprint'Overall power efficiency = %.1f percent'%n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Overall power efficiency = 0.5 percent\n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.7, page 430"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npdc=300*10**-6 #optical output power\nf=20*10**6 #frequency in hertz\nti=5*10**-9 #minority carrier recombination lifetime\nf2=100*10**6 #frequency in hertz\nt=10**-8\nw=math.sqrt(3)\n\n#Calculation\npe1=pdc/math.sqrt(1+(2*math.pi*f*ti)**2) #Optical output power (f=20 MHz)\npe2=pdc/math.sqrt(1+(2*math.pi*f2*ti)**2) #Optical output power (f=100 MHz)\nf=w/(math.pi*t)\nB=f/math.sqrt(2)\n\n#Result\nprint'(a) Optical output power (f=20 MHz) = %.2f uW'%(pe1*10**6)\nprint'(b) Optical output power (f=100 MHz) = %.2f uW'%(pe2*10**6)\nprint'Electrical bandwidth = %.1f MHz'%(B*10**-6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Optical output power (f=20 MHz) = 254.02 uW\n(b) Optical output power (f=100 MHz) = 90.99 uW\nElectrical bandwidth = 39.0 MHz\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 7.8, page 435"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nbo=1.84*10**7 #proportionality constant\ne=-1.602*10**-19 #charge of electron\nk=1.38*10**-23 #boltzman constant\nt1=290 #tempreture in kelvin\nexp=0.67\n\n\n\n#Calculation\nbt=bo*math.exp(e/(k*t1)) #degradation rate\nt=-math.log(exp)/bt #operating lifetime\n\n#Result\nprint'CW operating lifetime = %.1f x 10^9 h'%(t*10**-9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "CW operating lifetime = 5.3 x 10^9 h\n"
- }
- ],
- "prompt_number": 7
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter8.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter8.ipynb
deleted file mode 100755
index 057f59a0..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter8.ipynb
+++ /dev/null
@@ -1,209 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_8"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter - 8 : Optical detectors"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.1, page 454"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nn=1.2*10**11 #no of electrons\nm=3*10**11 #no of photons\ne=1.602*10**-19 #1 electron volt\nh=0.85*10**-6 #wavelength\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\n\n#Calculation\nQ=n/m #quantum efficiency\nR=(Q*e*h)/(h1*c) #responsivity\n\n#Result\nprint'Quantum efficiency = %.1f '%Q\nprint'Responsivity = %.3f A W^-1'%R",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Quantum efficiency = 0.4 \nResponsivity = 0.274 A W^-1\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.2, page 454"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\nE=1.5*10**-19 #energy of photons\nn=0.65 #quantum efficiency\ne=1.602*10**-19 #1 electron volt\nio=25*10**-6 #photocurrent\n\n#Calculation\nh=h1*c/E #wavelength\nR=(n*e)/(E) #responsivity\npo=io/R #incident optical power\n\n#Result\nprint'(a) Wavelength = %.2f um'%(h*10**6)\nprint'(b) Incident optical power = %.2f uW'%(po*10**6)\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Wavelength = 1.32 um\n(b) Incident optical power = 36.01 uW\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.3, page 456"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\ne=1.602*10**-19 #1 electron volt\nE=1.43 #bandgap energy in eV\n\n#Calculation\nh=h1*c/(E*e) #wavelength\n\n#Result\nprint'Wavelength = %.3f um'%(h*10**6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Wavelength = 0.867 um\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.4, page 463"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nw=20*10**-6 #width\nvd=10**5 #drift velocity\nr=500*10**-6 #diameter in meter\nes=10.5*10**-13 #permitivity\n\n#Calculation\ntd=w/vd #drift time\nA=math.pi*r**2 #area\ncj=es*A/w #junction capacitance\n\n#Result\nprint'Drift time = %.1f x 10^-10 S'%(td*10**10)\nprint'Junction capacitance = %.2f x 10^-13 F'%(cj*10**13)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Drift time = 2.0 x 10^-10 S\nJunction capacitance = 0.41 x 10^-13 F\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.5, page 464"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nvd=3*10**4 #drift velocity\nw=25*10**-6 #width\n\n#Calculation\nBm=vd/(2*math.pi*w) #maximum bandwidth\ntr=1/Bm #maximum response time\n\n#Result\nprint'Maximum response time = %.1f ns'%(tr*10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum response time = 5.2 ns\n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.6, page 470"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\ne=1.602*10**-19 #1 electron volt\nl=8*10**-9 #dark current\nn=0.55 #quantum efficiency\nh=1.3*10**-6 #wavelength\nA=100*50*10**-12\n\n#Calculation\nnep=(h1*c*math.sqrt(2*e*l))/(n*e*h) #Noise equivalent power\nD=math.sqrt(A)/nep #Specific detectivity\n\n#Result\nprint'Noise equivalent power = %.2f x 10^-14 W'%(nep*10**14)\nprint'Specific detectivity = %.1f x 10^8 m Hz^(1/2) W^-1'%(D*10**-8)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Noise equivalent power = 8.78 x 10^-14 W\nSpecific detectivity = 8.1 x 10^8 m Hz^(1/2) W^-1\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.7, page 482"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\ne=1.602*10**-19 #1 electron volt\nn=0.8 #quantum efficiency\nh=0.9*10**-6 #wavelength\npo=0.5*10**-6 #incident optical power\nI=11*10**-6 #output current\n\n#Calculation\nR=(n*e*h)/(h1*c) #resposivity\nIp=po*R #photocurrent\nM=I/Ip #multiplication factor\n\n#Result\nprint'Multiplication factor = %.2f '%M\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Multiplication factor = 37.89 \n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.8, page 487"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\ne=1.602*10**-19 #1 electron volt\nh=1.26*10**-6 #wavelength\nIc=15*10**-3 #collector current\npo=125*10**-6 #incident optical power\nn=0.4 #quantum efficiency\n\n#Calculation\ngo=(h1*c*Ic)/(h*e*po) #Optical gain\nhfe=go/n #Common emitter current gain\n \n#Result\nprint'Optical gain, Go = %.1f'%go\nprint'Common emitter current gain, hfe = %.1f '%hfe",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Optical gain, Go = 118.1\nCommon emitter current gain, hfe = 295.2 \n"
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.9, page 491"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nt=5*10**-12 #electron transit time\nG=70 #Optical gain\n\n#Calculation\nB=1/(2*math.pi*t*G) #Maximum 3dB bandwidth\n\n#Result\nprint'Maximum bandwidth = %.1f MHz'%(B*10**-6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum bandwidth = 454.7 MHz\n"
- }
- ],
- "prompt_number": 9
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter8_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter8_1.ipynb
deleted file mode 100755
index 057f59a0..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter8_1.ipynb
+++ /dev/null
@@ -1,209 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_8"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter - 8 : Optical detectors"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.1, page 454"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "#Variable declaration\nn=1.2*10**11 #no of electrons\nm=3*10**11 #no of photons\ne=1.602*10**-19 #1 electron volt\nh=0.85*10**-6 #wavelength\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\n\n#Calculation\nQ=n/m #quantum efficiency\nR=(Q*e*h)/(h1*c) #responsivity\n\n#Result\nprint'Quantum efficiency = %.1f '%Q\nprint'Responsivity = %.3f A W^-1'%R",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Quantum efficiency = 0.4 \nResponsivity = 0.274 A W^-1\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.2, page 454"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\nE=1.5*10**-19 #energy of photons\nn=0.65 #quantum efficiency\ne=1.602*10**-19 #1 electron volt\nio=25*10**-6 #photocurrent\n\n#Calculation\nh=h1*c/E #wavelength\nR=(n*e)/(E) #responsivity\npo=io/R #incident optical power\n\n#Result\nprint'(a) Wavelength = %.2f um'%(h*10**6)\nprint'(b) Incident optical power = %.2f uW'%(po*10**6)\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Wavelength = 1.32 um\n(b) Incident optical power = 36.01 uW\n"
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.3, page 456"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\ne=1.602*10**-19 #1 electron volt\nE=1.43 #bandgap energy in eV\n\n#Calculation\nh=h1*c/(E*e) #wavelength\n\n#Result\nprint'Wavelength = %.3f um'%(h*10**6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Wavelength = 0.867 um\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.4, page 463"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nw=20*10**-6 #width\nvd=10**5 #drift velocity\nr=500*10**-6 #diameter in meter\nes=10.5*10**-13 #permitivity\n\n#Calculation\ntd=w/vd #drift time\nA=math.pi*r**2 #area\ncj=es*A/w #junction capacitance\n\n#Result\nprint'Drift time = %.1f x 10^-10 S'%(td*10**10)\nprint'Junction capacitance = %.2f x 10^-13 F'%(cj*10**13)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Drift time = 2.0 x 10^-10 S\nJunction capacitance = 0.41 x 10^-13 F\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.5, page 464"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nvd=3*10**4 #drift velocity\nw=25*10**-6 #width\n\n#Calculation\nBm=vd/(2*math.pi*w) #maximum bandwidth\ntr=1/Bm #maximum response time\n\n#Result\nprint'Maximum response time = %.1f ns'%(tr*10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum response time = 5.2 ns\n"
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.6, page 470"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\ne=1.602*10**-19 #1 electron volt\nl=8*10**-9 #dark current\nn=0.55 #quantum efficiency\nh=1.3*10**-6 #wavelength\nA=100*50*10**-12\n\n#Calculation\nnep=(h1*c*math.sqrt(2*e*l))/(n*e*h) #Noise equivalent power\nD=math.sqrt(A)/nep #Specific detectivity\n\n#Result\nprint'Noise equivalent power = %.2f x 10^-14 W'%(nep*10**14)\nprint'Specific detectivity = %.1f x 10^8 m Hz^(1/2) W^-1'%(D*10**-8)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Noise equivalent power = 8.78 x 10^-14 W\nSpecific detectivity = 8.1 x 10^8 m Hz^(1/2) W^-1\n"
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.7, page 482"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\ne=1.602*10**-19 #1 electron volt\nn=0.8 #quantum efficiency\nh=0.9*10**-6 #wavelength\npo=0.5*10**-6 #incident optical power\nI=11*10**-6 #output current\n\n#Calculation\nR=(n*e*h)/(h1*c) #resposivity\nIp=po*R #photocurrent\nM=I/Ip #multiplication factor\n\n#Result\nprint'Multiplication factor = %.2f '%M\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Multiplication factor = 37.89 \n"
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.8, page 487"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\ne=1.602*10**-19 #1 electron volt\nh=1.26*10**-6 #wavelength\nIc=15*10**-3 #collector current\npo=125*10**-6 #incident optical power\nn=0.4 #quantum efficiency\n\n#Calculation\ngo=(h1*c*Ic)/(h*e*po) #Optical gain\nhfe=go/n #Common emitter current gain\n \n#Result\nprint'Optical gain, Go = %.1f'%go\nprint'Common emitter current gain, hfe = %.1f '%hfe",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Optical gain, Go = 118.1\nCommon emitter current gain, hfe = 295.2 \n"
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 8.9, page 491"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nt=5*10**-12 #electron transit time\nG=70 #Optical gain\n\n#Calculation\nB=1/(2*math.pi*t*G) #Maximum 3dB bandwidth\n\n#Result\nprint'Maximum bandwidth = %.1f MHz'%(B*10**-6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximum bandwidth = 454.7 MHz\n"
- }
- ],
- "prompt_number": 9
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter9_1.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter9_1.ipynb
deleted file mode 100755
index 42d197be..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter9_1.ipynb
+++ /dev/null
@@ -1,188 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_9"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 9 :Direct detection receiver performance considerations\n"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.1, page 506"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nzm=20.7 #average number of photons\nh=6.626*10**-34 #plancks constant\nf=2.998*10**14 #frequency in hertz \nn=1 #for ideal detector\nBt=10**7 #bit rate\n\n#Calculation\npo=zm*h*f*Bt/(2*n) #output power in binary\npod=10*math.log10(po) #output power in dBW\npod1=10*math.log10(po*10**3) #output power in dBm\n\n#Result\nprint'Minimum incident optical power = %.1f dBW'%(pod)\nprint' = %.1f dBm'%(pod1)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Minimum incident optical power = -106.9 dBW\n = -76.9 dBm\n"
- }
- ],
- "prompt_number": 26
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.2, page 508"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nsn=50/10 #signal to noise ratio in dB\nf=2.998*10**14 #frequency in hertz\nn=1 #for an ideal detector\nB=5*10**6 #bandwidth\nh=6.626*10**-34 #plancks constant\n\n#Calculation\nSN=10**(sn) \npo=SN*f*2*h*B/n #incident optical power\npdb=10*math.log10(po*10**3) #incident optical power in dB\n\n#Result\nprint'Incident optical power = %.1f nW '%(po*10**9)\nprint' in dB = %.1f dBm'%(pdb)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Incident optical power = 198.6 nW \n in dB = -37.0 dBm\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.3, page 512"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npo=200*10**-9 #incident optical power in W\ne=1.602*10**-19 #1 electron volt\nh=0.9*10**-6 #operating wavelength\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\nK=1.38*10**-23 #boltzman constant\nT=293 #tempreture in kelvin\nn=0.6 #quantum efficiency\nB=5*10**6 #post-detection bandwidth \nib=3*10**-9 #dark current in ampere\nRl=4*10**3 #load resistance\n\n#Calculation\nip=n*po*e*h/(h1*c) #photocurrent\ni2=2*e*B*(ib+ip) #total shot noise current\ni2rms=math.sqrt(i2) #RMS value \nit=4*K*T*B/Rl #thermal noise current\nitrms=math.sqrt(it) #RMS value\n\n#Result\nprint'RMS shot noise current = %.2f x10^-10 A'%(i2rms*10**10)\nprint'RMS thermal noise current = %.2f x10^-9 A'%(itrms*10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "RMS shot noise current = 3.80 x10^-10 A\nRMS thermal noise current = 4.50 x10^-9 A\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.4, page 514"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nip=87.1*10**-9 #photocurrent\nits=1.44*10**-19 #rms shot noise current \nit=2.02*10**-17 #rms thermal noise current\nfd=0.3 #frequency in 3 dB\n\n#Calculation\nf=10**(fd)\nsn=ip**2/(its+(it*f)) #signal to noise ratio\nsnr=10*math.log10(sn) #signal to noise ratio in dB\n\n#Result\nprint'SNR at output = %.2f dB'%snr",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "SNR at output = 22.73 dB\n"
- }
- ],
- "prompt_number": 39
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.5, page 516"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nB=8*10**6 #post detection bandwidth\nCd=6*10**-12 #capacitance in farad\nCa=12*10**-12 #input capacitance in farad\n\n\n#Calculation\nRl=1/(2*math.pi*Cd*B) #maximum load resistance\nB1=1/(2*math.pi*Rl*Ca) #maximum bandwidth\n\n#Result\nprint'Maximu load resistance = %.2f K\u03a9'%(Rl*10**-3)\nprint'Maximum bandwidth = %.1f MHz'%(B1*10**-6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximu load resistance = 3.32 K\u03a9\nMaximum bandwidth = 4.0 MHz\n"
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.6, page 518"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nB=50*10**6 #post detection bandwidth\nCd=5*10**-12 #capacitance in farad\ne=1.602*10**-19 #1 electron volt\nK=1.38*10**-23 #boltzman constant\nT=291 #tempreture in kelvin\nib=10**-7 #photocurrent before gain\nx=0.3\n\n#Calculation\nRl=1/(2*math.pi*Cd*B) #maximum value of the load resistor\na=2*e*B*ib #shot noise\nb=4*K*T*B/Rl #thermal noise\nsn=ib**2/(a+b) #SNR, when M = 1,\nsnd=10*math.log10(sn) #SNR in dB\nMop=((4*K*T)/(x*e*Rl*ib))**0.435\nsn1=(Mop**2*ib**2)/((2*e*B*ib*Mop**2.3)+b) #SNR, when M = Mop,\nsdb=10*math.log10(sn1) #SNR in dB\n\n#Result\nprint'SNR (M=1) = %.2f dB'%(snd)\nprint'SNR (M=Mop) = %.1f dB'%(sdb)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "SNR (M=1) = 8.99 dB\nSNR (M=Mop) = 32.5 dB\n"
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.7, page 520"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ne=1.602*10**-19 #1 electron volt\nK=1.38*10**-23 #boltzman constant\nT=120 #tempreture in kelvin\nB=10**7 #post detection bandwidth\nsn=3.5 #SNR/10\nfn=0.1 #noise figure/10\nRl=10**4 #load resistance\n\n#Calculation\nsn1=10**(sn)\nfn1=10**(fn)\na=12*K*T*B*fn1/Rl\nb=((4*K*T*fn1)/(1.1*e*Rl))**0.667\nIp=(sn1*a/b)**0.75 #minimum photocurrent\nMop=((4*K*T*fn1)/(e*Ip*1.1*10**3))**0.334 #optimum avalanche multiplication factor\n\n#Result\nprint'Optimum avalanche multiplication factor = %.1f '%(Mop)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Optimum avalanche multiplication factor = 8.9 \n"
- }
- ],
- "prompt_number": 22
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.8, page 528"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nr1=4*10**6 #effective input resistance in ohm\nr2=8*10**6 #resistance in ohm\nct=6*10**-12 #total capacitance in farad\nK=1.38*10**-23 #boltzman constant\nT=300 #tempreture in kelvin\nRf=10**5 #feedback resitor\nG=400 #open loop gain\n\n#Calculation\nRt=(r1**2)/r2 #total effective load resistance\nB=1/(2*math.pi*Rt*ct) #maximum bandwidth\ni2=4*K*T/Rt #for highimpedance config\nB1=G/(2*math.pi*Rf*ct) #maximum bandwidth for transimpedance config\nit=4*K*T/(Rf) #for transimpedance\n\n#transimpedance configuration factor of 20 greater than that obtained high-input-impedance configuration.\nn=it/i2\nndb=10*math.log10(n)\n\n#Result\nprint'(a) Maximum bandwidth = %.2f x10^4 Hz'%(B*10**-4)\nprint'(b) Mean square thermal noise current (high impedance config)= %.2f x10^-27 A^2 Hz^-1'%(i2*10**27)\nprint'\\n(c) Maximum bandwidth for transimpedance = %.2f X 10^6 Hz'%(B1*10**-8)\nprint' Mean square thermal noise current (transimpedance config) = %.2f x10^-25 A^2 Hz^-1'%(it*10**25)\nprint' Ratio of these noise power = %d dB'%ndb",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Maximum bandwidth = 1.33 x10^4 Hz\n(b) Mean square thermal noise current (high impedance config)= 8.28 x10^-27 A^2 Hz^-1\n\n(c) Maximum bandwidth for transimpedance = 1.06 X 10^6 Hz\n Mean square thermal noise current (transimpedance config) = 1.66 x10^-25 A^2 Hz^-1\n Ratio of these noise power = 13 dB\n"
- }
- ],
- "prompt_number": 21
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter9_2.ipynb b/Optical_Fiber_Communication_Principles_and_Practice/Chapter9_2.ipynb
deleted file mode 100755
index 42d197be..00000000
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter9_2.ipynb
+++ /dev/null
@@ -1,188 +0,0 @@
-{
- "metadata": {
- "name": "Chapter_9"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 9 :Direct detection receiver performance considerations\n"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.1, page 506"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nzm=20.7 #average number of photons\nh=6.626*10**-34 #plancks constant\nf=2.998*10**14 #frequency in hertz \nn=1 #for ideal detector\nBt=10**7 #bit rate\n\n#Calculation\npo=zm*h*f*Bt/(2*n) #output power in binary\npod=10*math.log10(po) #output power in dBW\npod1=10*math.log10(po*10**3) #output power in dBm\n\n#Result\nprint'Minimum incident optical power = %.1f dBW'%(pod)\nprint' = %.1f dBm'%(pod1)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Minimum incident optical power = -106.9 dBW\n = -76.9 dBm\n"
- }
- ],
- "prompt_number": 26
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.2, page 508"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nsn=50/10 #signal to noise ratio in dB\nf=2.998*10**14 #frequency in hertz\nn=1 #for an ideal detector\nB=5*10**6 #bandwidth\nh=6.626*10**-34 #plancks constant\n\n#Calculation\nSN=10**(sn) \npo=SN*f*2*h*B/n #incident optical power\npdb=10*math.log10(po*10**3) #incident optical power in dB\n\n#Result\nprint'Incident optical power = %.1f nW '%(po*10**9)\nprint' in dB = %.1f dBm'%(pdb)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Incident optical power = 198.6 nW \n in dB = -37.0 dBm\n"
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.3, page 512"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\npo=200*10**-9 #incident optical power in W\ne=1.602*10**-19 #1 electron volt\nh=0.9*10**-6 #operating wavelength\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\nK=1.38*10**-23 #boltzman constant\nT=293 #tempreture in kelvin\nn=0.6 #quantum efficiency\nB=5*10**6 #post-detection bandwidth \nib=3*10**-9 #dark current in ampere\nRl=4*10**3 #load resistance\n\n#Calculation\nip=n*po*e*h/(h1*c) #photocurrent\ni2=2*e*B*(ib+ip) #total shot noise current\ni2rms=math.sqrt(i2) #RMS value \nit=4*K*T*B/Rl #thermal noise current\nitrms=math.sqrt(it) #RMS value\n\n#Result\nprint'RMS shot noise current = %.2f x10^-10 A'%(i2rms*10**10)\nprint'RMS thermal noise current = %.2f x10^-9 A'%(itrms*10**9)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "RMS shot noise current = 3.80 x10^-10 A\nRMS thermal noise current = 4.50 x10^-9 A\n"
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.4, page 514"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nip=87.1*10**-9 #photocurrent\nits=1.44*10**-19 #rms shot noise current \nit=2.02*10**-17 #rms thermal noise current\nfd=0.3 #frequency in 3 dB\n\n#Calculation\nf=10**(fd)\nsn=ip**2/(its+(it*f)) #signal to noise ratio\nsnr=10*math.log10(sn) #signal to noise ratio in dB\n\n#Result\nprint'SNR at output = %.2f dB'%snr",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "SNR at output = 22.73 dB\n"
- }
- ],
- "prompt_number": 39
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.5, page 516"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nB=8*10**6 #post detection bandwidth\nCd=6*10**-12 #capacitance in farad\nCa=12*10**-12 #input capacitance in farad\n\n\n#Calculation\nRl=1/(2*math.pi*Cd*B) #maximum load resistance\nB1=1/(2*math.pi*Rl*Ca) #maximum bandwidth\n\n#Result\nprint'Maximu load resistance = %.2f K\u03a9'%(Rl*10**-3)\nprint'Maximum bandwidth = %.1f MHz'%(B1*10**-6)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Maximu load resistance = 3.32 K\u03a9\nMaximum bandwidth = 4.0 MHz\n"
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.6, page 518"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nB=50*10**6 #post detection bandwidth\nCd=5*10**-12 #capacitance in farad\ne=1.602*10**-19 #1 electron volt\nK=1.38*10**-23 #boltzman constant\nT=291 #tempreture in kelvin\nib=10**-7 #photocurrent before gain\nx=0.3\n\n#Calculation\nRl=1/(2*math.pi*Cd*B) #maximum value of the load resistor\na=2*e*B*ib #shot noise\nb=4*K*T*B/Rl #thermal noise\nsn=ib**2/(a+b) #SNR, when M = 1,\nsnd=10*math.log10(sn) #SNR in dB\nMop=((4*K*T)/(x*e*Rl*ib))**0.435\nsn1=(Mop**2*ib**2)/((2*e*B*ib*Mop**2.3)+b) #SNR, when M = Mop,\nsdb=10*math.log10(sn1) #SNR in dB\n\n#Result\nprint'SNR (M=1) = %.2f dB'%(snd)\nprint'SNR (M=Mop) = %.1f dB'%(sdb)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "SNR (M=1) = 8.99 dB\nSNR (M=Mop) = 32.5 dB\n"
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.7, page 520"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\ne=1.602*10**-19 #1 electron volt\nK=1.38*10**-23 #boltzman constant\nT=120 #tempreture in kelvin\nB=10**7 #post detection bandwidth\nsn=3.5 #SNR/10\nfn=0.1 #noise figure/10\nRl=10**4 #load resistance\n\n#Calculation\nsn1=10**(sn)\nfn1=10**(fn)\na=12*K*T*B*fn1/Rl\nb=((4*K*T*fn1)/(1.1*e*Rl))**0.667\nIp=(sn1*a/b)**0.75 #minimum photocurrent\nMop=((4*K*T*fn1)/(e*Ip*1.1*10**3))**0.334 #optimum avalanche multiplication factor\n\n#Result\nprint'Optimum avalanche multiplication factor = %.1f '%(Mop)",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Optimum avalanche multiplication factor = 8.9 \n"
- }
- ],
- "prompt_number": 22
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 9.8, page 528"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "import math\n\n#Variable declaration\nr1=4*10**6 #effective input resistance in ohm\nr2=8*10**6 #resistance in ohm\nct=6*10**-12 #total capacitance in farad\nK=1.38*10**-23 #boltzman constant\nT=300 #tempreture in kelvin\nRf=10**5 #feedback resitor\nG=400 #open loop gain\n\n#Calculation\nRt=(r1**2)/r2 #total effective load resistance\nB=1/(2*math.pi*Rt*ct) #maximum bandwidth\ni2=4*K*T/Rt #for highimpedance config\nB1=G/(2*math.pi*Rf*ct) #maximum bandwidth for transimpedance config\nit=4*K*T/(Rf) #for transimpedance\n\n#transimpedance configuration factor of 20 greater than that obtained high-input-impedance configuration.\nn=it/i2\nndb=10*math.log10(n)\n\n#Result\nprint'(a) Maximum bandwidth = %.2f x10^4 Hz'%(B*10**-4)\nprint'(b) Mean square thermal noise current (high impedance config)= %.2f x10^-27 A^2 Hz^-1'%(i2*10**27)\nprint'\\n(c) Maximum bandwidth for transimpedance = %.2f X 10^6 Hz'%(B1*10**-8)\nprint' Mean square thermal noise current (transimpedance config) = %.2f x10^-25 A^2 Hz^-1'%(it*10**25)\nprint' Ratio of these noise power = %d dB'%ndb",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "(a) Maximum bandwidth = 1.33 x10^4 Hz\n(b) Mean square thermal noise current (high impedance config)= 8.28 x10^-27 A^2 Hz^-1\n\n(c) Maximum bandwidth for transimpedance = 1.06 X 10^6 Hz\n Mean square thermal noise current (transimpedance config) = 1.66 x10^-25 A^2 Hz^-1\n Ratio of these noise power = 13 dB\n"
- }
- ],
- "prompt_number": 21
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter10.ipynb b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_10.ipynb
index 077ac9f5..077ac9f5 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter10.ipynb
+++ b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_10.ipynb
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter11_1.ipynb b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_11.ipynb
index 77cd82ac..fd7eec66 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter11_1.ipynb
+++ b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_11.ipynb
@@ -11,7 +11,7 @@
"cell_type": "heading",
"level": 1,
"metadata": {},
- "source": "Chapter 1 : Integrated optics and photonics"
+ "source": "Chapter 11 : Integrated optics and photonics"
},
{
"cell_type": "heading",
@@ -54,6 +54,27 @@
}
],
"prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example 11.3, page 631"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "import math\n\n#Variable declaration\nn1=8 #no of bands\nN1=0 #no of channels between any two bands\nN2=1 #no of channels between any two bands\nN3=2 #no of channels between any two bands\nM=4 #no of channels in each band\n\n#Calculation\nCs1=(n1-1)*N1 #total number of channels skipped \nCt1=(n1*M)+Cs1 #total number of channels for 4 skip-0 scheme\nCs2=(n1-1)*N2 #total number of channels skipped \nCt2=(n1*M)+Cs2 #total number of channels for 4 skip-1 scheme\nCs3=(n1-1)*N3 #total number of channels skipped \nCt3=(n1*M)+Cs3 #total number of channels for 4 skip-2 scheme\n\n#Result\nprint'Total number ofchannels required for each interleaver band filter'\nprint'(i) 4-skip-0:'\nprint' Ctotal = %d'%Ct1\nprint'(ii) 4-skip-1:'\nprint' Ctotal = %d'%Ct2\nprint'(iii) 4-skip-2:'\nprint' Ctotal = %d'%Ct3",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Total number ofchannels required for each interleaver band filter\n(i) 4-skip-0:\n Ctotal = 32\n(ii) 4-skip-1:\n Ctotal = 39\n(iii) 4-skip-2:\n Ctotal = 46\n"
+ }
+ ],
+ "prompt_number": 9
}
],
"metadata": {}
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter12.ipynb b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_12.ipynb
index 288c514a..38f7d751 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter12.ipynb
+++ b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_12.ipynb
@@ -379,7 +379,7 @@
{
"cell_type": "code",
"collapsed": false,
- "input": "%pylab inline\nimport math\nfrom pylab import *\nfrom numpy import *\n\n#Variable declaration\nacr=1 #connector loss in dB\nafc=5 #loss per kilometer in dB\nLbu=0.1 #fiber length between each of the access couplers\nLac=1 #insertion loss\nLtr=10 #loss due to the tap ratio\nLsp=3 #splitting loss\n \n#Calculating, we get two equation in terms of N, no of nodes, i.e C(1,N-1)=(3.5*N)+8.5 and C(star)=4.5+(10*log10(N)) \n\n#For Bus distribution system\n\nfor N in range(1,13,1):\n C=(3.5*N)+8.5;\n a=plot(N,C,'.r')\n \n \n#for Star distribution system\n \nfor N in range(1,30,1):\n C1=4.5+(10*log10(N));\n b=plot(N,C1,'.g')\n \n \n#To show plot in same graph\n#Graphical comparison showing total channel loss against number of nodes\n\nxlabel(\"Number of nodes $N$\")\nylabel(\"Total channel loss $CL$ (dB)\")\ngrid()\nshow(a)\nshow(b)\n",
+ "input": "%pylab inline\nimport math\nfrom pylab import *\nfrom numpy import *\n\n#Variable declaration\nacr=1 #connector loss in dB\nafc=5 #loss per kilometer in dB\nLbu=0.1 #fiber length between each of the access couplers\nLac=1 #insertion loss\nLtr=10 #loss due to the tap ratio\nLsp=3 #splitting loss\n \n#Calculating, we get two equation in terms of N, no of nodes, i.e C(1,N-1)=(3.5*N)+8.5 and C(star)=4.5+(10*log10(N)) \n\n#For Bus distribution system\n\nfor N in range(1,13,1):\n C=(3.5*N)+8.5;\n a=plot(N,C,'.r')\n \n \n#for Star distribution system\n \nfor N in range(1,30,1):\n C1=4.5+(10*log10(N));\n b=plot(N,C1,'.g')\n \n \n#To show plot in same graph\n#Graphical comparison showing total channel loss against number of nodes\n\nplt.annotate('Linear Bus',xy=(10, 43.5), xytext=(11, 40))\nplt.annotate('Star',xy=(16, 15), xytext=(17, 13))\nxlabel(\"Number of nodes $N$\")\nylabel(\"Total channel loss $CL$ (dB)\")\ntitle(\"Characteristics showing the total channel loss against the number of nodes\")\ngrid()\nshow(a)\nshow(b)\n",
"language": "python",
"metadata": {},
"outputs": [
@@ -391,11 +391,11 @@
{
"metadata": {},
"output_type": "display_data",
- "png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEOCAYAAABmVAtTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XtcVHX6B/DPqCgpJWgxmPprfJmoXIRREbdCpxAsTUQU\nq/UCarLpul1Nrd2Ktq1wU1O77UvXTUqp2LYIWzE1QbEyFbDLamIpWi2gCSheUIHv7w/irCjinMOc\nmTnf+bxfr14xw1yep7N7Hs7znPM9JiGEABEREYA2rg6AiIjcB4sCEREpWBSIiEjBokBERAoWBSIi\nUrAoEBGRwqlFoaqqChMmTED//v0RFBSEL7/8EhUVFYiJiUFgYCBiY2NRVVXlzJCIiOgiTi0KDz30\nEEaNGoV9+/bh66+/Rr9+/ZCWloaYmBgUFxcjOjoaaWlpzgyJiIguYnLWxWsnTpyA1WrFwYMHmzzf\nr18/bN26FWazGWVl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WqFwYMHgzGGw4cPN1jmLl26YObMmZgzZw4G\nDhyIXr16KS3P6NGjsXXrVnh6eiIwMFDpsoSIDSVW0qxMmzYNXbt2xfjx4wEABgYGXHcnAK4bFwBa\ntmzJ/a2np4cWLVpwf1dWVnKv1R2jZIxBIpGAMYbw8HB89dVXCsthbGys8Pna9z67vuepW1Z9fX0u\njmfXpexvZWXu0KED0tPT8euvv2LevHno06cP5s+fz1smNzcXr7zyCgBg2LBh8Pf3h4eHx3PLTojY\n0BgraVYsLS0xYsQIbNiwARKJBFKpFPfv30d+fj6ePHmCvXv3qnwxz507d3Dy5EkAQHx8PAICAtCn\nTx/s3LkTDx48AADk5+fjzp07z11XQEAAEhMTUVZWhsePHyMxMREBAQGqB9rAunr37o3evXsjMTER\n5eXlKC4u5mJWVuacnBy0atUKo0ePxsyZM5GWllZve6dPn0bXrl0B1PQOeHh4cOsipDmhM1bSLNRN\nljNmzMDq1asB1JyxLliwAH5+fnBwcICbm5vC9zz7uO7fnTp1wvfff48JEybA3d0dU6ZMQatWrfCv\nf/0LISEhqK6uhqGhIdasWQNnZ2eF667l4+ODiIgIrpt40qRJXDewsoSvqKzK1jVy5Eh4eXnB1taW\ne93V1bXBMl+8eBGffPIJd+a+du1a3vYOHz6MRYsW4cmTJ3jnnXcA1HSLW1tbN1hmQsSKfjaOEEII\nUSPqCiaEEELUiBIrIYQQokaUWAkhhBA1osRKCCGEqBElVkIIIUSNKLESQgghakSJlRBCCFEjSqyE\nEEKIGv0/kAL13NFyzXoAAAAASUVORK5CYII=\n",
+ "text": "<matplotlib.figure.Figure at 0x46877d0>"
}
],
- "prompt_number": 27
+ "prompt_number": 11
},
{
"cell_type": "heading",
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter13.ipynb b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_13.ipynb
index 3392b3ce..3392b3ce 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter13.ipynb
+++ b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_13.ipynb
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter14.ipynb b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_14.ipynb
index 80d85c26..80d85c26 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter14.ipynb
+++ b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_14.ipynb
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter2.ipynb b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_2.ipynb
index 81d67649..81d67649 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter2.ipynb
+++ b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_2.ipynb
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter3_2.ipynb b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_3.ipynb
index 3778a224..44b64c87 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter3_2.ipynb
+++ b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_3.ipynb
@@ -22,17 +22,17 @@
{
"cell_type": "code",
"collapsed": false,
- "input": "import math\n\n#Variable declaration\nPi=120*10**-6 #mean i/p power in uW\nPo=3*10**-6 #mean o/p power in uW\nL=8 #length of fibre in Km\na1=2 #loss in dB\nL1=10 #length of fibre in Km\nloss=9 #loss in dB\n\n#Calculation \nSA=10*math.log10(Pi/Po) #overall signal attenuation\na=SA/L #signal attenuation per kilometer\nal=a1*L1\nSA1=al+loss #signal attenuation for the 10KM link\nP=10**(2.9) #i/o power ratio, 2.9 is numeric value\n\n\n#Result\nprint'Overall signal attenuation = ',round(SA),'dB'\nprint'Signal attenuation per kilometer = ',round(a),'per KM'\nprint'Overall signal attenuation for the 10KM link = ',round(SA1),'dB'\nprint'Numeric value for i/o power ratio = %.1f' %P",
+ "input": "import math\n\n#Variable declaration\nPi=120*10**-6 #mean i/p power in uW\nPo=3*10**-6 #mean o/p power in uW\nL=8 #length of fibre in Km\na1=2 #loss in dB\nL1=10 #length of fibre in Km\nloss=9 #loss in dB\n\n#Calculation \nSA=10*math.log10(Pi/Po) #overall signal attenuation\na=SA/L #signal attenuation per kilometer\nal=a1*L1\nSA1=al+loss #signal attenuation for the 10KM link\nP=10**(2.9) #i/o power ratio, 2.9 is numeric value\n\n\n#Result\nprint'Overall signal attenuation = ',round(SA),'dB'\nprint'Signal attenuation per kilometer = ',round(a),'dB Km^-1'\nprint'Overall signal attenuation for the 10KM link = ',round(SA1),'dB'\nprint'Numeric value for i/o power ratio = %.1f' %P",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "Overall signal attenuation = 16.0 dB\nSignal attenuation per kilometer = 2.0 per KM\nOverall signal attenuation for the 10KM link = 29.0 dB\nNumeric value for i/o power ratio = 794.3\n"
+ "text": "Overall signal attenuation = 16.0 dB\nSignal attenuation per kilometer = 2.0 dB Km^-1\nOverall signal attenuation for the 10KM link = 29.0 dB\nNumeric value for i/o power ratio = 794.3\n"
}
],
- "prompt_number": 5
+ "prompt_number": 1
},
{
"cell_type": "heading",
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter4.ipynb b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_4.ipynb
index 7a8733a2..7a8733a2 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter4.ipynb
+++ b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_4.ipynb
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter5_2.ipynb b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_5.ipynb
index 0c445b62..3b95860b 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter5_2.ipynb
+++ b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_5.ipynb
@@ -9,7 +9,7 @@
"cells": [
{
"cell_type": "heading",
- "level": 2,
+ "level": 1,
"metadata": {},
"source": "Chapter 5 : Optical fiber connection: joints, couplers and isolators"
},
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter6.ipynb b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_6.ipynb
index fa4189b4..fa4189b4 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter6.ipynb
+++ b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_6.ipynb
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter7.ipynb b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_7.ipynb
index 7150478c..7150478c 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter7.ipynb
+++ b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_7.ipynb
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter8_2.ipynb b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_8.ipynb
index 057f59a0..ef4b2404 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter8_2.ipynb
+++ b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_8.ipynb
@@ -43,17 +43,17 @@
{
"cell_type": "code",
"collapsed": false,
- "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\nE=1.5*10**-19 #energy of photons\nn=0.65 #quantum efficiency\ne=1.602*10**-19 #1 electron volt\nio=25*10**-6 #photocurrent\n\n#Calculation\nh=h1*c/E #wavelength\nR=(n*e)/(E) #responsivity\npo=io/R #incident optical power\n\n#Result\nprint'(a) Wavelength = %.2f um'%(h*10**6)\nprint'(b) Incident optical power = %.2f uW'%(po*10**6)\n",
+ "input": "import math\n\n#Variable declaration\nh1=6.626*10**-34 #plancks constant\nc=2.998*10**8 #speed of light\nE=1.5*10**-19 #energy of photons\nn=0.65 #quantum efficiency\ne=1.602*10**-19 #1 electron volt\nio=2.5*10**-6 #photocurrent\n\n#Calculation\nh=h1*c/E #wavelength\nR=(n*e)/(E) #responsivity\npo=io/R #incident optical power\n\n#Result\nprint'(a) Wavelength = %.2f um'%(h*10**6)\nprint'(b) Incident optical power = %.2f uW'%(po*10**6) \n",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "(a) Wavelength = 1.32 um\n(b) Incident optical power = 36.01 uW\n"
+ "text": "(a) Wavelength = 1.32 um\n(b) Incident optical power = 3.60 uW\n"
}
],
- "prompt_number": 2
+ "prompt_number": 1
},
{
"cell_type": "heading",
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/Chapter9.ipynb b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_9.ipynb
index 42d197be..42d197be 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/Chapter9.ipynb
+++ b/Optical_Fiber_Communications_Principles_and_Practice/Chapter_9.ipynb
diff --git a/Optical_Fiber_Communications_Principles_and_Practice/README.txt b/Optical_Fiber_Communications_Principles_and_Practice/README.txt
new file mode 100644
index 00000000..7fb62b0e
--- /dev/null
+++ b/Optical_Fiber_Communications_Principles_and_Practice/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Sufiyan Siddique
+Course: be
+College/Institute/Organization: A.I Kalsekar Technical Campus, Mumbai University
+Department/Designation: Electronics & Telecommunication
+Book Title: Optical Fiber Communications Principles and Practice
+Author: John M. Senior
+Publisher: Prentice Hall, UK
+Year of publication: 2009
+Isbn: 9780130326812
+Edition: 3 \ No newline at end of file
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Selection_001.png b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_001.png
index effd888e..effd888e 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Selection_001.png
+++ b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_001.png
Binary files differ
diff --git a/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_001_1.png b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_001_1.png
new file mode 100644
index 00000000..effd888e
--- /dev/null
+++ b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_001_1.png
Binary files differ
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Selection_002.png b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_002.png
index 394be49f..394be49f 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Selection_002.png
+++ b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_002.png
Binary files differ
diff --git a/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_002_1.png b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_002_1.png
new file mode 100644
index 00000000..394be49f
--- /dev/null
+++ b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Selection_002_1.png
Binary files differ
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes.png b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel.png
index e92adc62..e92adc62 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes.png
+++ b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel.png
Binary files differ
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_1.png b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_1.png
index e92adc62..e92adc62 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_1.png
+++ b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_1.png
Binary files differ
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_2.png b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes.png
index e92adc62..e92adc62 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_2.png
+++ b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes.png
Binary files differ
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_3.png b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_1.png
index e92adc62..e92adc62 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_3.png
+++ b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_1.png
Binary files differ
diff --git a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_4.png b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_2.png
index e92adc62..e92adc62 100755..100644
--- a/Optical_Fiber_Communication_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_4.png
+++ b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_2.png
Binary files differ
diff --git a/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_3.png b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_3.png
new file mode 100644
index 00000000..e92adc62
--- /dev/null
+++ b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_3.png
Binary files differ
diff --git a/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_4.png b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_4.png
new file mode 100644
index 00000000..e92adc62
--- /dev/null
+++ b/Optical_Fiber_Communications_Principles_and_Practice/screenshots/Total_channel_loss_against_number_of_nodes_4.png
Binary files differ
diff --git a/Optical_Fiber_Communications_Principles_and_Practice/techsupport b/Optical_Fiber_Communications_Principles_and_Practice/techsupport
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/Optical_Fiber_Communications_Principles_and_Practice/techsupport
diff --git a/Principles_Of_Fluid_Mechanics/README.txt b/Principles_Of_Fluid_Mechanics/README.txt
new file mode 100644
index 00000000..89034682
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Nirav Lalani
+Course: be
+College/Institute/Organization: Freelancer
+Department/Designation: Computer Science
+Book Title: Principles Of Fluid Mechanics
+Author: M. K. Natarajan
+Publisher: Oxford and IBH Publishing Co.
+Year of publication: 1984
+Isbn: 8120408888
+Edition: 3 \ No newline at end of file
diff --git a/Principles_Of_Fluid_Mechanics/ch1.ipynb b/Principles_Of_Fluid_Mechanics/ch1.ipynb
new file mode 100644
index 00000000..947959aa
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/ch1.ipynb
@@ -0,0 +1,275 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5f74478ce49dffc1b551f32fb2744aa025f82f0e4c0a37162dfc5c9eb6e76508"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1 : Basic Concepts"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.1 Page No : 5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "weight = 9800. \t\t\t#Kg\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "a = 2. \t\t \t#m/s**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "m = weight/g\n",
+ "Wm = m*a\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Density on earth = %.2f Kg/m**3\"%(m)\n",
+ "print \" Weight on moon = %.2f N\"%(Wm)\n",
+ "print \" Density on moon remains unchanged and is equal to %.2f Kg/m**3\"%(m)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Density on earth = 998.98 Kg/m**3\n",
+ " Weight on moon = 1997.96 N\n",
+ " Density on moon remains unchanged and is equal to 998.98 Kg/m**3\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.2 Page No : 14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "w = 150. \t\t\t#N\n",
+ "theta = 30. \t\t\t#degrees\n",
+ "l = 0.8 \t\t\t#m\n",
+ "b = 0.8 \t\t\t#m\n",
+ "dy = 0.12 \t\t\t#cm\n",
+ "v = 20. \t\t\t#cm/s\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Tau = round(w*math.sin(math.radians(theta)) /(l*b),2) #shear stress\n",
+ "rd = v/dy #rate of deformation\n",
+ "vis = Tau/rd #viscosity\n",
+ "\n",
+ "#results\n",
+ "print \"Viscosity of the fluid = %.2f N s/m**2\"%(vis)\n",
+ "\n",
+ "# incorrect solution for 'rate of deformation' in textbook"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Viscosity of the fluid = 0.70 N s/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.3 Page No : 14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "vis = 2.5/10 \t\t\t#N s/m**2\n",
+ "D = 15. \t\t\t#cm\n",
+ "N = 180.\n",
+ "dy = 0.0001 \t\t\t#m\n",
+ "l = 0.15 \t\t\t#length - m\n",
+ "b = 0.25 \t\t\t#breadth - m\n",
+ "r = 0.152 \t\t\t#radius - m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "dv = math.pi*D*N/60/100\n",
+ "Tau = vis*dv/dy\n",
+ "Tor = round(Tau*math.pi*l*b*r/2,1)\n",
+ "P = Tor*2*math.pi*N/60\n",
+ "print \t\t\t\n",
+ "#results\n",
+ "print \"Power required = %d W\"%(P)\n",
+ "\n",
+ "# Note : The answer is different due to rounding off error in textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Power required = 595 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.4 Page No : 15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "w = 1 \t\t\t#rad/s\n",
+ "T = 0.4 \t\t\t#N/m**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "mu = T/math.tan(w)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Viscosity = %.2f N s/m**2\"%(mu)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Viscosity = 0.26 N s/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.6 Page No : 19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "d = 0.05*10**-3 \t#diameter - m\n",
+ "T = 72.*10**-3 \t\t#surface tension of water - N/m\n",
+ "P = 101. \t\t\t#pressure - kN/m**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Pi = P*1000 + 2*T/(d/2)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Pressure = %.2f kN/m**2\"%(Pi/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pressure = 106.76 kN/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7 Page No : 19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "rho = 981. \t\t\t#dyn/cm**2\n",
+ "sigma = 72. \t\t\t#dyn/cm\n",
+ "theta = 0. \t \t\t#degrees\n",
+ "d = 0.5 \t\t \t#cm\n",
+ "depth = 90. \t\t\t#cm\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "h = 4*sigma*math.cos(math.radians(theta)) /(rho*d)\n",
+ "Td = depth-h\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"True depth = %.3f cm\"%(Td)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "True depth = 89.413 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_Of_Fluid_Mechanics/ch10.ipynb b/Principles_Of_Fluid_Mechanics/ch10.ipynb
new file mode 100644
index 00000000..83f386c6
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/ch10.ipynb
@@ -0,0 +1,200 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:be59baaa0b424ca36821aba74f7944f301ffd891c617783ec6544d131134dbbb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10 : The Boundary Layer"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.1 Page No : 379"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "v = 30. \t\t\t#velocity - m/s\n",
+ "nu = 1.5e-5 \t\t\t#m**2/s\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Re = 5*10**5\n",
+ "xc = Re*nu/v\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Transistion region = %.2f m\"%(xc)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Transistion region = 0.25 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.2 Page No : 388"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "u = 2. \t\t\t #velocity - m/s\n",
+ "x = 0.15 \t\t\t#length - m\n",
+ "nu = 1.5e-5 \t\t#m**2/s\n",
+ "B = 0.5 \t\t\t#m\n",
+ "rho = 1.22 \t\t\t#kg/m**3\n",
+ "\n",
+ "#calcualtions\n",
+ "Rx = u*x/nu\n",
+ "delta = 4.91*x/math.sqrt(Rx)\n",
+ "deltas = 1.729*x/math.sqrt(Rx)\n",
+ "Cf = 1.328/math.sqrt(Rx)\n",
+ "Ff = Cf*0.5*rho*u**2 *2*B*x\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Boundary layer thickness = %.2f cm\"%(delta*100)\n",
+ "print \" Displacement thickness = %.2f cm\"%(deltas*100)\n",
+ "print \" Average drag coeffcient = %.4f\"%(Cf)\n",
+ "print \" Drag force = %.4f N\"%(Ff)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Boundary layer thickness = 0.52 cm\n",
+ " Displacement thickness = 0.18 cm\n",
+ " Average drag coeffcient = 0.0094\n",
+ " Drag force = 0.0034 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.5 Page No : 400"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "U = 172.*1000/3600 \t\t\t#m/s\n",
+ "w = 3. \t \t\t#m\n",
+ "h = 3. \t\t \t#m\n",
+ "L = 100. \t\t\t #m\n",
+ "nu = 1.5e-5 \t\t\t#m**2/s\n",
+ "rho = 1.22 \t \t\t#kg/m**3\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Rl = U*L/nu\n",
+ "Cf = 0.074 /(Rl**(1./5))\n",
+ "Ff = Cf*0.5*rho*U**2 *w*h*L\n",
+ "power = Ff*U\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"power required = %.1f kW\"%(power/1000)\n",
+ "#The answer is a bit different due to rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "power required = 88.3 kW\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.6 Page No : 400"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "U = 4000. \t\t \t#m/s\n",
+ "L = 8. \t\t \t#m\n",
+ "nu = 3600.e-6 \t\t\t#m**2/s\n",
+ "rho = 1000. \t\t\t#kg/m**3\n",
+ "b = 5. \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Rl = U*L/nu\n",
+ "Cf = 0.074/Rl**(1./5) -1700/Rl\n",
+ "Ff = Cf*0.5*rho*(U/3600)**2 *L*b\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Skin friction drag = %.2f N\"%(Ff)\n",
+ "\n",
+ "# note : rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Skin friction drag = 69.75 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_Of_Fluid_Mechanics/ch11.ipynb b/Principles_Of_Fluid_Mechanics/ch11.ipynb
new file mode 100644
index 00000000..c955d372
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/ch11.ipynb
@@ -0,0 +1,284 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:bc810be53841861ce90eab0fd4e6714fb575581f40efe36263891984b30579a4"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11 : Forces on Immersed Bodies"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.1 Page No : 413"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "d = 1.2 \t\t \t#diameter - m\n",
+ "w = 1. \t \t\t #m\n",
+ "U = 60.*1000/3600 \t\t\t#speed - m/s\n",
+ "nu = 1.5e-5 \t\t\t#m**2/s\n",
+ "Cd = 0.4\n",
+ "rho = 1.22 \t\t \t#kg/m**3\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Rn = U*d/nu\n",
+ "A = d*w\n",
+ "Fd = Cd*0.5*rho*U**2 *A\n",
+ "M = 0.5*Fd\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Bending moment = %.2f h**2 N m\"%(M)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bending moment = 40.67 h**2 N m\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.2 Page No : 415"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "d = 0.006 \t\t\t#diameter - m\n",
+ "U = 0.01 \t\t\t#m/s\n",
+ "gaml = 8000. \t\t#specific weight - N/m**3\n",
+ "gams = 7.9*10**3 *9.81\n",
+ "mu = 13.9 \n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "mu = d**2 /18 *(gams - gaml)/U\n",
+ "RN = U*d*(gaml/9.81) /mu\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Viscosity of oil = %.1f Ns /m**2\"%(mu)\n",
+ "print \"Reynolds number of motion is = %.3f\"%RN\n",
+ "\n",
+ "# rounding off error. please check."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Viscosity of oil = 13.9 Ns /m**2\n",
+ "Reynolds number of motion is = 0.004\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.3 Page No : 416"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "s = 2.7\n",
+ "gamw = 9810. \t\t\t#N/m**3\n",
+ "mu = 0.001 \t\t\t#Ns/m**2\n",
+ "d = 0.15*10**-3 \t\t\t#m\n",
+ "rho = 1000. \t\t\t#kg/m**3\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "gams = s*gamw\n",
+ "U = d**2 *(gams-gamw)/(18*mu)\n",
+ "RN = U*d*rho/mu\n",
+ "Cd = (1+ 3./16 *RN)**0.5 *(24/RN)\n",
+ "U22 = 4./3 *d*(gams-gamw) /(Cd*rho)\n",
+ "U2 = math.sqrt(U22)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Settling velocity of sand in case 1 = %.2f m/s\"%(U)\n",
+ "print \" Settling velocity of sand in case 2 = %.4f m/s\"%(U2)\n",
+ "#The answer is a bit different due to rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Settling velocity of sand in case 1 = 0.02 m/s\n",
+ " Settling velocity of sand in case 2 = 0.0186 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.4 Page No : 417"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "A = 2. \t\t\t#area - m**2\n",
+ "U = 100*1000./3600 \t\t\t#speed-m/s\n",
+ "Cd = 0.32\n",
+ "rho = 1.24\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Fd = Cd*0.5*rho*U**2 *A\n",
+ "P = Fd*U\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Power required = %.1f kW\"%(P/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Power required = 8.5 kW\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.5 Page No : 417"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "ratio = 0.15\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "VU = (1/(1-ratio))**(1./3)\n",
+ "percent = (VU-1)*100\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"percent increase in speed = %.1f %%\"%(percent)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "percent increase in speed = 5.6 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.6 Page No : 419"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from sympy import Symbol,solve\n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "U = 50.*1000/3600 \t\t\t#speed - m/s\n",
+ "cd1 = 0.34\n",
+ "cd2 = 1.33\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "print (\"On solving for both convex and concave surfaces,\")\n",
+ "w = Symbol(\"w\")\n",
+ "ans = solve(1.98*(13.98 - 0.25*w) - (13.88 + 0.25*w))\n",
+ "w = ans[0]\n",
+ "N = w/(2*math.pi) *60\n",
+ "\n",
+ "#results\n",
+ "print \"rotational speed = %.1f rpm\"%(N)\n",
+ "\n",
+ "# note : value of w is slightly different because of sympy inbuilt method solve. but it is very accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On solving for both convex and concave surfaces,\n",
+ "rotational speed = 176.9 rpm\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_Of_Fluid_Mechanics/ch2.ipynb b/Principles_Of_Fluid_Mechanics/ch2.ipynb
new file mode 100644
index 00000000..a8c9b316
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/ch2.ipynb
@@ -0,0 +1,823 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:29c2c55c7f92ba07b1426c985419398b6baf83f563e8d0219eeaa4d84ad525c8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2 : Fluid Statics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1 Page No : 44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "h1 = 1.5 \t\t\t#m\n",
+ "h2 = 2. \t\t\t#m\n",
+ "g1 = 800. \t\t\t#kg/m**3\n",
+ "g2 = 1000. \t\t\t#kg/m**3\n",
+ "g = 9.81\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "P = h1*g*g1 + h2*g*g2\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Pressure at the bottom of the vessel = %.2f kN/m**2\"%(P/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pressure at the bottom of the vessel = 31.39 kN/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2 Page No : 44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "depth = 8000. \t\t\t#m\n",
+ "sw = 10.06 \t\t\t#kN/m**3\n",
+ "BM = 2.05*10**9 \t\t\t#N/m**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "g = sw*10**3 /(1- sw*10**3 *depth/BM)\n",
+ "Ph = 2.3*BM*math.log10(BM/(BM-depth*9.81*1025))\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Specific weight = %.2f kN/m**2\"%(g/1000)\n",
+ "print \" Pressure at depth h = %.2f MN/m**2\"%(Ph/10**6)\n",
+ "\n",
+ "# note : rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Specific weight = 10.47 kN/m**2\n",
+ " Pressure at depth h = 81.97 MN/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3 Page No : 55"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "Patm = 101.3/9.81 \t\t\t#m of water\n",
+ "x1 = 0.45 \t\t\t#m\n",
+ "x2 = 0.3 \t\t\t#m\n",
+ "s1 = 920. \t\t\t#Kg/m**3\n",
+ "s2 = 13.6 \t\t\t#Kg/m**3\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Pa = (s1*x1*g + s2*x2*g)/1000\n",
+ "Pa2 = Pa*10**3/(1000*g)\n",
+ "Pa3 = Pa/(s2)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Pressure at A = %.1f kPa\"%Pa\n",
+ "print \" Pressure at A = %.3f m of water\"%(Pa2)\n",
+ "print \" Pressure at A = %.3f m of mercury\"%(Pa3)\n",
+ "print \" Pressure at A = %.1f m of water absolute\"%(Pa/1000 +101.3)\n",
+ "print \" Pressure at A = %.3f m of mercury\"%(Pa2+10.3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pressure at A = 4.1 kPa\n",
+ " Pressure at A = 0.418 m of water\n",
+ " Pressure at A = 0.302 m of mercury\n",
+ " Pressure at A = 101.3 m of water absolute\n",
+ " Pressure at A = 10.718 m of mercury\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4 Page No : 55"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "sg = 1.25 # gravity\n",
+ "d = 0.5 \t\t\t#m\n",
+ "d2 = 13.5*10**-2\t#m\n",
+ "sw = 9.81 \t\t\t#specific weight of water - kN/m**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "sl = sg*sw #specific weight of liquid\n",
+ "sm = 13.6*sw #specfic weight of mercury\n",
+ "Pa = sl*d - sm*d2\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Pressure at A = %.2f kN/m**2 vacuum \"%(-Pa)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pressure at A = 11.88 kN/m**2 vacuum \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5 Page No : 56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "#Following values are ontained from the figure 2.17\n",
+ "s1 = 0.85\n",
+ "s2 = 13.6\n",
+ "z1 = 30\n",
+ "z2 = 15\n",
+ "z3 = 20\n",
+ "z4 = 35\n",
+ "z5 = 60\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "dHa = s1*(z1+z5+z3-z4) +s2*z4 -z3+s2*z2-s1*(z1+z2) #Ha-Hb\n",
+ "Pd = 1000*9.81*dHa/100 #Pa-Pb\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Pressure difference = %.2f kN/m**2\"%(Pd/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pressure difference = 67.25 kN/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.6 Page No : 57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "P = 450 \t\t\t#pressure - kN/m**2\n",
+ "alt = 2000 \t\t\t#altitude - m\n",
+ "r = 610 \t\t\t#atmospheric pressure - mm of mercury\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Pat = 760-r\n",
+ "Pat2 = Pat*13.6*9.81*10**-3\n",
+ "Pg = Pat2+P\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Gauge reading = %.2f kN/m**2\"%(Pg)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gauge reading = 470.01 kN/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.7 Page No : 62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#kN/m**2\n",
+ "hc = 16.25 \t\t\t#m\n",
+ "w = 1.5 \t\t\t#width - m\n",
+ "b = 2.5 \t\t\t#depth - m\n",
+ "f = 0.3 #coefficient of friction\n",
+ "Pi = 50. \t\t\t#weight of gate - kN\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "P = g*hc*w*b\n",
+ "Preq = Pi+f*P\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Force required to lift the gate = %.2f kN\"%(Preq)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Force required to lift the gate = 229.34 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8 Page No : 62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "a = 6. \t\t\t#m\n",
+ "b = 8. \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Ixy = 9./32 *b**4 /4\n",
+ "xp = Ixy/(2./3 *b *1./2 *a*b)\n",
+ "ICG = 1./36 *a*b**3\n",
+ "yp = 2./3*b + ICG/(2./3 *b* 1./2 *a*b )\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"The coordinates of centre of pressure are %.2f,%d\"%(xp,yp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The coordinates of centre of pressure are 2.25,6\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9 Page No : 63"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "z = 1.2 \t\t\t#m\n",
+ "y = 1. \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "hp = 0.6 + 1./12 *y*z**3 /(0.6*y*z)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Position of hinge = %.1f m\"%(hp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Position of hinge = 0.8 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.10 Page No : 64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from sympy import *\n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "r = 0.75 \t\t\t#radius of plane - m\n",
+ "gam = 8. \t\t\t#specific weight of fluid - kN/m**3\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "P = gam*2./3 *r**3\n",
+ "hp = Symbol('hp')\n",
+ "hp = 4*r/(3*math.pi) + (math.pi/gam - gam/(9*math.pi)) * r**4/(4*r/(3*math.pi) * 1./2*math.pi*r**3)\n",
+ "\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \" Total pressure = %.2f kN\"%(P)\n",
+ "print \"Total pressure location = %.3f m\"%(hp)\n",
+ "\n",
+ "# note : answer is slightly different because of rounding off error. please check."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Total pressure = 2.25 kN\n",
+ "Total pressure location = 0.483 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.11 Page No : 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "B = 3. \t\t\t#m\n",
+ "b = 2. \t\t\t#m\n",
+ "h1 = 0.75 \t\t\t#m\n",
+ "h2 = 1. \t\t\t#m\n",
+ "sg = 0.9 #specific gravity\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "IP = sg*9.81*h2\n",
+ "F1 = 0.5*IP*h2\n",
+ "F2 = IP*h1\n",
+ "F3 = 0.5*(9.81*h1)*h1\n",
+ "F = B*(F1+F2+F3)\n",
+ "ybar = (F1*(h1+ 1./3) + F2* h1/2 + F3* h1/3)/(F1+F2+F3)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Total force = %.2f kN\"%(F)\n",
+ "print \"Location = %.3f m from the base\"%(ybar)\n",
+ "\n",
+ "# note : rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total force = 41.39 kN\n",
+ " Location = 0.577 m from the base\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12 Page No : 67"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from scipy.integrate import quad\n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 1000*9.81 \t\t\t#kg/m**3\n",
+ "hc = 20. \t\t\t#m\n",
+ "Ax = 40.*1 \t\t\t#m**2\n",
+ "y1 = 0. \t\t\t#m\n",
+ "y2 = 40. \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Fx = g*hc*Ax\n",
+ "def fy(y):\n",
+ " return (12*y)**(1./3)\n",
+ "\n",
+ "Fy = quad(fy,y1,y2)\n",
+ "Fy = g*Fy[0]\n",
+ "F = math.sqrt(Fx**2 +Fy**2)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Net force = %d kN\"%(F/1000)\n",
+ "#The answer is a bit different due to rounding off error in the textbook"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Net force = 8179 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.13 Page No : 68"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#kN/m**2\n",
+ "hc = 1. \t\t\t#m\n",
+ "l = 3. \t\t\t#m\n",
+ "b = 0.5 \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Ax = l*b \t\t\t#m**2\n",
+ "Fx = g*hc*Ax\n",
+ "Fz = g*(0.5* math.pi/4 *b**2)*l\n",
+ "F = math.sqrt(Fx**2 + Fz**2)\n",
+ "theta = math.degrees(math.atan(Fz/Fx))\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Magintude of resultant force = %.3f kN\"%(F)\n",
+ "print \" Direction of the resultant force = %.1f deg\"%(theta)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Magintude of resultant force = 14.996 kN\n",
+ " Direction of the resultant force = 11.1 deg\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.14 Page No : 71"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "r1 = 920. \t\t\t#density of ice - kg/m**3\n",
+ "r2 = 1030. \t\t\t#density of sea water - kg/m**3\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "VtbyV2 = r2/r1\n",
+ "V1byV2 = VtbyV2-1\n",
+ "V1byVt = 1./(1+1/V1byV2)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"fraction = %.3f \"%(V1byVt)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "fraction = 0.107 \n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.15 Page No : 72"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "d = 3. \t\t\t #diameter of balloon - m\n",
+ "rh1 = 1.19 \t\t\t#density of air - kg/m**3\n",
+ "rh2 = 0.17 \t\t\t#density of helium - kg/m**3 \n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "pay = (rh1-rh2)*g*math.pi/6 *d**3\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \" Pay load = %.2f N\"%(pay)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Pay load = 141.46 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.16 Page No : 76"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import roots\t\t\t\n",
+ "#calculations\n",
+ "y = [6,-6,1]\n",
+ "z = roots(y)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"For stability, s must be greater than %.2f and less than %.2f and must be less than 1\"%(z[0],z[1])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For stability, s must be greater than 0.79 and less than 0.21 and must be less than 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.17 Page No : 81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "ax = 1.5 \t\t\t#m/s**2\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "alpha = math.degrees(math.atan(ax/g))\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"The interface is inclined at %.f degrees with the horizontal\"%(alpha)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The interface is inclined at 9 degrees with the horizontal\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.18 Page No : 81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "d = 10. \t\t\t#diameter - cm\n",
+ "h = 25. \t\t\t#height - cm\n",
+ "hw = 15. \t\t\t#cm\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "z = d**2 *d*2/d**2\n",
+ "w = math.sqrt(z*2*g/(d/2)**2 *100)\n",
+ "N = w/(2*math.pi) *60\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Speed of rotation = %d rpm\"%(N)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Speed of rotation = 378 rpm\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.19 Page No : 82"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from scipy.integrate import quad\n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "dia = 1. \t\t\t#diameter - m\n",
+ "h = 3. \t\t\t #height - m\n",
+ "rho = 1000. \t\t#kg/m**3\n",
+ "N = 80. \t\t\t#rpm\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "\n",
+ "#calculation\n",
+ "w = 2*math.pi*N/60\n",
+ "def fun(r):\n",
+ " return 0.5*rho*w**2 *r**3 *2*math.pi\n",
+ "\n",
+ "vec = quad(fun,0,dia/2)\n",
+ "Pt = vec[0] + math.pi/4 *dia**2 *(h-dia)*rho*g\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Total pressure on base = %.2f kN\"%(Pt/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total pressure on base = 18.85 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_Of_Fluid_Mechanics/ch3.ipynb b/Principles_Of_Fluid_Mechanics/ch3.ipynb
new file mode 100644
index 00000000..b45e37c3
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/ch3.ipynb
@@ -0,0 +1,101 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e51408600d11e929cd24c31057edae00d199336d2c2b7260dda7e3b7642c128f"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3 : Conservation Principle of Mass"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3 Page No : 100"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "d1 = 60. \t\t\t#diameter of a section of pipe - cm\n",
+ "V1 = 45. \t\t\t#velocity of water - cm/s\n",
+ "d2 = 90. \t\t\t#diameter of enlarged section - cm\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V2 = V1*d1**2 /d2**2\n",
+ "Q = math.pi/4 *d1**2 *V1 *10**-6\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Velocity at point 2 = %d cm/s\"%(V2)\n",
+ "print \" FLow rate = %.4f m**3/s\"%(Q)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Velocity at point 2 = 20 cm/s\n",
+ " FLow rate = 0.1272 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.4 Page No : 100"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "dn1 = 4 \t\t\t#spacing between streamlines - cm\n",
+ "v1 = 300. \t\t\t#velocity - cm/s\n",
+ "dn2 = 2.5 \t\t\t#spacing - cm\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "v2 = v1*dn1/dn2\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Velocity = %.1f m/s\"%(v2/100)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Velocity = 4.8 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_Of_Fluid_Mechanics/ch4.ipynb b/Principles_Of_Fluid_Mechanics/ch4.ipynb
new file mode 100644
index 00000000..b908467d
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/ch4.ipynb
@@ -0,0 +1,346 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:4641f495fb637b43843e8fcd55506866f439259b641b4627c67482beed84d471"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4 : Conservation Principle of Momentum"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.1 Page No : 111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "Q = 0.2 \t\t\t#m**3/s\n",
+ "v = 30. \t\t\t#m/s\n",
+ "angle = 120. \t\t\t#degrees\n",
+ "rho = 1000. \t\t\t#kg/m**3\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Rx = rho*Q*(v-v*math.cos(math.radians(angle)))\n",
+ "Ry = rho*Q*v*math.sin(math.radians(angle))\n",
+ "R = math.sqrt(Rx**2 +Ry**2)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Resultant force = %.2f kN\"%(R/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resultant force = 10.39 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3 Page No : 112"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "angle = 45. \t\t#degrees\n",
+ "p1 = 150.*10**3 \t#pressure at inlet - N/m**2\n",
+ "Q = 0.5 \t\t\t#rate of flow - m**3/s\n",
+ "d1 = 60. \t\t\t#cm\n",
+ "d2 = 30. \t\t\t#cm\n",
+ "rho = 1000. \t\t#kg/m**3\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V1 = Q/(math.pi/4 *(d1/100)**2)\n",
+ "V2 = V1*(d1/d2)**2\n",
+ "P2 = rho*g*(p1/(rho*g) + V1**2 /(2*g) -V2**2 /(2*g))\n",
+ "Rx = p1*math.pi/4*(d1/100)**2 - P2*math.pi/4 *(d2/100)**2 *math.cos(math.radians(angle)) -rho*Q*(V2*math.cos(math.radians(angle)) -V1)\n",
+ "Ry = P2*math.pi/4 *(d2/100)**2 *math.sin(math.radians(angle)) + rho*Q*(V2*math.sin(math.radians(angle)))\n",
+ "R = math.sqrt(Rx**2 + Ry**2)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"resultant force = %.2f kN\"%(R/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resultant force = 35.58 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4 Page No : 113"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "Q = 20.*10**3 \t\t\t#discharge - cc/s\n",
+ "depth = 4. \t\t\t#m\n",
+ "d = 5. \t \t\t#cm\n",
+ "g = 9.81 \t\t \t#m/s**2\n",
+ "rho = 10.**3 \t\t\t#kg/m**3\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V1 = Q/(math.pi/4 *d**2) /100\n",
+ "V2 = math.sqrt(2*g*(V1**2/(2*g) + depth))\n",
+ "W = rho*Q*(V2-V1)/10**6\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"weight of water = %d N\"%(W)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "weight of water = 66 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.5 Page No : 116"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t \t\t#m/s**2\n",
+ "rho = 10.**3 \t\t\t#kg/m**3\n",
+ "V = 50. \t\t \t#velocity - m/s\n",
+ "u = 20. \t\t\t #m/s\n",
+ "A = 6./10**4 \t\t\t#area - m**2\n",
+ "angle = 180. \t\t\t#degrees\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Vr = V-u\n",
+ "rq = rho*A*Vr\n",
+ "Rx = -rq*(Vr*math.cos(math.radians(angle)) - Vr)\n",
+ "Rx2 = -rho*A*V*(Vr*math.cos(math.radians(angle)) -Vr)\n",
+ "power = Rx2*u\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Force exetred on fluid = %d N\"%(Rx)\n",
+ "print \" Force transferred in case 2 = %d N\"%(Rx2)\n",
+ "print \" Power transferred in case 2 = %d kW\"%(power/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Force exetred on fluid = 1080 N\n",
+ " Force transferred in case 2 = 1800 N\n",
+ " Power transferred in case 2 = 36 kW\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6 Page No : 119"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "Vr = 10. \t\t\t#m/s\n",
+ "u = 8.5 \t\t\t#m/s\n",
+ "A = 250./10**4 \t\t#m**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V = Vr-u\n",
+ "Q = A*Vr\n",
+ "R = rho*Q*V\n",
+ "P = R*u\n",
+ "eth = 1/(1+ V/(2*u))\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Power required = %.3f kW\"%(P/1000)\n",
+ "print \" Efficiency of jet propulsion = %.0f percent\"%(eth*100)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Power required = 3.188 kW\n",
+ " Efficiency of jet propulsion = 92 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7 Page No : 123"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "v1 = 20. \t\t\t#m/s\n",
+ "v2 = 5. \t\t\t#m/s\n",
+ "r1 = 50./100 \t\t#cm\n",
+ "r2 = 30./100 \t\t#cm\n",
+ "a1 = 20. \t\t\t#degrees\n",
+ "a2 = 80. \t\t\t#degrees\n",
+ "N = 300. \t\t\t#rpm\n",
+ "Q = 5. \t\t\t #m**3/s\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "u1 = round(math.pi*2*r1*N/60,1)\n",
+ "u2 = round(math.pi*2*r2*N/60,2)\n",
+ "T = rho*Q*(r1*v1*math.cos(math.radians(a1)) - r2*v2*math.cos(math.radians(a2)))\n",
+ "H = 1/g *(u1*v1*math.cos(math.radians(a1)) - u2*v2*math.cos(math.radians(a2)))\n",
+ "power = rho*g*Q*H\n",
+ "\t\n",
+ " \n",
+ "#results\n",
+ "print \"torque = %d N m\"%(T)\n",
+ "print \" Heat = %.1f m\"%(H)\n",
+ "print \" Power = %d kW\"%(power/10**3)\n",
+ "\n",
+ "# Note :The answers given in textbook are a bit different due to rounding off error. please check using calculator."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "torque = 45682 N m\n",
+ " Heat = 29.2 m\n",
+ " Power = 1434 kW\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8 Page No : 124"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "d1 = 0.05 \t\t\t#m\n",
+ "d2 = 0.3 \t\t\t#m\n",
+ "N = 1800. \t\t\t#rpm\n",
+ "Q = 0.425/60 \t\t#m**3/s\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "u1 = math.pi*d1*N/60\n",
+ "u2 = math.pi*d2*N/60\n",
+ "T = rho*Q*(d2*u2 - d1*u1)/2\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Torque supplied = %.1f Nm\"%(T)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Torque supplied = 29.2 Nm\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_Of_Fluid_Mechanics/ch5.ipynb b/Principles_Of_Fluid_Mechanics/ch5.ipynb
new file mode 100644
index 00000000..2be5eb9c
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/ch5.ipynb
@@ -0,0 +1,1167 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:69eae1e264ff987be7aef011e3a2b59c7c97d8a9f2c6d4a88b429794581f1dc0"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5 : Conservation Principle of Energy"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.1 Page No : 136"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "z2 = 0. \t\t\t#m\n",
+ "z1 = 8. \t\t\t#m\n",
+ "V2 = 5. \t\t\t#outlet velocity - m/s\n",
+ "V1 = 3. \t\t\t#inlet velocity - m/s\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Hs = (z2-z1) + (V2**2 -V1**2)/(2*g)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Work done by fluid = %.3f J/N\"%(Hs)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Work done by fluid = -7.185 J/N\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2 Page No : 137"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t #m/s**2\n",
+ "rho = 10.**3 \t\t\t#kg/m**3\n",
+ "P1 = 80.*10**3 \t\t\t#N/m**2\n",
+ "P2 = 12.*10**6 + 101300 \t\t\t#N/m**2\n",
+ "Hq = -400. \t\t\t#J/N\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "g1 = g*rho\n",
+ "Hs = -Hq+ (P2-P1)/(g1)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Energy added by pump = %d J/N\"%(Hs)\n",
+ "print (\"The answer given in textbook is wrong. Please verify using a calculator\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Energy added by pump = 1625 J/N\n",
+ "The answer given in textbook is wrong. Please verify using a calculator\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.3 Page No : 140"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "d1 = 15. \t\t\t#cm\n",
+ "d2 = 10. \t\t\t#cm\n",
+ "V1 = 2.4 \t\t\t#m/s\n",
+ "P1 = 450.*10**3 \t\t\t#N/m**2\n",
+ "rho2 = 900. \t\t\t#kg/m**3\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V2 = d1**2 /d2**2 *V1\n",
+ "P2 = g*rho2*(P1/(rho2*g) + V1**2 /(2*g) - V2**2 /(2*g))\n",
+ "Q = math.pi/4*(d2/100)**2 *V2\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Pressure at 2 = %.2f kN/m**2\"%(P2/1000)\n",
+ "print \" Flow rate = %.4f m**3/s\"%(Q)\n",
+ "#The answer given in textbook is wrong. Please verify it."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pressure at 2 = 439.47 kN/m**2\n",
+ " Flow rate = 0.0424 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4 Page No : 140"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t \t\t#m/s**2\n",
+ "rho = 10.**3 \t\t\t#kg/m**3\n",
+ "z = 10. \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "PE = g*rho*math.pi*z**2 /2\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Work obtained = %.2e J\"%(PE)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Work obtained = 1.54e+06 J\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6 Page No : 141"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10**3 \t\t\t#kg/m**3\n",
+ "d1 = 7.5 \t \t\t#diameter - cm\n",
+ "d2 = 3. \t\t\t #cm\n",
+ "P1 = 300+101.3 \t\t\t#pressure - kPa\n",
+ "P2 = 25. \t\t \t#kPa\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V1 = math.sqrt(2*g/ ((d1/d2)**4 -1) *(P1*10**3 /(rho*g) -P2*10**3 /(rho*g)))\n",
+ "Q = math.pi/4 *(d1/100)**2 *V1\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Max discharge = %.4f m**3/s\"%(Q)\n",
+ "#The answer given in textbook is wrong. Please use a calculator to verify"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Max discharge = 0.0196 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.7 Page No : 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10**3 \t\t#kg/m**3\n",
+ "z1 = 1.2 \t\t\t#m\n",
+ "z2 = 4. \t\t\t#m\n",
+ "d = 5. \t\t\t#cm\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Va = math.sqrt(2*g*(z2-z1))\n",
+ "Q = math.pi/4 *(d/100)**2 *Va\n",
+ "Pc = - z2*rho*g\n",
+ "P = 25*10**3 \t\t\t#Pa\n",
+ "Zab = (101325 - P)/rho/g\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"rate of discharge = %.4f m**3/s\"%(Q)\n",
+ "print \" Pressure at C = %.2f kPa\"%(Pc/1000)\n",
+ "print \" Max. permissible length = %.2f m\"%(Zab)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rate of discharge = 0.0146 m**3/s\n",
+ " Pressure at C = -39.24 kPa\n",
+ " Max. permissible length = 7.75 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.8 Page No : 146"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "Q = 0.09 \t\t\t#m**3/s\n",
+ "d1 = 0.12 \t\t\t#diameter - m\n",
+ "d2 = 0.2 \t\t\t#diameter - m\n",
+ "P1 = 80. \t\t\t#pressure - kN/m**2\n",
+ "P2 = 120. \t\t\t#pressure - kN/m**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V1 = Q/(math.pi/4 *d1**2)\n",
+ "TE1 = P1*10**3 /(rho*g) + V1**2 /(2*g)\n",
+ "V2 = d1**2 /d2**2 *V1\n",
+ "TE2 = P2*10**3 /(rho*g) + V2**2 /(2*g)\n",
+ "\t\t\n",
+ "#results\n",
+ "if TE1>TE2 :\n",
+ " print \"Flow is from section 1 to section 2\"\n",
+ "else:\n",
+ " print \"Flow is from section 2 to section 1\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Flow is from section 2 to section 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.9 Page No : 147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "Q = 0.012 \t\t\t#m**3/s\n",
+ "z = 10. \t\t\t#m\n",
+ "d = 0.075 \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Vb = Q/(math.pi/4 *d**2)\n",
+ "Hm = z+ Vb**2 /(2*g)\n",
+ "P = Hm*rho*g*Q\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Power required = %.3f kW\"%(P/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Power required = 1.221 kW\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.10 Page No : 150"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 860. \t\t\t#kg/m**3\n",
+ "P1 = 20. *10**3 \t#Pa\n",
+ "P2 = 50.*10**3 \t\t#Pa\n",
+ "z = 2.8 \t\t\t#m\n",
+ "d1 = 0.1 \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V1 = math.sqrt(2*g*(P2/(rho*g) -z - P1/(rho*g)))\n",
+ "Q = math.pi/4 *d1**2 *V1\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"rate of flow = %.4f m**3/s\"%(Q)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rate of flow = 0.0302 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.11 Page No : 156"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "Cv = 0.92 #coefficient of velocity\n",
+ "P = 210.*10**3 \t\t#Pressure - Pa\n",
+ "d = 0.05 \t\t\t#m\n",
+ "ret = 1.5 \t\t\t#m/s**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "H = P/(g*rho)\n",
+ "Va = Cv*(2*g*H)\n",
+ "h = Cv**2 *H\n",
+ "h2 = Cv**2 *2*g*H/(2*(g+ret))\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"The height to which the jet will rise is %.2f m\"%(h)\n",
+ "print \" In case height = %.2f m\"%(h2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The height to which the jet will rise is 18.12 m\n",
+ " In case % height = 15.72 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.12 Page No : 157"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "h = 4. \t\t\t #m\n",
+ "d = 0.03 \t\t\t#m\n",
+ "Qa = 3.8/1000 \t\t#m**3/s\n",
+ "x = 2.5 \t\t\t#m\n",
+ "y = 0.41 \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Qth = math.pi/4 *d**2 *math.sqrt(2*g*h)\n",
+ "Cd = Qa/Qth\n",
+ "Cv = math.sqrt(x**2 /(4*y*h))\n",
+ "Cc = Cd/Cv\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Cd = %.2f\"%(Cd)\n",
+ "print \" Cv = %.3f\"%(Cv)\n",
+ "print \" Cc = %.2f\"%(Cc)\n",
+ "\n",
+ "# note : rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Cd = 0.61\n",
+ " Cv = 0.976\n",
+ " Cc = 0.62\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.13 Page No : 157"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "rho2 = 13.6*10**3 \t#kg/m**3\n",
+ "d1 = 3.2 \t\t\t#m\n",
+ "d2 = 0.6 \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "z1 = d1*rho/rho2\n",
+ "head = d2+z1\n",
+ "V = math.sqrt(2*g*head)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Efflux velocity = %.2f m/s\"%(V)\n",
+ "#The answer is a bit different due to rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Efflux velocity = 4.05 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.15 Page No : 159"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from scipy.integrate import quad\n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "Cd = 0.6\n",
+ "d = 0.04 \t\t\t#m\n",
+ "h2 = 2.5 \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "def fun(h):\n",
+ " return 1/(Cd*math.pi/4 *d**2 *math.sqrt(2*g)) *(4/math.sqrt(h) + math.sqrt(64-h**2))\n",
+ "\n",
+ "t = quad(fun,0,h2)[0]\n",
+ "tmin = 31.1\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Time required = %.1f min\"%(tmin)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time required = 31.1 min\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.16 Page No : 160"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from scipy.integrate import quad\n",
+ "from sympy import solve,Symbol\n",
+ "\n",
+ "#Initialization of variables\n",
+ "g = 981. \t\t\t#cm/s**2\n",
+ "Cd = 0.6\n",
+ "Q = 1200.\n",
+ "d = 3. \t\t\t #cm\n",
+ "l = 30. \t\t\t#cm\n",
+ "b = 30. \t\t\t#cm\n",
+ "dh = 5. \t\t\t#cm\n",
+ "h1 = 9. \t\t\t#cm\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "def fun1(h):\n",
+ " return l*b/(Q - Cd*math.pi/4 *d**2 *math.sqrt(2*g*h))\n",
+ "#t = Symbol(\"t\")\n",
+ "#ans = solve((Q - Cd*math.pi/4*d**2*math.sqrt(2*g*h)*d*t) - (30*30*dh))\n",
+ "#print ans\n",
+ "t = quad(fun1,h1,h1+dh)[0]\n",
+ "t = 126\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Time required = %d sec\"%(t)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time required = 126 sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.17 Page No : 165"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "pst = 25.2*10**3 \t#pressure - Pa\n",
+ "h = 2.5 \t\t\t#depth - m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "v = math.sqrt(2/rho *(pst - g*rho*h))\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"velocity = %.2f m/s\"%(v)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "velocity = 1.16 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.18 Page No : 165"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t\t#kg/m**3\n",
+ "vel = 800.*10**3 /3600\n",
+ "sm = 13.57\n",
+ "sl2 = 12.2 #specific weight of air\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "sl = sl2/(g*rho)\n",
+ "y = vel**2 /(2*g*(sm/sl -1))\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"length of manometer = %.f cm\"%(y*100)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "length of manometer = 23 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.19 Page No : 166"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10**3 \t\t#kg/m**3\n",
+ "h = 3.5 \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "v = math.sqrt(2*g*h)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Speed necessary = %.1f m/s\"%(v)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Speed necessary = 8.3 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.20 Page No : 173"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "sm = 13.6 \n",
+ "s = 1.\n",
+ "Q = 1. \t\t\t#m**3/s\n",
+ "d2 = 0.25 \t\t\t#m\n",
+ "d1 = 0.5 \t\t\t#m\n",
+ "nu = 1e-6\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "RN = Q*d1/(math.pi/4 *d1**2 *nu)\n",
+ "Cv = 0.98\n",
+ "yd = Q**2 *(1-d2**4 /d1**4)/(Cv**2 *math.pi/4 *d2**2 *2*g)\n",
+ "y = yd/(sm/s -1)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Mercury manometer reading = %.2f cm\"%(y*100)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mercury manometer reading = 8.04 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.21 Page No : 174"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "sm = 13.6\n",
+ "s = 1.\n",
+ "y = 0.12 \t\t\t#m\n",
+ "Cv = 0.984\n",
+ "d1 = 0.05 \t\t\t#m\n",
+ "d2 = 0.1 \t\t\t#m\n",
+ "nu = 1e-6\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Q = Cv*math.pi/4 *d1**2 *math.sqrt(2*g) /math.sqrt(1- (d1/d2)**4) *math.sqrt(y*(sm/s -1))\n",
+ "V1 = Q/(math.pi/4 *d2**2)\n",
+ "R = V1*d1/nu\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Since reynolds number is in required value Flow rate = %.4f m**3/s\"%(Q)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Since reynolds number is in required value Flow rate = 0.0109 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.22 Page No : 174"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "P1 = 150.*10**3 \t#pressure - Pa\n",
+ "d0 = 3. \t\t\t#cm\n",
+ "d1 = 6. \t\t\t#diameter - cm\n",
+ "Cv = 0.98 \n",
+ "Cc = 0.62\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "P1g = P1/(g*rho)\n",
+ "Ar = (d0/d1)**4\n",
+ "A0 = math.pi/4 *(d0/100)**2\n",
+ "Q = Cv*Cc*A0 *math.sqrt(2*g) /math.sqrt(1- Cc**2 *Ar) *math.sqrt(P1g)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Discharge = %.2f lps\"%(Q*10**3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Discharge = 7.53 lps\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.23 Page No : 182"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from numpy import *\n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10**3 \t\t#kg/m**3\n",
+ "Cd = 0.6\n",
+ "L = 3 \t\t\t #m\n",
+ "H = 0.4 \t\t\t#m\n",
+ "V0 = array([0, 0.24, 0.275])\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Q = Cd*2/3 *math.sqrt(2*g) *(L-0.2*H) *((H+ V0**2 /(2*g) )**(3./2) - (V0**2 / (2*g))**(3./2))\n",
+ "\t\t\t\n",
+ "#results\n",
+ "H = max(Q)\n",
+ "print \"Flow rate = %.2f m**3/s\"%(H)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Flow rate = 1.33 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.24 Page No : 183"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from sympy import Symbol, solve\n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "d = 0.5 \t\t\t#m\n",
+ "vel = 1. \t\t\t#m/s\n",
+ "depth = 1.2 \t\t#m\n",
+ "Cd = 0.62\n",
+ "L = 1\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "#H = Symbol(\"H\")\n",
+ "#ans = solve(d*L/(Cd*2./3*L*H**(3./2)) - 1)\n",
+ "#print ans\n",
+ "H = (d*3./(2*Cd))**(2/3.)\n",
+ "hw = depth-H\n",
+ "\t\n",
+ "#results\n",
+ "print \"height of weir plate = %.2f m\"%(hw)\n",
+ "\n",
+ "# note : value of H is calculated wrongly. please check."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "height of weir plate = 0.06 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.25 Page No : 184"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t\t#kg/m**3\n",
+ "Q = 0.1*100**2 /(24.*3600) \t\t\t#m**3/s\n",
+ "Cd = 0.61\n",
+ "theta = 60. \t\t\t#degrees\n",
+ "\n",
+ "#Calculations\n",
+ "Hd = Q/(Cd*8./15 *math.sqrt(2*g) *math.tan(math.radians(theta/2)))\n",
+ "H = Hd**(2./5)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"apex of weir must be set %.1f cm below the free surface\"%(H*100)\n",
+ "\n",
+ "#The answer in the textbook is wrong. Please verify it"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "apex of weir must be set 18.1 cm below the free surface\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.26 Page No : 184"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "Q1 = 0.93 #m**3/s \n",
+ "Q2 = 0.4 #m**3/s\n",
+ "H1 = 0.7 #m\n",
+ "H2 = 0.5 #m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "n = math.log(Q1/Q2) /math.log(H1/H2)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Shape n = %.1f . hence shape of weir is triangular\"%(n)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Shape n = 2.5 . hence shape of weir is triangular\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.27 Page No : 185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 981. \t\t\t#cm/s**2\n",
+ "H = 20. \t\t\t#cm\n",
+ "err = 3./100\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "dH = err/2.5 *H\n",
+ "v0 = math.sqrt(2*g*dH)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Required velocity = %.2f cm/s\"%(v0)\n",
+ "\n",
+ "#The answer is a bit different due to rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Required velocity = 21.70 cm/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.28 Page No : 185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from scipy.integrate import quad\n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "Q = 12000. \t\t\t#m**2\n",
+ "f = 30. \t\t\t#h**2/3\n",
+ "t1 = 0.5 \t\t\t#m\n",
+ "t2 = 1.2 \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "def fun2(h):\n",
+ " return Q/f *(1/h**(3./2))\n",
+ "\n",
+ "t = quad(fun2,t1,t2)[0]\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Time = %d sec\"%(t)\n",
+ "\n",
+ "#The answer is different due to rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time = 401 sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_Of_Fluid_Mechanics/ch6.ipynb b/Principles_Of_Fluid_Mechanics/ch6.ipynb
new file mode 100644
index 00000000..cd7afbaa
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/ch6.ipynb
@@ -0,0 +1,236 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:6e7275009478231e09bfec0423553af7b62637e958570036cb846adaade3feab"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6 : Dimensional Analysis and Similitude"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.11 Page No : 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "dw = 1000. \t\t\t#density of water - kg/m**3\n",
+ "muw = 0.001 \t\t#viscosity of water - N s /m**2\n",
+ "da = 1.225 \t\t\t#density of air - kg/m**3\n",
+ "mua = 18.*10**-6 \t#viscosity of air - N s /m**2\n",
+ "lr = 1./10\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "dr = da/dw\n",
+ "mur = mua/muw\n",
+ "vr = mur/dr\n",
+ "velocity = vr/lr\n",
+ "discharge = lr*vr\n",
+ "pressure = mur**2 /(dr*lr**2)\n",
+ "force = mur**2 /dr\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Scale ratio for velocity = %.f \"%(velocity)\n",
+ "print \"Scale ratio for discharge = %.2f \"%(discharge)\n",
+ "print \"Scale ratio for pressure = %.1f \"%(pressure)\n",
+ "print \"Scale ratio for force = %.3f \"%(force)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Scale ratio for velocity = 147 \n",
+ "Scale ratio for discharge = 1.47 \n",
+ "Scale ratio for pressure = 26.4 \n",
+ "Scale ratio for force = 0.264 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.12 Page No : 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "dr = 1000.\n",
+ "mur = 100. #times\n",
+ "lr = 1./10 #prototype size\n",
+ "dpm = 60. #kN/m**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Vr = mur/dr/lr\n",
+ "dpr = dr*Vr**2\n",
+ "dpp = dpm/dpr\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Pressure drop in prototype = %d N/m**2\"%(dpp*10**3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pressure drop in prototype = 60 N/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.14 Page No : 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "lr = 1./25\n",
+ "Tp = 6. \t\t\t#sec\n",
+ "dr = 1./1.025\n",
+ "Fm = 70. \t\t\t#N\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Tr = lr**(0.5)\n",
+ "Tm = Tr*Tp\n",
+ "Fr = dr*lr**3\n",
+ "Fp = Fm/Fr\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Wave period = %.1f sec\"%(Tm)\n",
+ "print \"Force = %.3f kN\"%(Fp/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wave period = 1.2 sec\n",
+ "Force = 1121.094 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.16 Page No : 227"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "lr = 1./10 #scale ratio\n",
+ "Vp = 10. \t\t\t#speed - knots\n",
+ "Fm = 12. \t\t\t#tension - N\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Vm = Vp*math.sqrt(lr)\n",
+ "Fp = Fm/lr**3\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"force = %.1f kN\"%(Fp/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "force = 12.0 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.17 Page No : 229"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "lr = 1./7200\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Tr = 60./(12*3600)\n",
+ "yr = (lr/Tr)**2\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"vertical scale to be adopted is 1 in %d\"%(1/yr)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "vertical scale to be adopted is 1 in 100\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_Of_Fluid_Mechanics/ch7.ipynb b/Principles_Of_Fluid_Mechanics/ch7.ipynb
new file mode 100644
index 00000000..bbf860be
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/ch7.ipynb
@@ -0,0 +1,1067 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:de3cacdaf57dab2533c3d6a29cdb98f8a7442d8b301aac65e35672e8b8cf9017"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7 : Incompressible Flow Through Conduits"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.1 Page No : 240"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "h1 = 4. \t\t\t#m\n",
+ "muw = 0.001 \t\t#Ns/m**2\n",
+ "l = 1.5 \t\t\t#m\n",
+ "B = 0.15/1000 \t\t#m\n",
+ "lenth = 11.2 \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "P1 = g*rho*h1\n",
+ "V = P1*B**2 /(12*muw*l)\n",
+ "A = B*lenth\n",
+ "Q = A*V\n",
+ "Q = 7112.4\n",
+ "tau = B/2 *(P1)/l\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Average velocity through the crack = %.3f m/s\"%(V)\n",
+ "print \" rate of leakage = %.1f l/hr\"%(Q)\n",
+ "print \" Shear stress = %.3f N/m**2\"%(tau)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average velocity through the crack = 0.049 m/s\n",
+ " rate of leakage = 7112.4 l/hr\n",
+ " Shear stress = 1.962 N/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2 Page No : 242"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 1200. \t\t\t#kg/m**3\n",
+ "mu = 0.005 \t\t\t#Ns/m**2\n",
+ "d = 0.006 \t\t\t#m\n",
+ "Re = 2000.\n",
+ "V = 0.15 \t\t\t#m/s\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Vc = Re*mu/(d*rho)\n",
+ "Vr = V/Vc\n",
+ "T0 = 8*mu*V/d\n",
+ "\t\n",
+ "#results\n",
+ "print \"Shear stress = %d N/m**2\"%(T0)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Shear stress = 1 N/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3 Page No : 243"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "Q = 0.45/(60*1000) \t#m**3/s\n",
+ "d = 0.003 \t\t\t#m\n",
+ "depth = 0.95 \t\t#m\n",
+ "alpha = 2.\n",
+ "lenth = 1.25 \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "A = math.pi/4 *d**2\n",
+ "V = Q/A\n",
+ "nu = (depth - alpha*V**2 /(2*g))*g*d**2 /(32*V*lenth)\n",
+ "Re = V*d/nu\n",
+ "\t\t\t\n",
+ "#results\n",
+ "if Re<2000:\n",
+ " print \"Flow is laminar\"\n",
+ "else:\n",
+ " print \"Flow is not laminar\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Flow is laminar\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.4 Page No : 262"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 787. \t\t\t#specific gravity - kg/m**3\n",
+ "Q = 90.*10**-3 \t\t#m**3/hr\n",
+ "d = 0.015 \t\t\t#m\n",
+ "k = 0.0045*10**-2 \t#m\n",
+ "nu = 1.6e-6 #kinematic viscosity - m^2/s\n",
+ "l = 5. \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V = Q/(60*math.pi/4 *d**2)\n",
+ "Rn = V*d/nu\n",
+ "e = k/d\n",
+ "print (\"From moody diagram, f = 0.028\")\n",
+ "f = 0.028\n",
+ "hl = f*l/d *V**2 /(2*g)\n",
+ "Power = rho*g*Q/60 *hl\n",
+ "\t\t\t#result\n",
+ "print \"Head loss = %.2f m\"%(hl)\n",
+ "print \" power required = %.3f kW\"%(Power/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "From moody diagram, f = 0.028\n",
+ "Head loss = 34.27 m\n",
+ " power required = 0.397 kW\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5 Page No : 263"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 870. \t\t\t#density - kg/m**3\n",
+ "Q = 2.*10**-3 \t\t#m**3/s\n",
+ "d = 0.03 \t\t\t#diameter - m\n",
+ "mu = 5.*10**-4 #dynamics viscosity(N-s/m^2)\n",
+ "l = 50. \t\t\t#length - m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V = Q/(math.pi/4 *d**2)\n",
+ "RN = rho*V*d/mu\n",
+ "f = 0.017\n",
+ "hl = f*l/d *V**2/(2*g)\n",
+ "Ploss = rho*g*hl\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Loss of pressure = %.1f kN/m**2\"%(Ploss/1000)\n",
+ "#The answers are a bit different due to rounding off error in textbook"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Loss of pressure = 98.7 kN/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.6 Page No : 263"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 813. \t\t\t#density - kg/m**3\n",
+ "Q = 0.007 \t\t\t#m**3/hr\n",
+ "d = 0.01\t\t\t#m\n",
+ "mu = 0.002 \t\t\t#Ns/m**2\n",
+ "l = 30. \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V = Q/(60*math.pi/4*d**2)\n",
+ "RN = V*d*rho/mu\n",
+ "f = 0.316/RN**(0.25)\n",
+ "h = (1+f*l/d)*V**2 /(2*g)\n",
+ "\n",
+ "#result\n",
+ "print \"Height required = %.2f m\"%(h)\n",
+ "\n",
+ "# rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Height required = 12.21 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7 Page No : 264"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t \t#m/s**2\n",
+ "rho = 10**3 \t\t\t#kg/m**3\n",
+ "hl = 0.02\n",
+ "d = 1.2 \t\t\t#diameter - m\n",
+ "l = 1. \t \t\t#m\n",
+ "k = 0.5 *10**-2 \t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "v2f = hl*(2*g*d)/l\n",
+ "e = k/d\n",
+ "f = 0.028\n",
+ "V = math.sqrt(v2f/f)\n",
+ "Q = math.pi/4 *d**2 *V\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Rate of flow = %.2f m**3/s\"%(Q)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rate of flow = 4.64 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8 Page No : 265"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t \t#m/s**2\n",
+ "rho = 10.**3 \t\t\t#kg/m**3\n",
+ "e = 0.03*10**-2 \t\t#surface roughness - m\n",
+ "l = 3000. \t \t\t#distance - m\n",
+ "Q = 300.*10**-3 \t\t#m**3/s\n",
+ "nu = 10.**-5 \t\t\t#kinematic viscosity - m**2/s\n",
+ "hl = 24. \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "d5f = l*Q/(math.pi/4) * Q/(math.pi/4) /(hl*2*g)\n",
+ "f = 0.022\n",
+ "d = (d5f*f)**(1./5)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Size of the required pipe = %d cm\"%(d*100)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size of the required pipe = 45 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9 Page No : 266"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "d = 0.3 \t\t\t#m\n",
+ "per = 25./100\n",
+ "Q = 0.1 \t\t\t#m**3/s\n",
+ "k0 = 0.025*10**-2 \t#m\n",
+ "nu = 0.000001\n",
+ "year = 10.\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V = Q/(math.pi/4 *d**2)\n",
+ "RN = V*d/nu\n",
+ "e1 = k0/d\n",
+ "f1 = 0.019 \n",
+ "f2 = (1+per)*f1\n",
+ "e2 = 0.002\n",
+ "k2 = e2*d\n",
+ "rate = (k2-k0)*100/year\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Rate of increase = %.4f cm/year\"%(rate)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rate of increase = 0.0035 cm/year\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10 Page No : 267"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "l = 1. \t\t\t #m\n",
+ "b = 0.3 \t\t\t#m\n",
+ "Q = 4.2 \t\t\t#m**3/s\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "A = l*b\n",
+ "R = A/(2*(l+b))\n",
+ "d5 = 1.62/24.15\n",
+ "d = d5**(1./5)\n",
+ "Pr = 2*(l+b)/(math.pi*d)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"The rectangular cross section will cost %.2f times that of a circular cross section\"%(Pr)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The rectangular cross section will cost 1.42 times that of a circular cross section\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.11 Page No : 270"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t\t#kg/m**3\n",
+ "d1 = 2.5*10**-2 \t\t\t#m\n",
+ "d2 = 7.2*10**-2 \t\t\t#m\n",
+ "Q = 100.*10**-3 \t\t\t#m**3/hr\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V1 = Q/(60*math.pi/4*d1**2)\n",
+ "V2 = (d1/d2)**2 *V1\n",
+ "dp = -(V2**2 -V1**2 + (V1-V2)**2)/(2*g)\n",
+ "Pdiff = dp*g*rho\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"pressure difference = %.2f kN/m**2\"%(Pdiff/1000)\n",
+ "\n",
+ "# note : The answers are a bit different due to rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pressure difference = 1.22 kN/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.12 Page No : 273"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t\t#kg/m**3\n",
+ "d2 = 30./100 \t\t\t#cm\n",
+ "d1 = 60./100 \t\t\t#cm\n",
+ "Pu = 105. \t\t\t#kN/m**2\n",
+ "Pd = 75. \t\t\t#kN/m**2\n",
+ "Cc = 0.65\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V22 = (2*g/(1 - (d2/d1)**4 + (1/Cc -1)**2)) *(Pu-Pd)*10**3 /(rho*g)\n",
+ "V2 = math.sqrt(V22)\n",
+ "Q = math.pi/4 *V2 *d2**2\n",
+ "hl = (1/Cc -1)**2 *V2**2 /(2*g)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Flow rate = %.3f m**3/s\"%(Q)\n",
+ "print \" Head loss = %.3f m\"%(hl)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Flow rate = 0.494 m**3/s\n",
+ " Head loss = 0.722 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.13 Page No : 277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "rho = 10.**3 \t\t#kg/m**3\n",
+ "d = 9. \t\t\t#m\n",
+ "dia = 0.3 \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V302 = 2*g*d/(0.5 + 20 + 2.53+101+0.66+41.47+2.07)\n",
+ "V30 = math.sqrt(V302)\n",
+ "Q = math.pi/4 *dia**2 *V30\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Flow rate = %.3f m**3/s\"%(Q)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Flow rate = 0.072 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.14 Page No : 278"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "h = 6. \t\t\t #m\n",
+ "rho = 930. \t\t\t#kg/m**3\n",
+ "Q = 3./60 \t\t\t#m**3/s\n",
+ "d = 0.15 \t\t\t#m\n",
+ "L = 20. \t\t\t#m\n",
+ "mu = 0.006 #viscosity\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V = Q/(math.pi/4 *d**2)\n",
+ "RN = V*d*rho/mu\n",
+ "f = 0.316/RN**0.25\n",
+ "hl = f*L/d *V**2 /(2*g)\n",
+ "Hp = h+hl\n",
+ "gam = rho*g\n",
+ "W = gam*Q\n",
+ "Power = W*Hp\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Power required = %.3f kW\"%(Power/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Power required = 3.227 kW\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.15 Page No : 279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from scipy.integrate import quad\n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "d = 0.02 \t\t\t#m\n",
+ "d2 = 1.2 \t\t\t#diameter - m\n",
+ "f = 0.01\n",
+ "L = 250.\n",
+ "ken = 0.5\n",
+ "g = 9.81\n",
+ "h1 = 8. \t\t\t#m\n",
+ "h2 = 4. \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V2 = 2*g/(1+ken+ f*L/d)\n",
+ "V = math.sqrt(V2)\n",
+ "Q = math.pi/4 *d**2 *V\n",
+ "def time(h):\n",
+ " return -math.pi/4 *d2**2 /Q /math.sqrt(h)\n",
+ "\n",
+ "ti = quad(time,h1,h2)[0]\n",
+ "hours = ti/3600\n",
+ "mins = ti%3600/60\n",
+ "secs = ti%3600%60\n",
+ "\n",
+ "#results\n",
+ "print \"Time required = %d hours %d mins %d seconds\"%(hours,mins,secs)\n",
+ "\n",
+ "# rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time required = 4 hours 12 mins 25 seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.16 Page No : 280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "d1 = 0.1 \t\t\t#m\n",
+ "d2 = 0.05 \t\t\t#m\n",
+ "l1 = 20. \t\t\t#m\n",
+ "l2 = 20. \t\t\t#m\n",
+ "f = 0.02\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "Kl = (f*l2/d2 *(d1/d2)**4 - f*l1/d1)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Loss coefficient = %d \"%(Kl)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Loss coefficient = 124 \n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.17 Page No : 281"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81 \n",
+ "ratio = 1.265\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "percent = (ratio-1)*100\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Increase in discharge = %.1f %%\"%(percent)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Increase in discharge = 26.5 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.18 Page No : 282"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "Q = 0.6 \t\t\t#m**3/s\n",
+ "l1 = 1200. \t\t\t#m\n",
+ "l2 = 800. \t\t\t#m\n",
+ "d1 = 0.3 \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V1 = 1.02 \t\t\t#m/s\n",
+ "d5 = d1*l2*4**2 *Q**2 /(l1*math.pi**2 *V1**2)\n",
+ "d = d5**(1./5)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"diameter of the single pipe = %.2f m\"%(d)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "diameter of the single pipe = 0.65 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.19 Page No : 284"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "g = 9.81\n",
+ "Q = 0.18 \t\t\t#m**3/s\n",
+ "d3 = 0.3\t\t\t#m\n",
+ "f = 0.032 #friction factor\n",
+ "L3 = 360. \t\t\t#m\n",
+ "z = 25.5 \t\t\t#m\n",
+ "z2 = 30. \t\t\t#m\n",
+ "L2 = 450. \t\t\t#m\n",
+ "d2 = 0.45\t\t\t#m\n",
+ "L1 = 950. \t\t\t#m\n",
+ "d1 = 0.45 \t\t\t#m\n",
+ "zn = 18. \t\t\t#m\n",
+ "rho = 1000.\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "V3 = Q/(math.pi/4 *d3**2)\n",
+ "hl3 = f*L3/d3 *(V3**2 /(2*g))\n",
+ "Z2 = z+hl3\n",
+ "hl2 = Z2-z2\n",
+ "V2 = math.sqrt(2*g*d2*hl2/(f*L2))\n",
+ "Q2 = math.pi/4 *d2**2 *V2\n",
+ "V1 = V2+ (d3/d2)**2 *V3\n",
+ "hl1 = f*L1/d1*V1**2 /(2*g)\n",
+ "Hp = hl1+ Z2-zn\n",
+ "gam = rho*g\n",
+ "P = gam*Hp\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Discharge into the reservoir = %.3f m**3/s\"%(Q2)\n",
+ "print \" Pressure maintained by the pump = %.2f kN/m**2\"%(P/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Discharge into the reservoir = 0.356 m**3/s\n",
+ " Pressure maintained by the pump = 582.34 kN/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.20 Page No : 285"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from numpy import *\n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "z1 = 10. \t\t\t#m\n",
+ "z2 = 5. \t\t\t#m\n",
+ "z3 = 7.5 \t\t\t#m\n",
+ "f = 0.04 \n",
+ "l1 = 100. \t\t\t#m\n",
+ "l2 = 50. \t\t\t#m\n",
+ "l3 = 70. \t\t\t#m\n",
+ "d1 = 0.1 \t\t\t#m\n",
+ "d2 = 0.075 \t\t\t#m\n",
+ "d3 = 0.06 \t\t\t#m\n",
+ "g = 9.81 \t\t\t#m/s**2\n",
+ "h = array([1, 2, 1.9, 1.96])\n",
+ "\n",
+ "#calculations\n",
+ "Q1 = sqrt(d1**5 *(math.pi/4)**2 *2*g/(f*l1)) *sqrt(z1-h)\n",
+ "Q2 = sqrt(d2**5 *(math.pi/4)**2 *2*g/(f*l2)) *sqrt(h+z2)\n",
+ "Q3 = sqrt(d3**5 *(math.pi/4)**2 *2*g/(f*l3)) *sqrt(h+z3)\n",
+ "for i in range(4):\n",
+ " Q = Q2[i]+Q3[i]\n",
+ " if (Q1[i] == Q):\n",
+ " break;\n",
+ " print \"height h = %.2f m\"%(h[i])\n",
+ " print \"Discharge in BC Q2 = %.2f lps\"%((Q2[i])*1000)\n",
+ " print \"Discharge in BD Q3 = %.2f lps\"%((Q3[i])*1000)\n",
+ " \n",
+ "# note : rounding off error. "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "height h = 1.00 m\n",
+ "Discharge in BC Q2 = 9.28 lps\n",
+ "Discharge in BD Q3 = 5.35 lps\n",
+ "height h = 2.00 m\n",
+ "Discharge in BC Q2 = 10.03 lps\n",
+ "Discharge in BD Q3 = 5.65 lps\n",
+ "height h = 1.90 m\n",
+ "Discharge in BC Q2 = 9.95 lps\n",
+ "Discharge in BD Q3 = 5.62 lps\n",
+ "height h = 1.96 m\n",
+ "Discharge in BC Q2 = 10.00 lps\n",
+ "Discharge in BD Q3 = 5.64 lps\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.21 Page No : 290"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "e = 0.8\n",
+ "output = 400. \t\t#kW\n",
+ "H = 150. \t\t\t#m\n",
+ "rho = 1000. \n",
+ "g = 9.81\n",
+ "f = 0.028\n",
+ "l = 1250. \t\t\t#m\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "gam = rho*g\n",
+ "inpu = output/e\n",
+ "Q = inpu*10**3 /(2./3 *gam*H)\n",
+ "hl = 1./3 *H\n",
+ "d5 = f*l*Q**2 /(2*g* math.pi/4 * math.pi/4 *hl)\n",
+ "d = d5**(1./5)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Smallest diameter of pen stock = %d cm\"%(d*100)\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Smallest diameter of pen stock = 43 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.22 Page No : 291"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "f = 0.04\n",
+ "H = 30. \t\t\t#m\n",
+ "l = 200. \t\t\t#m\n",
+ "d = 0.075 \t\t\t#m\n",
+ "g = 9.81\n",
+ "rho = 1000.\n",
+ "gam = rho*g\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "h = 2/3. *H\n",
+ "vj = math.sqrt(2.*g*h)\n",
+ "hl = 1/3. *H\n",
+ "V = math.sqrt(hl*d*2*g/(f*l))\n",
+ "dj = d*(math.sqrt(V/vj))\n",
+ "Power = 2/3. *gam*math.pi/4. *d**2 *V*H\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Size of nozzle = %.1f cm\"%(dj*100)\n",
+ "print \" Max power = %.2f kW\"%(Power/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size of nozzle = 2.0 cm\n",
+ " Max power = 1.18 kW\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_Of_Fluid_Mechanics/ch8.ipynb b/Principles_Of_Fluid_Mechanics/ch8.ipynb
new file mode 100644
index 00000000..85eb3fee
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/ch8.ipynb
@@ -0,0 +1,532 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:994ba4703f91ead0a5ff4da6459451af8490fc9d0d26864c4973279092fd8132"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8 : Uniform Open Channel Flow"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.1 Page No : 306"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "b = 4. \t\t\t #m\n",
+ "y = 1.2 \t\t\t#m\n",
+ "sf = 0.001\n",
+ "n = 0.012\n",
+ "gam = 9.81*1000\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "A = b*y\n",
+ "R = A/(b+ 2*y)\n",
+ "Q = 1/n *A*R**(2./3) *sf**(1./2)\n",
+ "T = gam*R*sf\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Discharge = %.3f m**3/s\"%(Q)\n",
+ "print \" bed shear = %.2f N/m**2\"%(T)\n",
+ "#The answer in textbook is wrong for discharge. Please use a calculator."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Discharge = 10.442 m**3/s\n",
+ " bed shear = 7.36 N/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2 Page No : 306"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "b = 6. \t\t \t#m\n",
+ "y = 2. \t\t\t #m\n",
+ "sf = 0.005\n",
+ "slope = 2.\n",
+ "gam = 9.81*1000\n",
+ "Q = 65. \t\t\t#m**3/s\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "A = (b+ 2*y)*slope\n",
+ "P = b+ 2*y*math.sqrt(slope**2 +1)\n",
+ "R = A/P\n",
+ "V = Q/A\n",
+ "n = R**(2./3) *sf**(1./2) /V\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Value of mannings coefficient = %.3f\"%(n)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of mannings coefficient = 0.026\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3 Page No : 307"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "b = 3. \t\t\t#m\n",
+ "y = 1. \t\t\t#m\n",
+ "sf = 0.005 #slope\n",
+ "n = 0.028 \n",
+ "gam = 9.81*1000\n",
+ "Q = 0.25 \t\t\t#discharge - m**3/s\n",
+ "slope = 1.5\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "A = 0.5 *b*y\n",
+ "P = 2*math.sqrt(1 + (slope)**2)\n",
+ "R = A/P\n",
+ "yx = Q*n/(slope * R**(2./3) *sf**(1./2))\n",
+ "y = yx**(3./8)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"depth = %.2f m\"%(y)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "depth = 0.45 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4 Page No : 307"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "sf = 0.0064 #slope\n",
+ "n = 0.015\n",
+ "Q = 6. \t\t\t#discharge - m**3/s\n",
+ "gam = 9.81*1000\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "AR = n*Q/math.sqrt(sf)\n",
+ "print (\"On trial and error, \")\n",
+ "y = 0.385 \t\t\t#m\n",
+ "print \"normal depth = %.3f m\"%(y)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On trial and error, \n",
+ "normal depth = 0.385 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.5 Page No : 308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "from numpy import *\n",
+ "\t\t\t\n",
+ "#Initialization of variables\\\n",
+ "sf = 0.00007\n",
+ "n = 0.013\n",
+ "gam = 9.81*1000\n",
+ "V = 0.45 \t\t\t#velocity - m/s\n",
+ "Q = 1.4 \t\t\t#m**3/s\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "by = Q/V\n",
+ "#x = poly(0,\"x\")\n",
+ "#y = roots(x**2 -2.66*x +1.55)\n",
+ "y = roots([1,-2.66,1.55])\n",
+ "b = by/y\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"y = \", y \n",
+ "print \"corresponding b = \" ,b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "y = [ 1.7978675 0.8621325]"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "corresponding b = [ 1.73044516 3.60862294]\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.6 Page No : 310"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "sf = 0.0016 #slope\n",
+ "n = 0.02\n",
+ "Q = 0.84 \t\t\t#m**3/s\n",
+ "gam = 9.81*1000\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "y53 = Q*n/math.sqrt(sf)\n",
+ "y = y53**(3./5)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"depth of flow = %.2f m\"%(y)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "depth of flow = 0.59 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.7 Page No : 313"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "n = 0.015\n",
+ "Q = 1.3 \t\t\t#m**3/s\n",
+ "V = 0.6 \t\t\t#m/s\n",
+ "gam = 9.81*1000\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "alpha = 60. \t\t\t#degrees\n",
+ "A = 0.5 *(1./2)**2 *(180-alpha)/180 *math.pi -(1./4)**2 *math.radians(math.tan(alpha))\n",
+ "A = 0.206\n",
+ "P = 0.5*(180-alpha)/180 *math.pi\n",
+ "R = A/P\n",
+ "d2 = V*n/(R**(2./3))\n",
+ "d8 = Q*n*4*4**(2./3) /math.pi\n",
+ "d = math.sqrt(d8/d2)\n",
+ "sf = (d2**2/d**(4./3))\n",
+ "\t\n",
+ "#results\n",
+ "print \"Diameter = %.2f m\"%(d)\n",
+ "print \" slope = %.5f \"%(sf)\n",
+ "#The answer given in textbook is wrong. please check"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Diameter = 1.53 m\n",
+ " slope = 0.00040 \n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.8 Page No : 315"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "b = 0.5 \t\t\t#m\n",
+ "y = 0.35 \t\t\t#m\n",
+ "sf = 0.001 #slope\n",
+ "nc = 0.016\n",
+ "gam = 9.81*1000\n",
+ "Q = 0.15 \t\t\t#m**3/s\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "A = b*y\n",
+ "P = b+ 2*y\n",
+ "R = A/P\n",
+ "ng = 1/Q *A*R**(2./3) *sf**(1./2)\n",
+ "n = (b*nc**(3./2) + 2*y*ng**(3./2))**(2./3) /(P**(2./3))\n",
+ "Q2 = 1/n *A*R**(2./3) *sf**(1./2)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"flow in case 2 = %.3f m**3/s\"%(Q2)\n",
+ "\n",
+ "# note : rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "flow in case 2 = 0.120 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.9 Page No : 316"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "b1 = 8. \t\t\t#m\n",
+ "b2 = 5. \t\t\t#m\n",
+ "y = 5. \t\t\t#m\n",
+ "b5 = 15. \t\t\t#m\n",
+ "b3 = 3. \t\t\t#m\n",
+ "b4 = 3. \t\t\t#m\n",
+ "y2 = 2. \t\t\t#m\n",
+ "y3 = 3. \t\t\t#m\n",
+ "n1 = 0.025\n",
+ "n2 = 0.035\n",
+ "sf = 0.0008\n",
+ "\t\t\t#calcuations\n",
+ "A = (b1+b2)*y\n",
+ "P = b1+ math.sqrt(b2**2 +y**2) + math.sqrt(b3**2 +b4**2)\n",
+ "R = A/P\n",
+ "Q1 = 1/n1 *A*R**(2./3) *sf**(1./2)\n",
+ "A2 = b5*y2 - 0.5*y2*y2 + 0.5*y3*y2\n",
+ "P2 = b5 + math.sqrt(b4**2 + y3**2)\n",
+ "R2 = A2/P2\n",
+ "Q2 = 1/n2 *A2*R2**(2./3) *sf**(1./2)\n",
+ "Q = Q1+Q2\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Total discharge = %.f m**3/s\"%(Q)\n",
+ "\n",
+ "# rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total discharge = 200 m**3/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.10 Page No : 320"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "Q = 12. \t\t\t#m**3/s\n",
+ "n = 0.023\n",
+ "A = 2.472\n",
+ "b = 0.472\n",
+ "sf = 1./8000\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "y8 = Q*n/A *2**(2./3) /sf**(1./2)\n",
+ "y = y8**(3./8)\n",
+ "b2 = b*y\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"depth = %.3f m\"%(y)\n",
+ "print \" width = %.2f m\"%(b2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "depth = 2.819 m\n",
+ " width = 1.33 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.11 Page No : 320"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "Q = 30. \n",
+ "V = 1.\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "A = Q/V\n",
+ "y = math.sqrt(A/(math.sqrt(2) + 0.5))\n",
+ "b = (A- 0.5*y**2)/y\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"width = %.2f m\"%(b)\n",
+ "print \" depth = %.2f m\"%(y)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "width = 5.60 m\n",
+ " depth = 3.96 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_Of_Fluid_Mechanics/ch9.ipynb b/Principles_Of_Fluid_Mechanics/ch9.ipynb
new file mode 100644
index 00000000..d60bcd33
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/ch9.ipynb
@@ -0,0 +1,152 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:a18675a96e26e95bc119a7095e6c5f784a91bb484f337fa10d53e05acf798c32"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9 : Potential Flow"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4 Page No : 339"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "k = 1.5\n",
+ "r = 40. \t \t\t#cm\n",
+ "theta = 45. \t\t\t#degrees\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "vr = -2*k*r*math.cos(math.radians(2*theta))\n",
+ "vt = 2*k*r*math.sin(math.radians(2*theta))\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"velocity in radial direction = %d cm/s\"%(vr)\n",
+ "print \" velcoity in angular direction = %d cm/s\"%(vt)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "velocity in radial direction = 0 cm/s\n",
+ " velcoity in angular direction = 120 cm/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.14 Page No : 371"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "T = 4.5 #m^2/s\n",
+ "a = 0.6 #diameter - m\n",
+ "u = 5. \t\t \t#velocity - m/s\n",
+ "rho = 1000. \t\t\t#kg/m**3\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "sint = 0.5*(1- T/(2*math.pi*a*u))\n",
+ "theta = math.degrees(math.asin((sint)))\n",
+ "dp = 0.5*rho*u**2 *(1 - (2 + T/(2*math.pi*a*u))**2)\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"Angle = %.1f or %.1f degrees\"%(theta,180-theta)\n",
+ "print \" Min guage pressure = %.2f kN/m**2\"%(dp/1000)\n",
+ "\n",
+ "#The answer in textbook is wrong. please check"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Angle = 22.4 or 157.6 degrees\n",
+ " Min guage pressure = -50.15 kN/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.15 Page No : 371"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\t\t\n",
+ "#Initialization of variables\n",
+ "T = 6*math.pi\n",
+ "r = 1./3\n",
+ "\t\t\t\n",
+ "#calculations\n",
+ "vab = T/(4*math.pi)\n",
+ "vba = T/(2*math.pi)\n",
+ "w = vab/r\n",
+ "\t\t\t\n",
+ "#results\n",
+ "print \"rate of rotation = %.1f rad/s\"%(w)\n",
+ "print \"speed of A by B = %.1f m/s\"%(vab)\n",
+ "print \"speed of B by A = %.1f m/s\"%(vba)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rate of rotation = 4.5 rad/s\n",
+ "speed of A by B = 1.5 m/s\n",
+ "speed of B by A = 3.0 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_Of_Fluid_Mechanics/screenshots/10TheBoundaryLayer.png b/Principles_Of_Fluid_Mechanics/screenshots/10TheBoundaryLayer.png
new file mode 100644
index 00000000..87f14437
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/screenshots/10TheBoundaryLayer.png
Binary files differ
diff --git a/Principles_Of_Fluid_Mechanics/screenshots/1BasicConcepts.png b/Principles_Of_Fluid_Mechanics/screenshots/1BasicConcepts.png
new file mode 100644
index 00000000..7d530f7c
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/screenshots/1BasicConcepts.png
Binary files differ
diff --git a/Principles_Of_Fluid_Mechanics/screenshots/9PotentialFlow.png b/Principles_Of_Fluid_Mechanics/screenshots/9PotentialFlow.png
new file mode 100644
index 00000000..76999ba9
--- /dev/null
+++ b/Principles_Of_Fluid_Mechanics/screenshots/9PotentialFlow.png
Binary files differ
diff --git a/Principles_of_Data_structures_using_C_and_C++/README.txt b/Principles_of_Data_structures_using_C_and_C++/README.txt
new file mode 100644
index 00000000..7fc96069
--- /dev/null
+++ b/Principles_of_Data_structures_using_C_and_C++/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Tejas Dodiya
+Course: others
+College/Institute/Organization: Freelance
+Department/Designation: Science
+Book Title: Principles of Data structures using C and C++
+Author: Vinu V Das
+Publisher: New Age International (P) Limited , Publishers
+Year of publication: 2006
+Isbn: 9788122428643
+Edition: 1st \ No newline at end of file
diff --git a/Principles_of_Data_structures_using_C_and_C++/chapter2.ipynb b/Principles_of_Data_structures_using_C_and_C++/chapter2.ipynb
new file mode 100644
index 00000000..5293973c
--- /dev/null
+++ b/Principles_of_Data_structures_using_C_and_C++/chapter2.ipynb
@@ -0,0 +1,136 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e69ccbb1735a0c440e4d73af0d7e8991c9d99315b31e67bbedcd0e1e4ee9909a"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2: Memory Management"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, page no. 19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Enter the number of element(s) to be added: \"\n",
+ "n = int(raw_input())\n",
+ "nos = []\n",
+ "for i in range(1,n+1):\n",
+ " print \"Enter the %d element: \" %i\n",
+ " nos.append(int(raw_input()))\n",
+ "\n",
+ "sum = 0\n",
+ "for i in range(0,n):\n",
+ " sum += nos[i]\n",
+ "\n",
+ "print \"The SUM of no(s) is: %d\" %sum"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number of element(s) to be added: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the 1 element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the 2 element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the 3 element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the 4 element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The SUM of no(s) is: 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_of_Data_structures_using_C_and_C++/chapter3.ipynb b/Principles_of_Data_structures_using_C_and_C++/chapter3.ipynb
new file mode 100644
index 00000000..8a5b19bf
--- /dev/null
+++ b/Principles_of_Data_structures_using_C_and_C++/chapter3.ipynb
@@ -0,0 +1,950 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c98469f20d33ab4fe0f1fcb5a671c040610d80e4c529865895fc0cc3edbc9a24"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "raw",
+ "metadata": {},
+ "source": [
+ "Chapter 3: The Stack"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, page no. 28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAXSIZE = 100\n",
+ "\n",
+ "class stack:\n",
+ " def __init__(self):\n",
+ " self.stack = []\n",
+ " self.top = -1\n",
+ "\n",
+ "def push(pu):\n",
+ " if(pu.top == MAXSIZE-1):\n",
+ " print \"The stack is full\"\n",
+ " else:\n",
+ " print \"Enter the element to be inserted: \"\n",
+ " item = int(raw_input())\n",
+ " pu.stack.append(item)\n",
+ " pu.top += 1\n",
+ "\n",
+ "def pop(po):\n",
+ " if(po.top == -1):\n",
+ " print \"Stack is empty\"\n",
+ " else:\n",
+ " item = po.stack[po.top]\n",
+ " po.top-=1\n",
+ " print \"The item deleted is: %d\" %item\n",
+ "\n",
+ "\n",
+ "def traverse(pt):\n",
+ " if(pt.top == -1):\n",
+ " print \"Stack is empty\"\n",
+ " else:\n",
+ " print \"The element(s) in the stack are...\"\n",
+ " i = pt.top\n",
+ " while(i>=0):\n",
+ " print \"%d\" %pt.stack[i],\n",
+ " i-=1\n",
+ "\n",
+ "ps = stack()\n",
+ "ch = 'y'\n",
+ "\n",
+ "while(ch == 'Y' or ch == 'y'):\n",
+ " print \"1. PUSH\"\n",
+ " print \"2. POP\"\n",
+ " print \"3. TRAVERSE\"\n",
+ " print \"Enter your choice: \"\n",
+ " choice = int(raw_input())\n",
+ " if(choice == 1):\n",
+ " push(ps)\n",
+ " elif(choice == 2):\n",
+ " pop(ps)\n",
+ " elif(choice == 3):\n",
+ " traverse(ps)\n",
+ " else:\n",
+ " print \"You entered a wrong choice...\"\n",
+ " \n",
+ " print \"\\nPrint Y/y to continue\"\n",
+ " ch = raw_input()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1. PUSH\n",
+ "2. POP\n",
+ "3. TRAVERSE\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element to be inserted: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Print Y/y to continue\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1. PUSH\n",
+ "2. POP\n",
+ "3. TRAVERSE\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element to be inserted: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Print Y/y to continue\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exampe 2, page no. 31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAXSIZE = 100\n",
+ "\n",
+ "class stack:\n",
+ " \n",
+ " def __init__(self):\n",
+ " self.stack = []\n",
+ " self.top = -1\n",
+ " \n",
+ " def push(self,pu):\n",
+ " if(pu.top == MAXSIZE-1):\n",
+ " print \"The stack is full\"\n",
+ " else: \n",
+ " print \"Enter the element to be inserted: \"\n",
+ " item = int(raw_input())\n",
+ " pu.stack.append(item)\n",
+ " pu.top += 1\n",
+ "\n",
+ " def pop(self,po):\n",
+ " if(po.top == -1):\n",
+ " print \"Stack is empty\"\n",
+ " else:\n",
+ " item = po.stack[po.top]\n",
+ " po.top-=1\n",
+ " print \"The item deleted is: %d\" %item\n",
+ " \n",
+ " def traverse(self,pt):\n",
+ " if(pt.top == -1):\n",
+ " print \"Stack is empty\"\n",
+ " else:\n",
+ " print \"The element(s) in the stack are...\"\n",
+ " i = pt.top\n",
+ " while(i>=0):\n",
+ " print \"%d\" %pt.stack[i],\n",
+ " i-=1\n",
+ "\n",
+ "ps = stack()\n",
+ "ch = 'y'\n",
+ "\n",
+ "while(ch == 'Y' or ch == 'y'):\n",
+ " print \"1. PUSH\"\n",
+ " print \"2. POP\"\n",
+ " print \"3. TRAVERSE\"\n",
+ " print \"Enter your choice: \"\n",
+ " choice = int(raw_input())\n",
+ " if(choice == 1):\n",
+ " ps.push(ps)\n",
+ " elif(choice == 2):\n",
+ " ps.pop(ps)\n",
+ " elif(choice == 3):\n",
+ " ps.traverse(ps)\n",
+ " else:\n",
+ " print \"You entered a wrong choice...\"\n",
+ " \n",
+ " print \"\\nPrint Y/y to continue\"\n",
+ " ch = raw_input()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1. PUSH\n",
+ "2. POP\n",
+ "3. TRAVERSE\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element to be inserted: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Print Y/y to continue\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1. PUSH\n",
+ "2. POP\n",
+ "3. TRAVERSE\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element to be inserted: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Print Y/y to continue\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1. PUSH\n",
+ "2. POP\n",
+ "3. TRAVERSE\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The element(s) in the stack are...\n",
+ "10 5 \n",
+ "Print Y/y to continue\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, page no. 31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def fact(n):\n",
+ " if (n<=0):\n",
+ " return 1\n",
+ " else:\n",
+ " return n * fact(n-1)\n",
+ "\n",
+ "print \"Enter a number: \"\n",
+ "n = int(raw_input())\n",
+ "n = fact(n)\n",
+ "print \"Factorial is: %d\" %n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Factorial is: 120\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, page no. 36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class tower:\n",
+ " \n",
+ " def __init__(self):\n",
+ " self.nodisk = 0\n",
+ " self.fromtower = \"\"\n",
+ " self.totower = \"\"\n",
+ " self.auxtower = \"\"\n",
+ " \n",
+ " def hanoi(self,i, frm_t, to_t, aux_t):\n",
+ " if(i <= 1):\n",
+ " print \"Move from disk 1 from tower \" + frm_t + \" to tower \" + to_t\n",
+ " return\n",
+ " self.hanoi(i-1, frm_t, aux_t, to_t)\n",
+ " print \"\\nMove from disk \" + str(i) + \" from tower \" + frm_t + \" to tower \" + to_t\n",
+ " self.hanoi(i-1,aux_t, to_t, frm_t)\n",
+ "\n",
+ "print \"-----------Tower of Hanoi-------------\"\n",
+ "print \"Enter number of disks: \"\n",
+ "no = int(raw_input())\n",
+ "ob = tower()\n",
+ "ob.hanoi(no,'X','Y','Z')\n",
+ "print \"Press any key to continue...\"\n",
+ "raw_input()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-----------Tower of Hanoi-------------\n",
+ "Enter number of disks: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Move from disk 1 from tower X to tower Z\n",
+ "\n",
+ "Move from disk 2 from tower X to tower Y\n",
+ "Move from disk 1 from tower Z to tower Y\n",
+ "\n",
+ "Move from disk 3 from tower X to tower Z\n",
+ "Move from disk 1 from tower Y to tower X\n",
+ "\n",
+ "Move from disk 2 from tower Y to tower Z\n",
+ "Move from disk 1 from tower X to tower Z\n",
+ "\n",
+ "Move from disk 4 from tower X to tower Y\n",
+ "Move from disk 1 from tower Z to tower Y\n",
+ "\n",
+ "Move from disk 2 from tower Z to tower X\n",
+ "Move from disk 1 from tower Y to tower X\n",
+ "\n",
+ "Move from disk 3 from tower Z to tower Y\n",
+ "Move from disk 1 from tower X to tower Z\n",
+ "\n",
+ "Move from disk 2 from tower X to tower Y\n",
+ "Move from disk 1 from tower Z to tower Y\n",
+ "Press any key to continue...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 6,
+ "text": [
+ "''"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, page no. 48"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAXSIZE = 100\n",
+ "\n",
+ "class stack:\n",
+ " def __init__(self):\n",
+ " self.stack = []\n",
+ " self.top = -1\n",
+ "\n",
+ "def push(pu,symbol):\n",
+ " if(pu.top == MAXSIZE-1):\n",
+ " print \"The stack is full\"\n",
+ " else:\n",
+ " pu.stack.append(symbol)\n",
+ " pu.top += 1\n",
+ " return pu\n",
+ "\n",
+ "def pop(po):\n",
+ " if(po.top == -1):\n",
+ " print \"Stack is empty\"\n",
+ " else:\n",
+ " symbol = po.stack.pop()\n",
+ " po.top-=1\n",
+ " return symbol,po\n",
+ " \n",
+ " \n",
+ "def prec(symbol):\n",
+ " if symbol == '(':\n",
+ " return 1\n",
+ " elif symbol == ')':\n",
+ " return 2\n",
+ " elif symbol == '+' or symbol == '-':\n",
+ " return 3\n",
+ " elif symbol == '*' or symbol == '/' or symbol == '%':\n",
+ " return 4\n",
+ " elif symbol == '^':\n",
+ " return 5\n",
+ " else:\n",
+ " return 0\n",
+ "\n",
+ "def infix_postfix(infix):\n",
+ " \n",
+ " length = len(infix)\n",
+ " ps = stack()\n",
+ " infix += ')'\n",
+ " ps = push(ps,'(')\n",
+ " postfix = []\n",
+ " for i in range(0,length+1):\n",
+ " ret_val = prec(infix[i])\n",
+ " if ret_val == 1:\n",
+ " ps = push(ps,infix[i])\n",
+ " elif(ret_val == 2):\n",
+ " ch,ps = pop(ps)\n",
+ " while(ch != '('):\n",
+ " postfix.append(ch)\n",
+ " ch,ps = pop(ps)\n",
+ " elif(ret_val == 3):\n",
+ " ch,ps = pop(ps)\n",
+ " while(prec(ch) >= 3):\n",
+ " postfix.append(ch)\n",
+ " ch,ps = pop(ps)\n",
+ " ps=push(ps,ch)\n",
+ " ps=push(ps,infix[i])\n",
+ " elif(ret_val == 4):\n",
+ " ch,ps = pop(ps)\n",
+ " while(prec(ch) >= 4):\n",
+ " postfix.append(ch)\n",
+ " ch,ps = pop(ps)\n",
+ " ps=push(ps,ch)\n",
+ " ps=push(ps,infix[i])\n",
+ " elif(ret_val == 5):\n",
+ " ch,ps = pop(ps)\n",
+ " while(prec(ch) == 5):\n",
+ " postfix.append(ch)\n",
+ " ch,ps = pop(ps)\n",
+ " ps=push(ps,ch)\n",
+ " ps=push(ps,infix[i])\n",
+ " else:\n",
+ " postfix.append(infix[i])\n",
+ "\n",
+ " print \"The postfix expression is: \"\n",
+ " print postfix\n",
+ "\n",
+ "choice = 'y'\n",
+ "while (choice == 'Y' or choice == 'y'):\n",
+ " print \"Enter an infix expression: \"\n",
+ " infix = raw_input()\n",
+ " infix_postfix(infix)\n",
+ " print \"Do you want to continue? Y/y \"\n",
+ " choice = raw_input()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an infix expression: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a+b\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The postfix expression is: \n",
+ "['a', 'b', '+']\n",
+ "Do you want to continue? Y/y \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6, page no. 52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "MAXSIZE = 100\n",
+ "\n",
+ "class stack:\n",
+ " def __init__(self):\n",
+ " self.stack = []\n",
+ " self.top = -1\n",
+ "\n",
+ " def push(self, pu, symbol):\n",
+ " if(pu.top == MAXSIZE-1):\n",
+ " print \"The stack is full\"\n",
+ " else:\n",
+ " pu.stack.append(symbol)\n",
+ " pu.top += 1\n",
+ " return pu\n",
+ "\n",
+ " def pop(self, po):\n",
+ " if(po.top == -1):\n",
+ " print \"Stack is empty\"\n",
+ " else:\n",
+ " symbol = po.stack.pop()\n",
+ " po.top-=1\n",
+ " return symbol,po\n",
+ " \n",
+ " \n",
+ " def prec(self, symbol):\n",
+ " if symbol == '(':\n",
+ " return 1\n",
+ " elif symbol == ')':\n",
+ " return 2\n",
+ " elif symbol == '+' or symbol == '-':\n",
+ " return 3\n",
+ " elif symbol == '*' or symbol == '/' or symbol == '%':\n",
+ " return 4\n",
+ " elif symbol == '^':\n",
+ " return 5\n",
+ " else:\n",
+ " return 0\n",
+ "\n",
+ "def infix_postfix(infix):\n",
+ " \n",
+ " length = len(infix)\n",
+ " ps = stack()\n",
+ " infix += ')'\n",
+ " ps = ps.push(ps,'(')\n",
+ " postfix = []\n",
+ " for i in range(0,length+1):\n",
+ " ret_val = ps.prec(infix[i])\n",
+ " if ret_val == 1:\n",
+ " ps = ps.push(ps,infix[i])\n",
+ " elif(ret_val == 2):\n",
+ " ch,ps = ps.pop(ps)\n",
+ " while(ch != '('):\n",
+ " postfix.append(ch)\n",
+ " ch,ps = ps.pop(ps)\n",
+ " elif(ret_val == 3):\n",
+ " ch,ps = ps.pop(ps)\n",
+ " while(ps.prec(ch) >= 3):\n",
+ " postfix.append(ch)\n",
+ " ch,ps = ps.pop(ps)\n",
+ " ps = ps.push(ps,ch)\n",
+ " ps = ps.push(ps,infix[i])\n",
+ " elif(ret_val == 4):\n",
+ " ch,ps = ps.pop(ps)\n",
+ " while(ps.prec(ch) >= 4):\n",
+ " postfix.append(ch)\n",
+ " ch,ps = ps.pop(ps)\n",
+ " ps = ps.push(ps,ch)\n",
+ " ps = ps.push(ps,infix[i])\n",
+ " elif(ret_val == 5):\n",
+ " ch,ps = ps.pop(ps)\n",
+ " while(ps.prec(ch) == 5):\n",
+ " postfix.append(ch)\n",
+ " ch,ps = ps.pop(ps)\n",
+ " ps = ps.push(ps,ch)\n",
+ " ps = ps.push(ps,infix[i])\n",
+ " else:\n",
+ " postfix.append(infix[i])\n",
+ " print \"The postfix expression is: \"\n",
+ " print postfix\n",
+ "\n",
+ "choice = 'y'\n",
+ "while (choice == 'Y' or choice == 'y'):\n",
+ " print \"Enter an infix expression: \"\n",
+ " infix = raw_input()\n",
+ " infix_postfix(infix)\n",
+ " print \"Do you want to continue? Y/y \"\n",
+ " choice = raw_input()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an infix expression: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a+b\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The postfix expression is: \n",
+ "['a', 'b', '+']\n",
+ "Do you want to continue? Y/y \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7, page no. 57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAXSIZE = 100\n",
+ "\n",
+ "class stack:\n",
+ " def __init__(self):\n",
+ " self.stack = []\n",
+ " self.top = -1\n",
+ "\n",
+ "def push(pu,item):\n",
+ " if(pu.top == MAXSIZE-1):\n",
+ " print \"The stack is full\"\n",
+ " else:\n",
+ " pu.stack.append(item)\n",
+ " pu.top += 1\n",
+ " return pu\n",
+ "\n",
+ "def pop(po):\n",
+ " if(po.top == -1):\n",
+ " print \"Stack is empty\"\n",
+ " else:\n",
+ " item = po.stack.pop()\n",
+ " po.top-=1\n",
+ " return po, item\n",
+ "\n",
+ "def postfix_eval(postfix):\n",
+ " ps = stack()\n",
+ " for i in range(0,len(postfix)):\n",
+ " if(postfix[i]<='9' and postfix[i]>='0'):\n",
+ " ps = push(ps, postfix[i])\n",
+ " else:\n",
+ " ps, a = pop(ps)\n",
+ " ps, b = pop(ps)\n",
+ " a = int(a)\n",
+ " b = int(b)\n",
+ " temp = 0\n",
+ " if postfix[i] == \"+\":\n",
+ " temp = b+a\n",
+ " elif postfix[i] == \"-\":\n",
+ " temp = b-a\n",
+ " elif postfix[i] == \"*\":\n",
+ " temp = b*a\n",
+ " elif postfix[i] == \"/\":\n",
+ " temp = b/a\n",
+ " elif postfix[i] == \"%\":\n",
+ " temp = a%b\n",
+ " elif postfix[i] == \"^\":\n",
+ " temp = pow(a,b)\n",
+ " ps = push(ps, temp)\n",
+ " ps, a = pop(ps)\n",
+ " return a\n",
+ "\n",
+ "choice = \"y\"\n",
+ "while(choice == \"Y\" or choice == \"y\"):\n",
+ " print \"Enter the postfix expression: \",\n",
+ " post_fix = raw_input()\n",
+ " print \"The post fix evaluation is \", postfix_eval(post_fix),\n",
+ " print \"\\nYou want to continue(Y/y) ?? \"\n",
+ " choice = raw_input()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the postfix expression: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "54+\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The post fix evaluation is 9 \n",
+ "You want to continue(Y/y) ?? \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Example 8 will be same as Example 6."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_of_Data_structures_using_C_and_C++/chapter4.ipynb b/Principles_of_Data_structures_using_C_and_C++/chapter4.ipynb
new file mode 100644
index 00000000..2459282d
--- /dev/null
+++ b/Principles_of_Data_structures_using_C_and_C++/chapter4.ipynb
@@ -0,0 +1,818 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:78073ee3f019a89e9443c28342a99a4f8760679d25266109d7f7c11d0a9e5ceb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4: The Queue"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, page no. 68"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "MAX = 50\n",
+ "queue_arr = []\n",
+ "rear = [-1]\n",
+ "front = [-1]\n",
+ "\n",
+ "def insert():\n",
+ " if (rear[0] == MAX-1):\n",
+ " print \"Queue is full...\"\n",
+ " return\n",
+ " else:\n",
+ " if(front[0] == -1):\n",
+ " front[0] = 0\n",
+ " print \"Input the element to be added: \"\n",
+ " added_item = int(raw_input())\n",
+ " rear[0] = rear[0]+1\n",
+ " queue_arr.append(added_item)\n",
+ "\n",
+ "def que_del(): # del() is an inbuilt function in python so we name it as que_del here\n",
+ " print front[0]\n",
+ " if(front[0] == -1 or front[0]>rear[0]):\n",
+ " print \"Queue is empty...\"\n",
+ " return\n",
+ " else:\n",
+ " dell = front[0]\n",
+ " print \"Deleted element from queue is: \", queue_arr[dell]\n",
+ " front[0] = front[0]+1\n",
+ "\n",
+ "def display():\n",
+ " if(front[0] == -1 or front[0]>rear[0]):\n",
+ " print \"Queue is empty...\"\n",
+ " return\n",
+ " else:\n",
+ " print \"Queue is: \"\n",
+ " for i in range(front[0],rear[0]+1):\n",
+ " print queue_arr[i],\n",
+ "\n",
+ "while(1):\n",
+ " print \"\\n1. Insert\"\n",
+ " print \"2. Delete\"\n",
+ " print \"3. Display\"\n",
+ " print \"4. Quit\"\n",
+ " print \"Enter your choice: \"\n",
+ " choice = raw_input()\n",
+ " if choice == '1':\n",
+ " insert()\n",
+ " elif choice == '2':\n",
+ " que_del()\n",
+ " elif choice == '3':\n",
+ " display()\n",
+ " elif choice == '4':\n",
+ " sys.exit()\n",
+ " else:\n",
+ " print \"You entered an invalid choice...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert\n",
+ "2. Delete\n",
+ "3. Display\n",
+ "4. Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the element to be added: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert\n",
+ "2. Delete\n",
+ "3. Display\n",
+ "4. Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the element to be added: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert\n",
+ "2. Delete\n",
+ "3. Display\n",
+ "4. Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Queue is: \n",
+ "5 10 \n",
+ "1. Insert\n",
+ "2. Delete\n",
+ "3. Display\n",
+ "4. Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, page no. 73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "MAX = 50\n",
+ "\n",
+ "class circular_queue:\n",
+ " def __init__(self):\n",
+ " self.cqueue_arr = []\n",
+ " self.rear = -1\n",
+ " self.front = -1\n",
+ "\n",
+ " def insert(self):\n",
+ " if((self.front == 0 and self.rear == MAX-1) or (self.front == self.rear+1)):\n",
+ " print \"Queue is full...\"\n",
+ " return\n",
+ " if(self.front == -1):\n",
+ " self.front = 0\n",
+ " self.rear = 0\n",
+ " else:\n",
+ " if(self.rear == MAX-1):\n",
+ " rear = 0\n",
+ " else:\n",
+ " self.rear = self.rear+1\n",
+ " print \"Enter element to be added: \"\n",
+ " item_added = int(raw_input())\n",
+ " self.cqueue_arr.append(item_added)\n",
+ " \n",
+ " def que_del(self):\n",
+ " if(self.front == -1):\n",
+ " print \"Queue is empty...\"\n",
+ " return\n",
+ " print \"Element deleted from queue is: \", self.cqueue_arr[self.front]\n",
+ " if(self.front == self.rear):\n",
+ " self.front = -1\n",
+ " self.rear = -1\n",
+ " else:\n",
+ " if(self.front == MAX-1):\n",
+ " self.front = 0\n",
+ " else:\n",
+ " self.front += 1\n",
+ " \n",
+ " def display(self):\n",
+ " front_pos = self.front\n",
+ " rear_pos = self.rear\n",
+ " if(self.front == -1):\n",
+ " print \"Queue is empty...\"\n",
+ " return\n",
+ " print \"Queue Elements: \",\n",
+ " if(front_pos <= rear_pos):\n",
+ " while(front_pos <= rear_pos):\n",
+ " print \" \", self.cqueue_arr[front_pos],\n",
+ " front_pos += 1\n",
+ " \n",
+ "co = circular_queue()\n",
+ "while(1):\n",
+ " print \"\\n1. Insert\"\n",
+ " print \"2. Delete\"\n",
+ " print \"3. Display\"\n",
+ " print \"4. Quit\"\n",
+ " print \"Enter your choice: \"\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " co.insert()\n",
+ " elif choice == 2:\n",
+ " co.que_del()\n",
+ " elif choice == 3:\n",
+ " co.display()\n",
+ " elif choice == 4:\n",
+ " sys.exit()\n",
+ " else:\n",
+ " print \"You entered an invalid choice...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert\n",
+ "2. Delete\n",
+ "3. Display\n",
+ "4. Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter element to be added: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert\n",
+ "2. Delete\n",
+ "3. Display\n",
+ "4. Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter element to be added: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert\n",
+ "2. Delete\n",
+ "3. Display\n",
+ "4. Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter element to be added: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert\n",
+ "2. Delete\n",
+ "3. Display\n",
+ "4. Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Queue Elements: 5 10 15 \n",
+ "1. Insert\n",
+ "2. Delete\n",
+ "3. Display\n",
+ "4. Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, page no. 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "MAX = 50\n",
+ "left = -1\n",
+ "right = -1\n",
+ "dqueue_arr = []\n",
+ "\n",
+ "# insert element to right\n",
+ "def insert_right():\n",
+ " global left, right, dqueue_arr\n",
+ " if ((left == 0 and right == MAX-1) or (left == right+1)):\n",
+ " print \"Queue is full...\"\n",
+ " return\n",
+ " if(left == -1):\n",
+ " left = 0\n",
+ " right = 0\n",
+ " else:\n",
+ " if(right == MAX-1):\n",
+ " right = 0;\n",
+ " else:\n",
+ " right = right+1;\n",
+ " print \"Input the element for adding in queue: \"\n",
+ " added_item = int(raw_input())\n",
+ " # Inputting the element at the right\n",
+ " dqueue_arr.append(added_item)\n",
+ "\n",
+ "def insert_left():\n",
+ " global left, right, dqueue_arr\n",
+ " # Checking for queue overflow\n",
+ " if ((left == 0 and right == MAX-1) or (left == right+1)):\n",
+ " print \"Queue is full...\"\n",
+ " return\n",
+ " if (left == -1): # If queue is initially empty\n",
+ " left = 0;\n",
+ " right = 0;\n",
+ " else:\n",
+ " if (left== 0):\n",
+ " left = MAX -1;\n",
+ " else:\n",
+ " left = left-1;\n",
+ " print \"\\nInput the element for adding in queue:\"\n",
+ " added_item = int(raw_input())\n",
+ " # inputting at the left side of the queue\n",
+ " dqueue_arr.insert(added_item,left)\n",
+ "\n",
+ "# This function will delete an element from the queue from the left side\n",
+ "def delete_left():\n",
+ " global left, right, dqueue_arr\n",
+ " # Checking for queue underflow\n",
+ " if (left == -1):\n",
+ " print \"Queue is empty... \"\n",
+ " return\n",
+ " # deleting the element from the left side\n",
+ " print \"Element deleted from queue is: \", dqueue_arr[left]\n",
+ " if(left == right): # Queue has only one element \n",
+ " left = -1\n",
+ " right = -1\n",
+ " else:\n",
+ " if (left == MAX-1):\n",
+ " left = 0\n",
+ " else:\n",
+ " left = left+1\n",
+ " \n",
+ "# Function to delete an element from the right hand side of the de-queue\n",
+ "def delete_right():\n",
+ " global left, right, dqueue_arr\n",
+ " # Checking for underflow conditions\n",
+ " if (left == -1):\n",
+ " print \"Queue is empty...\"\n",
+ " return\n",
+ " print \"Element deleted from queue is : \", dqueue_arr[right]\n",
+ " if(left == right): # queue has only one element\n",
+ " left = -1\n",
+ " right = -1\n",
+ " else:\n",
+ " if (right == 0):\n",
+ " right = MAX-1\n",
+ " else:\n",
+ " right = right -1\n",
+ "\n",
+ "# Displaying all the contents of the queue\n",
+ "def display_queue():\n",
+ " global left, right, dqueue_arr\n",
+ " front_pos = left \n",
+ " rear_pos = right\n",
+ " # Checking whether the queue is empty or not\n",
+ " if (left == -1):\n",
+ " print \"Queue is empty...\"\n",
+ " return\n",
+ " # displaying the queue elements\n",
+ " print \"Queue elements :\",\n",
+ " if (front_pos <= rear_pos):\n",
+ " while(front_pos <= rear_pos):\n",
+ " print \" \", dqueue_arr[front_pos],\n",
+ " front_pos = front_pos + 1\n",
+ "\n",
+ "# Function to implement all the operation of the input restricted queue\n",
+ "def input_que():\n",
+ " global left, right, dqueue_arr\n",
+ " while(1):\n",
+ " # menu options to input restricted queue\n",
+ " print \"\\n1.Insert at right\"\n",
+ " print \"2.Delete from left\\n\"\n",
+ " print \"3.Delete from right\\n\"\n",
+ " print \"4.Display\\n\"\n",
+ " print \"5.Quit\\n\"\n",
+ " print \"\\nEnter your choice : \"\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " insert_right()\n",
+ " display_queue()\n",
+ " elif choice == 2:\n",
+ " delete_left()\n",
+ " elif choice == 3:\n",
+ " delete_right()\n",
+ " elif choice == 4:\n",
+ " display_queue()\n",
+ " elif choice == 5:\n",
+ " sys.exit\n",
+ " else:\n",
+ " print \"Wrong choice...\"\n",
+ "\n",
+ "def output_que():\n",
+ " global left, right, dqueue_arr\n",
+ " while(1):\n",
+ " # menu options for output restricted queue\n",
+ " print \"\\n1. Insert at right\"\n",
+ " print \"2. Insert at left\"\n",
+ " print \"3. Delete from left\"\n",
+ " print \"4. Display\"\n",
+ " print \"5 .Quit\"\n",
+ " print \"Enter your choice: \"\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " insert_right()\n",
+ " elif choice == 2:\n",
+ " insert_left()\n",
+ " elif choice == 3:\n",
+ " delete_left()\n",
+ " elif choice == 4:\n",
+ " display_queue()\n",
+ " elif choice == 5:\n",
+ " sys.exit()\n",
+ " else:\n",
+ " print \"Wrong choice...\"\n",
+ "\n",
+ "# Main menu options\n",
+ "print \"1. Input restricted dequeue\"\n",
+ "print \"2. Output restricted dequeue\"\n",
+ "print \"3. Enter your choice: \"\n",
+ "choice = int(raw_input())\n",
+ "if choice == 1:\n",
+ " input_que()\n",
+ "elif choice == 2:\n",
+ " output_que()\n",
+ "else:\n",
+ " print \"Wrong choice...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1. Input restricted dequeue\n",
+ "2. Output restricted dequeue\n",
+ "3. Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert at right\n",
+ "2. Insert at left\n",
+ "3. Delete from left\n",
+ "4. Display\n",
+ "5 .Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the element for adding in queue: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert at right\n",
+ "2. Insert at left\n",
+ "3. Delete from left\n",
+ "4. Display\n",
+ "5 .Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input the element for adding in queue: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1. Insert at right\n",
+ "2. Insert at left\n",
+ "3. Delete from left\n",
+ "4. Display\n",
+ "5 .Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element deleted from queue is: 5\n",
+ "\n",
+ "1. Insert at right\n",
+ "2. Insert at left\n",
+ "3. Delete from left\n",
+ "4. Display\n",
+ "5 .Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Queue elements : 10 \n",
+ "1. Insert at right\n",
+ "2. Insert at left\n",
+ "3. Delete from left\n",
+ "4. Display\n",
+ "5 .Quit\n",
+ "Enter your choice: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_of_Data_structures_using_C_and_C++/chapter5.ipynb b/Principles_of_Data_structures_using_C_and_C++/chapter5.ipynb
new file mode 100644
index 00000000..d2c1e55b
--- /dev/null
+++ b/Principles_of_Data_structures_using_C_and_C++/chapter5.ipynb
@@ -0,0 +1,2664 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5e20632f7ffb3d70fc7aa801806e31f8dcbb60de6731597c81506e60349baa6d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5: The Linked List"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, page no. 95"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class node:\n",
+ " def __init__(self, data=0, link=None):\n",
+ " self.data = data\n",
+ " self.link = link\n",
+ "\n",
+ "start = None\n",
+ "\n",
+ "def create_list(data):\n",
+ " global start\n",
+ " tmp = node(data)\n",
+ " q = node()\n",
+ " if(start==None):\n",
+ " start = tmp\n",
+ " else:\n",
+ " q = start\n",
+ " while(q.link != None):\n",
+ " q = q.link\n",
+ " q.link = tmp\n",
+ " \n",
+ "def AddAtBeg(data):\n",
+ " global start\n",
+ " tmp = node(data)\n",
+ " if(start == None):\n",
+ " start = tmp\n",
+ " else:\n",
+ " tmp.link = start\n",
+ " start = tmp\n",
+ " \n",
+ "def AddAfter(data, pos):\n",
+ " global start\n",
+ " q = start\n",
+ " for i in range(pos-1):\n",
+ " q = q.link\n",
+ " if(q == None):\n",
+ " print \"\\n\\n There are less than %d elements\" %pos\n",
+ " return\n",
+ " tmp = node(data)\n",
+ " tmp.link = q.link\n",
+ " q.link = tmp\n",
+ " \n",
+ "def Del(data):\n",
+ " global start\n",
+ " if (start.data == data):\n",
+ " tmp = start\n",
+ " start = start.link\n",
+ " return\n",
+ " q = start\n",
+ " while(q.link.link != None):\n",
+ " if(q.link.data == data):\n",
+ " tmp = q.link\n",
+ " q.link = tmp.link\n",
+ " return\n",
+ " q = q.link\n",
+ " if(q.link.data == data):\n",
+ " tmp = q.link;\n",
+ " q.link = None\n",
+ " return\n",
+ " print \"\\n\\nElement %d not found\" %data\n",
+ "\n",
+ "def Display():\n",
+ " global start\n",
+ " if(start == None):\n",
+ " print \"\\n\\nList is empty\"\n",
+ " return\n",
+ " q=start\n",
+ " print \"\\n\\nList is : \"\n",
+ " while(q != None):\n",
+ " print q.data,\n",
+ " q = q.link\n",
+ "\n",
+ "def Count():\n",
+ " global start\n",
+ " q = start\n",
+ " cnt = 0\n",
+ " while(q != None):\n",
+ " q = q.link\n",
+ " cnt+=1\n",
+ " print \"Number of elements are %d\\n\" %cnt\n",
+ "\n",
+ "def Rev():\n",
+ " global start\n",
+ " if(start.link==None):\n",
+ " return\n",
+ " p1 = start\n",
+ " p2 = p1.link\n",
+ " p3 = p2.link\n",
+ " p1.link = None\n",
+ " p2.link = p1\n",
+ " while(p3 != None):\n",
+ " p1=p2\n",
+ " p2=p3\n",
+ " p3=p3.link\n",
+ " p2.link=p1\n",
+ " start=p2\n",
+ "\n",
+ "def Search(data):\n",
+ " global start\n",
+ " ptr = start\n",
+ " pos = 1\n",
+ " while(ptr!=None):\n",
+ " if (ptr.data == data):\n",
+ " print \"\\n\\nItem %d found at position %d\" %(data, pos)\n",
+ " return\n",
+ " ptr = ptr.link\n",
+ " pos+=1\n",
+ " if (ptr == None):\n",
+ " print \"\\n\\nItem %d not found in list\" %data\n",
+ "\n",
+ "while(1):\n",
+ " print \"\\n1.Create List\"\n",
+ " print \"2.Add at beginning\"\n",
+ " print \"3.Add after\"\n",
+ " print \"4.Delete\"\n",
+ " print \"5.Display\"\n",
+ " print \"6.Count\"\n",
+ " print \"7.Reverse\"\n",
+ " print \"8.Search\"\n",
+ " print \"9.Quit\"\n",
+ " print \"Enter your choice: \",\n",
+ " choice =int(raw_input())\n",
+ " if choice == 1:\n",
+ " print \"\\n\\nHow many nodes you want:\"\n",
+ " n = int(raw_input())\n",
+ " for i in range(n):\n",
+ " print \"Enter the element: \"\n",
+ " data = int(raw_input())\n",
+ " create_list(data)\n",
+ " elif choice == 2:\n",
+ " print \"\\n\\nEnter the element : \"\n",
+ " data = int(raw_input())\n",
+ " AddAtBeg(data)\n",
+ " elif choice == 3:\n",
+ " print \"\\n\\nEnter the element : \"\n",
+ " data = int(raw_input())\n",
+ " print \"\\nEnter the position after which this element is inserted:\"\n",
+ " pos = int(raw_input())\n",
+ " AddAfter(data,pos)\n",
+ " elif choice == 4:\n",
+ " if (start == None):\n",
+ " print \"\\n\\nList is empty\"\n",
+ " continue\n",
+ " print \"\\n\\nEnter the element for deletion:\"\n",
+ " data = int(raw_input())\n",
+ " Del(data)\n",
+ " elif choice == 5:\n",
+ " Display()\n",
+ " elif choice == 6:\n",
+ " Count()\n",
+ " elif choice == 7:\n",
+ " Rev()\n",
+ " elif choice == 8:\n",
+ " print \"\\n\\nEnter the element to be searched:\"\n",
+ " data = int(raw_input())\n",
+ " Search(data)\n",
+ " elif choice == 9:\n",
+ " sys.exit()\n",
+ " else:\n",
+ " print \"\\n\\nWrong choice\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Create List\n",
+ "2.Add at beginning\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Count\n",
+ "7.Reverse\n",
+ "8.Search\n",
+ "9.Quit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "How many nodes you want:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1.Create List\n",
+ "2.Add at beginning\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Count\n",
+ "7.Reverse\n",
+ "8.Search\n",
+ "9.Quit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "List is : \n",
+ "10 15 20 \n",
+ "1.Create List\n",
+ "2.Add at beginning\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Count\n",
+ "7.Reverse\n",
+ "8.Search\n",
+ "9.Quit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Number of elements are 3\n",
+ "\n",
+ "\n",
+ "1.Create List\n",
+ "2.Add at beginning\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Count\n",
+ "7.Reverse\n",
+ "8.Search\n",
+ "9.Quit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2. page no. 101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "import sys\n",
+ "\n",
+ "class node:\n",
+ " def __init__(self, data=0, link=None):\n",
+ " self.data = data\n",
+ " self.link = link\n",
+ "\n",
+ "start = None\n",
+ "\n",
+ "class LinkedList():\n",
+ "\n",
+ " def create_list(self,data):\n",
+ " global start\n",
+ " tmp = node(data)\n",
+ " q = node()\n",
+ " if(start==None):\n",
+ " start = tmp\n",
+ " else:\n",
+ " q = start\n",
+ " while(q.link != None):\n",
+ " q = q.link\n",
+ " q.link = tmp\n",
+ " \n",
+ " \n",
+ " def AddAtBeg(self,data):\n",
+ " global start\n",
+ " tmp = node(data)\n",
+ " if(start == None):\n",
+ " start = tmp\n",
+ " else:\n",
+ " tmp.link = start\n",
+ " start = tmp\n",
+ " \n",
+ "\n",
+ " def AddAfter(self,data, pos):\n",
+ " global start\n",
+ " q = start\n",
+ " for i in range(pos-1):\n",
+ " q = q.link\n",
+ " if(q == None):\n",
+ " print \"\\n\\n There are less than %d elements\" %pos\n",
+ " return\n",
+ " tmp = node(data)\n",
+ " tmp.link = q.link\n",
+ " q.link = tmp\n",
+ " \n",
+ "\n",
+ " def Del(self,data):\n",
+ " global start\n",
+ " if (start.data == data):\n",
+ " tmp = start\n",
+ " start = start.link\n",
+ " return\n",
+ " q = start\n",
+ " while(q.link.link != None):\n",
+ " if(q.link.data == data):\n",
+ " tmp = q.link\n",
+ " q.link = tmp.link\n",
+ " return\n",
+ " q = q.link\n",
+ " if(q.link.data == data):\n",
+ " tmp = q.link;\n",
+ " q.link = None\n",
+ " return\n",
+ " print \"\\n\\nElement %d not found\" %data \n",
+ "\n",
+ "\n",
+ " def Display(self):\n",
+ " global start\n",
+ " if(start == None):\n",
+ " print \"\\n\\nList is empty\"\n",
+ " return\n",
+ " q=start\n",
+ " print \"\\n\\nList is : \"\n",
+ " while(q != None):\n",
+ " print q.data,\n",
+ " q = q.link\n",
+ " \n",
+ " def Count(self):\n",
+ " global start\n",
+ " q = start\n",
+ " cnt = 0\n",
+ " while(q != None):\n",
+ " q = q.link\n",
+ " cnt+=1\n",
+ " print \"Number of elements are %d\\n\" %cnt\n",
+ " \n",
+ " \n",
+ " def Rev(self):\n",
+ " global start\n",
+ " if(start.link==None):\n",
+ " return\n",
+ " p1 = start\n",
+ " p2 = p1.link\n",
+ " p3 = p2.link\n",
+ " p1.link = None\n",
+ " p2.link = p1\n",
+ " while(p3 != None):\n",
+ " p1=p2\n",
+ " p2=p3\n",
+ " p3=p3.link\n",
+ " p2.link=p1\n",
+ " start=p2\n",
+ " \n",
+ "\n",
+ " def Search(self,data):\n",
+ " global start\n",
+ " ptr = start\n",
+ " pos = 1\n",
+ " while(ptr!=None):\n",
+ " if (ptr.data == data):\n",
+ " print \"\\n\\nItem %d found at position %d\" %(data, pos)\n",
+ " return\n",
+ " ptr = ptr.link\n",
+ " pos+=1\n",
+ " if (ptr == None):\n",
+ " print \"\\n\\nItem %d not found in list\" %data\n",
+ " \n",
+ "\n",
+ "l_list = LinkedList()\n",
+ "\n",
+ "while(1):\n",
+ " print \"\\n1.Create List\"\n",
+ " print \"2.Add at beginning\"\n",
+ " print \"3.Add after\"\n",
+ " print \"4.Delete\"\n",
+ " print \"5.Display\"\n",
+ " print \"6.Count\"\n",
+ " print \"7.Reverse\"\n",
+ " print \"8.Search\"\n",
+ " print \"9.Quit\"\n",
+ " print \"Enter your choice: \",\n",
+ " choice =int(raw_input())\n",
+ " if choice == 1:\n",
+ " print \"\\n\\nHow many nodes you want:\"\n",
+ " n = int(raw_input())\n",
+ " for i in range(n):\n",
+ " print \"Enter the element: \"\n",
+ " data = int(raw_input())\n",
+ " l_list.create_list(data)\n",
+ " elif choice == 2:\n",
+ " print \"\\n\\nEnter the element : \"\n",
+ " data = int(raw_input())\n",
+ " l_list.AddAtBeg(data)\n",
+ " elif choice == 3:\n",
+ " print \"\\n\\nEnter the element : \"\n",
+ " data = int(raw_input())\n",
+ " print \"\\nEnter the position after which this element is inserted:\"\n",
+ " pos = int(raw_input())\n",
+ " l_list.AddAfter(data,pos)\n",
+ " elif choice == 4:\n",
+ " if (start == None):\n",
+ " print \"\\n\\nList is empty\"\n",
+ " continue\n",
+ " print \"\\n\\nEnter the element for deletion:\"\n",
+ " data = int(raw_input())\n",
+ " l_list.Del(data)\n",
+ " elif choice == 5:\n",
+ " l_list.Display()\n",
+ " elif choice == 6:\n",
+ " l_list.Count()\n",
+ " elif choice == 7:\n",
+ " l_list.Rev()\n",
+ " elif choice == 8:\n",
+ " print \"\\n\\nEnter the element to be searched:\"\n",
+ " data = int(raw_input())\n",
+ " l_list.Search(data)\n",
+ " elif choice == 9:\n",
+ " sys.exit()\n",
+ " else:\n",
+ " print \"\\n\\nWrong choice\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Create List\n",
+ "2.Add at beginning\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Count\n",
+ "7.Reverse\n",
+ "8.Search\n",
+ "9.Quit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "How many nodes you want:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1.Create List\n",
+ "2.Add at beginning\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Count\n",
+ "7.Reverse\n",
+ "8.Search\n",
+ "9.Quit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "List is : \n",
+ "5 10 15 \n",
+ "1.Create List\n",
+ "2.Add at beginning\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Count\n",
+ "7.Reverse\n",
+ "8.Search\n",
+ "9.Quit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Number of elements are 3\n",
+ "\n",
+ "\n",
+ "1.Create List\n",
+ "2.Add at beginning\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Count\n",
+ "7.Reverse\n",
+ "8.Search\n",
+ "9.Quit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, page no. 109"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class node:\n",
+ " def __init__(self, link=None):\n",
+ " self.data = None\n",
+ " self.link = link\n",
+ " \n",
+ "start = None\n",
+ "\n",
+ "\n",
+ "def push(top):\n",
+ " new = node()\n",
+ " print \"Enter element to be pushed: \",\n",
+ " pushed_item = int(raw_input())\n",
+ " new.data = pushed_item\n",
+ " new.link = top\n",
+ " top = new\n",
+ " return top\n",
+ "\n",
+ "def pop(top):\n",
+ " tmp = node()\n",
+ " if(top == None):\n",
+ " print \"Stack is empty...\" \n",
+ " else:\n",
+ " tmp = top\n",
+ " print \"Popped item is: \", tmp.data\n",
+ " top = top.link\n",
+ " tmp.link = None\n",
+ " return top\n",
+ "\n",
+ "def display(top):\n",
+ " if(top == None):\n",
+ " print \"Stack is empty...\"\n",
+ " else:\n",
+ " print \"Stack elements: \"\n",
+ " while(top.link != None):\n",
+ " print top.data,\n",
+ " top = top.link\n",
+ " \n",
+ "Top = node()\n",
+ "while(1):\n",
+ " print \"\\n1.PUSH\"\n",
+ " print \"2.POP\"\n",
+ " print \"3.DISPLAY\"\n",
+ " print \"4.EXIT\"\n",
+ " print \"Enter your choice: \",\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " Top = push(Top)\n",
+ " elif choice == 2:\n",
+ " Top=pop(Top)\n",
+ " elif choice == 3:\n",
+ " display(Top)\n",
+ " elif choice == 4:\n",
+ " sys.exit() \n",
+ " else:\n",
+ " print \"Wrong choice\"\n",
+ " print \"\\nDo you want to continue (Y/y) = \"\n",
+ " ch = raw_input()\n",
+ " if ch == 'Y' or ch == 'y':\n",
+ " continue\n",
+ " else:\n",
+ " sys.exit()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.DISPLAY\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element to be pushed: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.DISPLAY\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element to be pushed: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.DISPLAY\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Stack elements: \n",
+ "10 5 \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.DISPLAY\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, page no. 111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class node:\n",
+ " def __init__(self, link=None):\n",
+ " self.data = None\n",
+ " self.link = link\n",
+ "\n",
+ "\n",
+ "class linkList:\n",
+ " def push(self, top):\n",
+ " new = node()\n",
+ " print \"Enter element to be pushed: \",\n",
+ " pushed_item = int(raw_input())\n",
+ " new.data = pushed_item\n",
+ " new.link = top\n",
+ " top = new\n",
+ " return top\n",
+ "\n",
+ " def pop(self, top):\n",
+ " tmp = node()\n",
+ " if(top == None):\n",
+ " print \"Stack is empty...\" \n",
+ " else:\n",
+ " tmp = top\n",
+ " print \"Popped item is: \", tmp.data\n",
+ " top = top.link\n",
+ " tmp.link = None\n",
+ " return top\n",
+ "\n",
+ " def display(self, top):\n",
+ " if(top == None):\n",
+ " print \"Stack is empty...\"\n",
+ " else:\n",
+ " print \"Stack elements: \"\n",
+ " while(top.link != None):\n",
+ " print top.data,\n",
+ " top = top.link\n",
+ " \n",
+ "Top = node()\n",
+ "link_list = linkList()\n",
+ "while(1):\n",
+ " print \"\\n1.PUSH\"\n",
+ " print \"2.POP\"\n",
+ " print \"3.DISPLAY\"\n",
+ " print \"4.EXIT\"\n",
+ " print \"Enter your choice: \",\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " Top = link_list.push(Top)\n",
+ " elif choice == 2:\n",
+ " Top = link_list.pop(Top)\n",
+ " elif choice == 3:\n",
+ " link_list.display(Top)\n",
+ " elif choice == 4:\n",
+ " sys.exit() \n",
+ " else:\n",
+ " print \"Wrong choice\"\n",
+ " print \"\\nDo you want to continue (Y/y) = \"\n",
+ " ch = raw_input()\n",
+ " if ch == 'Y' or ch == 'y':\n",
+ " continue\n",
+ " else:\n",
+ " sys.exit()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.DISPLAY\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element to be pushed: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.DISPLAY\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element to be pushed: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.DISPLAY\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Stack elements: \n",
+ "10 5 None \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.DISPLAY\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, page no. 116"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class node:\n",
+ " def __init__(self, link=None):\n",
+ " self.data = None\n",
+ " self.link = link\n",
+ "\n",
+ "def push(rear):\n",
+ " new_node = node()\n",
+ " print \"Enter the no. to be pushed: \",\n",
+ " new_node.data = int(raw_input())\n",
+ " new_node.link = None\n",
+ " if (rear != None):\n",
+ " rear.link = new_node\n",
+ " rear = new_node\n",
+ " return rear\n",
+ "\n",
+ "def pop(f, r):\n",
+ " if f == None:\n",
+ " print \"The Queue is empty\"\n",
+ " else:\n",
+ " print \"The poped element is: \", f.data\n",
+ " if f != r:\n",
+ " f = f.link\n",
+ " else:\n",
+ " f = None\n",
+ " return f\n",
+ "\n",
+ "def traverse(fr, re):\n",
+ " if fr == None:\n",
+ " print \"The Queue is empty\"\n",
+ " else:\n",
+ " print \"The element(s) is/are: \"\n",
+ " while fr != re:\n",
+ " print fr.data,\n",
+ " fr = fr.link\n",
+ " print fr.data,\n",
+ "\n",
+ "rear = None\n",
+ "front = None\n",
+ "while(1):\n",
+ " print \"\\n1.PUSH\"\n",
+ " print \"2.POP\"\n",
+ " print \"3.TRAVERSE\"\n",
+ " print \"4.EXIT\"\n",
+ " print \"Enter your choice: \",\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " rear = push(rear)\n",
+ " if front == None:\n",
+ " front = rear\n",
+ " elif choice == 2:\n",
+ " front = pop(front, rear)\n",
+ " if front == None:\n",
+ " rear = None\n",
+ " elif choice == 3:\n",
+ " traverse(front, rear)\n",
+ " elif choice == 4:\n",
+ " sys.exit() \n",
+ " else:\n",
+ " print \"Wrong choice\"\n",
+ " print \"\\nDo you want to continue (Y/y) = \"\n",
+ " ch = raw_input()\n",
+ " if ch == 'Y' or ch == 'y':\n",
+ " continue\n",
+ " else:\n",
+ " sys.exit()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.TRAVERSE\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the no. to be pushed: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.TRAVERSE\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the no. to be pushed: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.TRAVERSE\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The element(s) is/are: \n",
+ "5 10 \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.TRAVERSE\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6, page no. 119"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class node:\n",
+ " def __init__(self, link=None):\n",
+ " self.data = None\n",
+ " self.link = link\n",
+ "\n",
+ "class linkList:\n",
+ " def push(self, rear):\n",
+ " new_node = node()\n",
+ " print \"Enter the no. to be pushed: \",\n",
+ " new_node.data = int(raw_input())\n",
+ " new_node.link = None\n",
+ " if (rear != None):\n",
+ " rear.link = new_node\n",
+ " rear = new_node\n",
+ " return rear\n",
+ "\n",
+ " def pop(self, f, r):\n",
+ " if f == None:\n",
+ " print \"The Queue is empty\"\n",
+ " else:\n",
+ " print \"The poped element is: \", f.data\n",
+ " if f != r:\n",
+ " f = f.link\n",
+ " else:\n",
+ " f = None\n",
+ " return f\n",
+ "\n",
+ " def traverse(self, fr, re):\n",
+ " if fr == None:\n",
+ " print \"The Queue is empty\"\n",
+ " else:\n",
+ " print \"The element(s) is/are: \"\n",
+ " while fr != re:\n",
+ " print fr.data,\n",
+ " fr = fr.link\n",
+ " print fr.data,\n",
+ " \n",
+ "rear = None\n",
+ "front = None\n",
+ "l = linkList()\n",
+ "while(1):\n",
+ " print \"\\n1.PUSH\"\n",
+ " print \"2.POP\"\n",
+ " print \"3.TRAVERSE\"\n",
+ " print \"4.EXIT\"\n",
+ " print \"Enter your choice: \",\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " rear = l.push(rear)\n",
+ " if front == None:\n",
+ " front = rear\n",
+ " elif choice == 2:\n",
+ " front = l.pop(front, rear)\n",
+ " if front == None:\n",
+ " rear = None\n",
+ " elif choice == 3:\n",
+ " l.traverse(front, rear)\n",
+ " elif choice == 4:\n",
+ " sys.exit() \n",
+ " else:\n",
+ " print \"Wrong choice\"\n",
+ " print \"\\nDo you want to continue (Y/y) = \"\n",
+ " ch = raw_input()\n",
+ " if ch == 'Y' or ch == 'y':\n",
+ " continue\n",
+ " else:\n",
+ " sys.exit()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.TRAVERSE\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the no. to be pushed: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.TRAVERSE\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the no. to be pushed: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.TRAVERSE\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The element(s) is/are: \n",
+ "5 10 \n",
+ "1.PUSH\n",
+ "2.POP\n",
+ "3.TRAVERSE\n",
+ "4.EXIT\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Wrong choice\n",
+ "\n",
+ "Do you want to continue (Y/y) = \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8, page no. 127"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class node:\n",
+ " \n",
+ " def __init__(self):\n",
+ " self.coef = 0.0\n",
+ " self.expo = 0\n",
+ " self.link = None\n",
+ "\n",
+ "def insert(start, co, ex):\n",
+ " ptr = node()\n",
+ " tmp = node()\n",
+ " tmp.coef = co\n",
+ " tmp.expo = ex\n",
+ " if(start==None or ex>start.expo):\n",
+ " tmp.link=start\n",
+ " start = tmp\n",
+ " else:\n",
+ " ptr=start\n",
+ " while(ptr.link != None and ptr.link.expo > ex):\n",
+ " ptr = ptr.link\n",
+ " tmp.link = ptr.link\n",
+ " ptr.link = tmp\n",
+ " if(ptr.link==None):\n",
+ " tmp.link = None\n",
+ " return start\n",
+ "\n",
+ "def poly_add(p1, p2):\n",
+ " p3 = node()\n",
+ " tmp = node()\n",
+ " p3_start = None\n",
+ " if(p1 == None and p2 == None):\n",
+ " return p3_start\n",
+ " while(p1 != None and p2 != None):\n",
+ " if(p3_start == None):\n",
+ " p3_start = tmp\n",
+ " p3 = p3_start\n",
+ " else:\n",
+ " p3.link = tmp\n",
+ " p3 = p3.link\n",
+ " if(p1.expo > p2.expo):\n",
+ " tmp.coef=p1.coef\n",
+ " tmp.expo=p1.expo\n",
+ " p1 = p1.link\n",
+ " else:\n",
+ " if(p2.expo > p1.expo):\n",
+ " tmp.coef = p2.coef\n",
+ " tmp.expo = p2.expo\n",
+ " p2 = p2.link\n",
+ " else:\n",
+ " if(p1.expo == p2.expo):\n",
+ " tmp.coef=p1.coef + p2.coef\n",
+ " tmp.expo=p1.expo\n",
+ " p1=p1.link\n",
+ " p2=p2.link\n",
+ " while(p1!=None):\n",
+ " tmp.coef = p1.coef\n",
+ " tmp.expo = p1.expo\n",
+ " if (p3_start==None):\n",
+ " p3_start=tmp\n",
+ " p3=p3_start\n",
+ " else:\n",
+ " p3.link=tmp\n",
+ " p3=p3.link\n",
+ " p1=p1.link\n",
+ " while(p2!=None):\n",
+ " tmp.coef = p2.coef\n",
+ " tmp.expo = p2.expo\n",
+ " if (p3_start==None):\n",
+ " p3_start = tmp\n",
+ " p3 = p3_start\n",
+ " else:\n",
+ " p3.link = tmp\n",
+ " p3 = p3.link\n",
+ " p2 = p2.link\n",
+ " p3.link = None\n",
+ " return p3_start\n",
+ "\n",
+ "def enter(start):\n",
+ " print \"How many terms u want to enter: \"\n",
+ " n = int(raw_input())\n",
+ " for i in range(n):\n",
+ " print \"Enter coeficient for term %d:\" %i\n",
+ " co = float(raw_input())\n",
+ " print \"Enter exponent for term %d:\" %i\n",
+ " ex = int(raw_input())\n",
+ " start = insert(start,co,ex);\n",
+ " return start\n",
+ "\n",
+ "def display(ptr):\n",
+ " if (ptr==None):\n",
+ " print \"Empty...\"\n",
+ " return\n",
+ " while(ptr!=None):\n",
+ " print \"(%.1fx^%d) + \" %(ptr.coef, ptr.expo)\n",
+ " ptr = ptr.link\n",
+ " print \"\\b\\b \\n\"\n",
+ "\n",
+ "p1_start=None\n",
+ "p2_start=None\n",
+ "p3_start=None\n",
+ "print \"\\nPolynomial 1 : \"\n",
+ "p1_start = enter(p1_start)\n",
+ "print \"\\nPolynomial 2 :\"\n",
+ "p2_start = enter(p2_start)\n",
+ "p3_start = poly_add(p1_start, p2_start)\n",
+ "print \"\\nPolynomial 1 is: \"\n",
+ "display(p1_start)\n",
+ "print \"Polynomial 2 is: \"\n",
+ "display(p2_start)\n",
+ "print \"\\nAdded polynomial is: \"\n",
+ "display (p3_start)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Polynomial 1 : \n",
+ "How many terms u want to enter: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter coeficient for term 0:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter exponent for term 0:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter coeficient for term 1:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter exponent for term 1:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Polynomial 2 :\n",
+ "How many terms u want to enter: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter coeficient for term 0:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter exponent for term 0:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter coeficient for term 1:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter exponent for term 1:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Polynomial 1 is: \n",
+ "(4.0x^5) + \n",
+ "(2.0x^3) + \n",
+ "\b\b \n",
+ "\n",
+ "Polynomial 2 is: \n",
+ "(3.0x^4) + \n",
+ "(1.0x^2) + \n",
+ "\b\b \n",
+ "\n",
+ "\n",
+ "Added polynomial is: \n",
+ "(1.0x^2) + \n",
+ "\b\b \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9, page no. 134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class node:\n",
+ " def __init__(self, info=0, next=None, prev=None):\n",
+ " self.info = info\n",
+ " self.next = next\n",
+ " self.prev = prev\n",
+ "\n",
+ "start = node()\n",
+ "\n",
+ "def create_list(num):\n",
+ " global start\n",
+ " tmp = node()\n",
+ " tmp.info = num\n",
+ " q = node()\n",
+ " if(start.next == None):\n",
+ " tmp.prev = None\n",
+ " start.prev = tmp\n",
+ " start = tmp\n",
+ " else:\n",
+ " q = start\n",
+ " while(q.next != None):\n",
+ " q = q.next\n",
+ " q.next = tmp\n",
+ " tmp.prev = q\n",
+ "\n",
+ "def addatbeg(num):\n",
+ " global start\n",
+ " tmp = node()\n",
+ " tmp.info = num\n",
+ " tmp.next = start\n",
+ " start.prev = tmp\n",
+ " start = tmp\n",
+ "\n",
+ "def addafter(num, pos):\n",
+ " global start\n",
+ " q=start\n",
+ " for i in range(0,pos-1):\n",
+ " q=q.next\n",
+ " if(q==None):\n",
+ " print \"\\nThere are less than %d elements\\n\" %pos\n",
+ " return\n",
+ " tmp = node()\n",
+ " tmp.info = num\n",
+ " q.next.prev = tmp\n",
+ " tmp.next = q.next\n",
+ " tmp.prev = q\n",
+ " q.next = tmp\n",
+ "\n",
+ "def my_del(num):\n",
+ " global start\n",
+ " if(start.info==num):\n",
+ " tmp = start\n",
+ " start = start.next\n",
+ " start.prev = None\n",
+ " return\n",
+ " q = start;\n",
+ " while(q.next.next != None):\n",
+ " if(q.next.info==num):\n",
+ " tmp=q.next\n",
+ " q.next=tmp.next\n",
+ " tmp.next.prev = q\n",
+ " return\n",
+ " q = q.next\n",
+ " if (q.next.info==num):\n",
+ " tmp = q.next\n",
+ " q.next = None\n",
+ " return\n",
+ " print \"\\nElement %d not found\\n\" %num\n",
+ "\n",
+ "def display():\n",
+ " global start\n",
+ " if(start==None):\n",
+ " print \"\\nList is empty\\n\"\n",
+ " return\n",
+ " q = start\n",
+ " print \"\\nList is :\\n\"\n",
+ " while(q!=None):\n",
+ " print q.info,\n",
+ " q = q.next\n",
+ "\n",
+ "def count():\n",
+ " global start\n",
+ " q=start\n",
+ " cnt=0\n",
+ " while(q!=None):\n",
+ " q=q.next\n",
+ " cnt+=1\n",
+ " print \"\\nNumber of elements are \\n\", cnt\n",
+ "\n",
+ "def rev():\n",
+ " global start\n",
+ " p1=start\n",
+ " p2=p1.next\n",
+ " p1.next=None\n",
+ " p1.prev=p2\n",
+ " while(p2!=None):\n",
+ " p2.prev=p2.next\n",
+ " p2.next=p1\n",
+ " p1=p2\n",
+ " p2=p2.prev\n",
+ " start=p1\n",
+ "\n",
+ "while(1):\n",
+ " print \"\\n1.Create List\"\n",
+ " print \"2.Add at begining\"\n",
+ " print \"3.Add after\"\n",
+ " print \"4.Delete\"\n",
+ " print \"5.Display\"\n",
+ " print \"6.Count\"\n",
+ " print \"7.Reverse\"\n",
+ " print \"8.exit\"\n",
+ " print \"Enter your choice: \",\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " print \"\\nHow many nodes you want: \",\n",
+ " n = int(raw_input())\n",
+ " for i in range(n):\n",
+ " print \"Enter the element: \",\n",
+ " m = int(raw_input())\n",
+ " create_list(m)\n",
+ " elif choice == 2:\n",
+ " print \"\\nEnter the element: \",\n",
+ " m = int(raw_input())\n",
+ " addatbeg(m)\n",
+ " elif choice == 3:\n",
+ " print \"\\nEnter the element: \",\n",
+ " m = int(raw_input())\n",
+ " print \"Enter the position after which this element is inserted: \",\n",
+ " po = int(raw_input())\n",
+ " addafter(m,po)\n",
+ " elif choice == 4:\n",
+ " print \"\\nEnter the element for deletion: \",\n",
+ " m = int(raw_input())\n",
+ " my_del(m);\n",
+ " elif choice == 5:\n",
+ " display()\n",
+ " elif choice == 6:\n",
+ " count()\n",
+ " elif choice == 7:\n",
+ " rev()\n",
+ " elif choice == 8:\n",
+ " sys.exit()\n",
+ " else:\n",
+ " print \"\\nWrong choice\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Create List\n",
+ "2.Add at begining\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Count\n",
+ "7.Reverse\n",
+ "8.exit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "How many nodes you want: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the element: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the element: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the element: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Create List\n",
+ "2.Add at begining\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Count\n",
+ "7.Reverse\n",
+ "8.exit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "List is :\n",
+ "\n",
+ "15 \n",
+ "1.Create List\n",
+ "2.Add at begining\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Count\n",
+ "7.Reverse\n",
+ "8.exit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10, page no. 141"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class node:\n",
+ " def __init__(self, info=None, link=None):\n",
+ " self.info = info\n",
+ " self.link = link\n",
+ "\n",
+ "last = None\n",
+ "class Circular_Linked:\n",
+ " def create_list(self, num):\n",
+ " global last\n",
+ " q = node()\n",
+ " tmp = node()\n",
+ " tmp.info = num\n",
+ " if (last == None):\n",
+ " last = tmp\n",
+ " tmp.link = last\n",
+ " else:\n",
+ " tmp.link = last.link\n",
+ " last.link = tmp\n",
+ " last = tmp\n",
+ "\n",
+ " def addatbeg(self, num):\n",
+ " global last\n",
+ " tmp = node()\n",
+ " tmp.info = num\n",
+ " tmp.link = last.link\n",
+ " last.link = tmp\n",
+ "\n",
+ " def addafter(self, num, pos):\n",
+ " global last\n",
+ " q = node()\n",
+ " tmp = node()\n",
+ " q = last.link\n",
+ " for i in range(0, pos-1):\n",
+ " q = q.link\n",
+ " if (q == last.link):\n",
+ " print \"There are less than \", pos, \" elements\"\n",
+ " return\n",
+ " tmp.link = q.link\n",
+ " tmp.info = num\n",
+ " q.link = tmp\n",
+ " if(q==last):\n",
+ " last=tmp\n",
+ "\n",
+ " def my_del(self):\n",
+ " global last\n",
+ " if(last == None):\n",
+ " print \"List underflow\"\n",
+ " return\n",
+ " print \"Enter the number for deletion:\"\n",
+ " num = int(raw_input())\n",
+ " q = node()\n",
+ " tmp = node()\n",
+ " if( last.link == last and last.info == num):\n",
+ " tmp = last\n",
+ " last = None\n",
+ " return\n",
+ " q = last.link\n",
+ " if(q.info == num):\n",
+ " tmp = q\n",
+ " last.link = q.link\n",
+ " return\n",
+ " while(q.link != last):\n",
+ " if(q.link.info == num):\n",
+ " tmp = q.link\n",
+ " q.link = tmp.link\n",
+ " print num, \" deleted\"\n",
+ " q = q.link\n",
+ " if(q.link.info == num):\n",
+ " tmp = q.link\n",
+ " q.link = last.link\n",
+ " last = q\n",
+ " return\n",
+ " print \"Element \",num,\" not found\"\n",
+ "\n",
+ " def display(self):\n",
+ " global last\n",
+ " q = node()\n",
+ " if(last == None):\n",
+ " print \"List is empty\"\n",
+ " return\n",
+ " q = last.link\n",
+ " print \"List is:\"\n",
+ " while(q != last):\n",
+ " print q.info,\n",
+ " q = q.link\n",
+ " print last.info\n",
+ " \n",
+ "co = Circular_Linked()\n",
+ "while(1):\n",
+ " print \"\\n1.Create List\"\n",
+ " print \"2.Add at begining\"\n",
+ " print \"3.Add after\"\n",
+ " print \"4.Delete\"\n",
+ " print \"5.Display\"\n",
+ " print \"6.Quit\"\n",
+ " print \"Enter your choice:\"\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " print \"How many nodes you want:\",\n",
+ " n = int(raw_input())\n",
+ " for i in range(n):\n",
+ " print \"\\nEnter the element:\",\n",
+ " m = int(raw_input())\n",
+ " co.create_list(m)\n",
+ " elif choice == 2:\n",
+ " print \"\\nEnter the element:\",\n",
+ " m = int(raw_input())\n",
+ " co.addatbeg(m)\n",
+ " elif choice == 3:\n",
+ " print \"\\nEnter the element:\",\n",
+ " m = int(raw_input())\n",
+ " print \"\\nEnter the position after which this element is inserted:\",\n",
+ " po = int(raw_input())\n",
+ " co.addafter(m,po)\n",
+ " elif choice == 4:\n",
+ " co.my_del()\n",
+ " elif choice == 5:\n",
+ " co.display()\n",
+ " elif choice == 6:\n",
+ " sys.exit()\n",
+ " else:\n",
+ " print \"Wrong choice\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Create List\n",
+ "2.Add at begining\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Quit\n",
+ "Enter your choice:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many nodes you want:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the element:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the element:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the element:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Create List\n",
+ "2.Add at begining\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Quit\n",
+ "Enter your choice:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "List is:\n",
+ "5 10 15\n",
+ "\n",
+ "1.Create List\n",
+ "2.Add at begining\n",
+ "3.Add after\n",
+ "4.Delete\n",
+ "5.Display\n",
+ "6.Quit\n",
+ "Enter your choice:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11, page no. 148"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class node:\n",
+ " def __init__(self, priority=None, info=None, link=None):\n",
+ " self.priority = priority\n",
+ " self.info = info\n",
+ " self.link = link\n",
+ "\n",
+ "def insert(front):\n",
+ " tmp = node()\n",
+ " q = node()\n",
+ " print \"Input the item value to be added in the queue:\"\n",
+ " added_item = int(raw_input())\n",
+ " print \"Enter its priority:\"\n",
+ " item_priority = int(raw_input())\n",
+ " tmp.info = added_item\n",
+ " tmp.priority = item_priority\n",
+ " if(front == None or item_priority < front.priority):\n",
+ " tmp.link = front\n",
+ " front = tmp\n",
+ " else:\n",
+ " q = front\n",
+ " while(q.link != None and q.link.priority <= item_priority):\n",
+ " q = q.link\n",
+ " tmp.link = q.link\n",
+ " q.link = tmp\n",
+ " return front\n",
+ "\n",
+ "def my_del(front):\n",
+ " tmp = node()\n",
+ " if(front == None):\n",
+ " print \"Queue Underflow\"\n",
+ " else:\n",
+ " tmp = front;\n",
+ " print \"Deleted item is \", tmp.info\n",
+ " front = front.link\n",
+ " return front\n",
+ "\n",
+ "def display(front):\n",
+ " ptr = node()\n",
+ " ptr = front;\n",
+ " if(front == None):\n",
+ " print \"Queue is empty\"\n",
+ " else:\n",
+ " print \"Queue is: \"\n",
+ " print \"Priority Item \"\n",
+ " while(ptr != None):\n",
+ " print \"%5d %5d \" %(ptr.priority,ptr.info)\n",
+ " ptr = ptr.link\n",
+ "\n",
+ "front = None\n",
+ "while(1):\n",
+ " print \"\\n1.Insert\"\n",
+ " print \"2.Delete\"\n",
+ " print \"3.Display\"\n",
+ " print \"4.Quit\"\n",
+ " print \"Enter your choice\",\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " front = insert(front);\n",
+ " elif choice == 2:\n",
+ " front = my_del(front);\n",
+ " elif choice == 3:\n",
+ " display(front)\n",
+ " elif choice == 4:\n",
+ " sys.exit()\n",
+ " else:\n",
+ " print \"Wrong choice\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Display\n",
+ "4.Quit\n",
+ "Enter your choice"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_of_Data_structures_using_C_and_C++/chapter6.ipynb b/Principles_of_Data_structures_using_C_and_C++/chapter6.ipynb
new file mode 100644
index 00000000..a11edf95
--- /dev/null
+++ b/Principles_of_Data_structures_using_C_and_C++/chapter6.ipynb
@@ -0,0 +1,1682 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:aba1be8ae42bb18059b4160131b71a6cc6c951a9fe76f13e7e039fc1531e880b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Sorting Techniques"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, page no. 155"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 20\n",
+ "arr = []\n",
+ "print \"Enter the number of elements : \",\n",
+ "n = int(raw_input())\n",
+ "print \"Enter %d elements: \" %n\n",
+ "for i in range(n):\n",
+ " arr.append(int(raw_input()))\n",
+ "print \"Unsorted list is : \"\n",
+ "for i in range(n):\n",
+ " print arr[i],\n",
+ "for i in range(n):\n",
+ " xchanges=0\n",
+ " for j in range(n-1-i):\n",
+ " if (arr[j] > arr[j+1]):\n",
+ " arr[j], arr[j+1] = arr[j+1],arr[j]\n",
+ " xchanges+=1\n",
+ " if (xchanges == 0):\n",
+ " break\n",
+ " print \"\\nAfter pass %d elements are : \" %(i+1)\n",
+ " for k in range(n):\n",
+ " print arr[k],\n",
+ "print \"\\nSorted list is : \"\n",
+ "for i in range(n):\n",
+ " print arr[i],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number of elements : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 3 elements: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Unsorted list is : \n",
+ "15 10 5 \n",
+ "After pass 1 elements are : \n",
+ "10 5 15 \n",
+ "After pass 2 elements are : \n",
+ "5 10 15 \n",
+ "Sorted list is : \n",
+ "5 10 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, page no. 157"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def bubblesort(a, n):\n",
+ " for i in range(1,n):\n",
+ " for j in range(0,n-1):\n",
+ " if (a[j] > a[j+1]):\n",
+ " a[j], a[j+1] = a[j+1], a[j]\n",
+ "\n",
+ "a = []\n",
+ "print \"\\nEnter the number of elements: \",\n",
+ "n = int(raw_input())\n",
+ "l = n;\n",
+ "print \"\\nEnter the elements: \",\n",
+ "while(l>0):\n",
+ " a.append(int(raw_input()))\n",
+ " l -= 1\n",
+ "bubblesort(a,n);\n",
+ "print \"\\nSorted array is: \",\n",
+ "l = 0\n",
+ "while(l < n):\n",
+ " print a[l],\n",
+ " l += 1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the number of elements: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the elements: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Sorted array is: 5 10 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, page no. 160"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = []\n",
+ "print \"\\nEnter the number of elements: \",\n",
+ "n = int(raw_input())\n",
+ "for i in range(n):\n",
+ " print \"Enter element %d: \" %(i+1),\n",
+ " arr.append(int(raw_input()))\n",
+ "print \"\\nUnsorted list is: \",\n",
+ "for i in range(n):\n",
+ " print arr[i],\n",
+ "\n",
+ "for i in range(0,n-1):\n",
+ " smallest = i\n",
+ " for k in range(i+1,n):\n",
+ " if (arr[smallest] > arr[k]):\n",
+ " smallest = k\n",
+ " if (i != smallest):\n",
+ " arr[i], arr[smallest] = arr[smallest], arr[i]\n",
+ " print \"\\nAfter pass %d elements are: \" %(i+1),\n",
+ " for j in range(n):\n",
+ " print arr[j],\n",
+ "\n",
+ "print \"\\nSorted list is: \",\n",
+ "for i in range(n):\n",
+ " print arr[i],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the number of elements: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 3: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Unsorted list is: 15 10 5 \n",
+ "After pass 1 elements are: 5 15 10 \n",
+ "After pass 2 elements are: 5 10 15 \n",
+ "Sorted list is: 5 10 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, page no. 161"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def selectionsort(a, n):\n",
+ " for i in range(n-1):\n",
+ " for j in range(i+1, n):\n",
+ " if (a[i]>a[j]):\n",
+ " a[i], a[j] = a[j],a[i]\n",
+ "\n",
+ "a = []\n",
+ "print \"\\nEnter the number of elements: \",\n",
+ "n = int(raw_input())\n",
+ "l = n\n",
+ "print \"\\nEnter the elements: \",\n",
+ "while(l > 0):\n",
+ " a.append(int(raw_input()))\n",
+ " l -= 1\n",
+ "selectionsort(a, n)\n",
+ "print \"\\nSorted array: \",\n",
+ "l = 0\n",
+ "while(l < n):\n",
+ " print a[l],\n",
+ " l += 1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the number of elements: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the elements: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Sorted array: 5 10 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, page no. 166"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = []\n",
+ "print \"\\nEnter the number of elements: \",\n",
+ "n = int(raw_input())\n",
+ "for i in range(n):\n",
+ " print \"Enter element %d: \" %(i+1),\n",
+ " arr.append(int(raw_input()))\n",
+ "print \"\\nUnsorted list is: \",\n",
+ "for i in range(n):\n",
+ " print arr[i],\n",
+ "for j in range (1, n):\n",
+ " k=arr[j]\n",
+ " i = j-1\n",
+ " while (i>=0):\n",
+ " if k < arr[i]:\n",
+ " arr[i+1]=arr[i]\n",
+ " i-=1\n",
+ " arr[i+1]=k\n",
+ " print \"\\nPass %d, Element inserted in proper place: %d \" %(j,k),\n",
+ " for i in range(n):\n",
+ " print arr[i],\n",
+ "\n",
+ "print \"\\nSorted list is: \",\n",
+ "for i in range(n):\n",
+ " print arr[i],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the number of elements: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 3: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Unsorted list is: 15 10 5 \n",
+ "Pass 1, Element inserted in proper place: 10 10 15 5 \n",
+ "Pass 2, Element inserted in proper place: 5 5 10 15 \n",
+ "Sorted list is: 5 10 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6, page no. 169"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = []\n",
+ "print \"Enter the number of elements : \",\n",
+ "n = int(raw_input())\n",
+ "for i in range(n):\n",
+ " print \"Enter element %d : \" %(i+1),\n",
+ " arr.append(int(raw_input()))\n",
+ "print \"Unsorted list is : \",\n",
+ "for i in range(n):\n",
+ " print arr[i],\n",
+ "print \"\\nEnter maximum increment (odd value) : \",\n",
+ "incr = int(raw_input())\n",
+ "\n",
+ "while(incr>=1):\n",
+ " for j in range(incr,n):\n",
+ " k = arr[j]\n",
+ " i = j-incr\n",
+ " while (i>=0 and k < arr[i]):\n",
+ " arr[i+incr] = arr[i]\n",
+ " i = i-incr\n",
+ " arr[i+incr] = k\n",
+ " print \"\\nIncrement=%d \" %incr\n",
+ " for i in range(n):\n",
+ " print arr[i],\n",
+ " incr = incr-2\n",
+ "print \"\\nSorted list is : \",\n",
+ "for i in range(n):\n",
+ " print arr[i],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number of elements : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 1 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 2 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 3 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Unsorted list is : 15 10 5 \n",
+ "Enter maximum increment (odd value) : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Increment=3 \n",
+ "15 10 5 \n",
+ "Increment=1 \n",
+ "5 10 15 \n",
+ "Sorted list is : 5 10 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7, page no. 173"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def display(arr, low, up):\n",
+ " for i in range(low, up):\n",
+ " print arr[i],\n",
+ " \n",
+ "def quick(arr, low, up):\n",
+ " left = low\n",
+ " right = up\n",
+ " piv = low\n",
+ " pivot_placed = False\n",
+ " print low, up\n",
+ " if (low>=up):\n",
+ " return\n",
+ " print \"\\nSublist: \",\n",
+ " display(arr,low,up)\n",
+ " while(pivot_placed == False):\n",
+ " while(arr[piv] <= arr[right] and piv != right):\n",
+ " right=right-1\n",
+ " if (piv==right):\n",
+ " pivot_placed = True\n",
+ " if (arr[piv] > arr[right]):\n",
+ " arr[piv], arr[right] = arr[right], arr[piv]\n",
+ " piv=right\n",
+ " while(arr[piv]>=arr[left] and left != piv):\n",
+ " left=left+1\n",
+ " if (piv==left):\n",
+ " pivot_placed = True\n",
+ " if (arr[piv] < arr[left]):\n",
+ " arr[piv], arr[left] = arr[left], arr[piv]\n",
+ " piv = left\n",
+ " print \"\\n-> Pivot Placed is %d -> \" %arr[piv]\n",
+ " display(arr,low,up)\n",
+ " quick(arr,low,piv-1)\n",
+ " quick(arr,piv+1,up)\n",
+ "\n",
+ "arr = []\n",
+ "print \"\\nEnter the number of elements : \",\n",
+ "n = int(raw_input())\n",
+ "for i in range(n):\n",
+ " print \"Enter element %d: \" %(i+1),\n",
+ " arr.append(int(raw_input()))\n",
+ "print \"\\nUnsorted list: \",\n",
+ "display(arr, 0, n)\n",
+ "quick(arr,0, n-1)\n",
+ "print \"\\nSorted List: \",\n",
+ "display(arr, 0, n)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the number of elements : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 3: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Unsorted list: 15 10 5 0 2\n",
+ "\n",
+ "Sublist: 15 10 \n",
+ "-> Pivot Placed is 15 -> \n",
+ "5 10 0 1\n",
+ "\n",
+ "Sublist: 5 \n",
+ "-> Pivot Placed is 5 -> \n",
+ "5 0 -1\n",
+ "1 1\n",
+ "3 2\n",
+ "\n",
+ "Sorted List: 5 10 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8, page no. 177"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr1 = []\n",
+ "arr2 = []\n",
+ "arr3 = []\n",
+ "print \"\\nEnter the number of elements in list1: \", \n",
+ "max1 = int(raw_input())\n",
+ "print \"\\nTake the elements in sorted order \\n\",\n",
+ "for i in range(max1):\n",
+ " print \"Enter element %d : \" %(i+1),\n",
+ " arr1.append(int(raw_input()))\n",
+ "print \"\\nEnter the number of elements in list2: \"\n",
+ "max2 = int(raw_input())\n",
+ "print \"\\nTake the elements in sorted order :\\n\"\n",
+ "for i in range(max2):\n",
+ " print \"Enter element %d: \"%(i+1),\n",
+ " arr2.append(int(raw_input()))\n",
+ "i = 0\n",
+ "j = 0\n",
+ "while((i < max1) and (j < max2)):\n",
+ " if (arr1[i] < arr2[j]):\n",
+ " arr3.append(arr1[i])\n",
+ " i += 1\n",
+ " else:\n",
+ " arr3.append(arr2[j])\n",
+ " j += 1\n",
+ "while(i < max1):\n",
+ " arr3.append(arr1[i])\n",
+ " i += 1\n",
+ "while(j < max2):\n",
+ " arr3.append(arr2[j])\n",
+ " j += 1\n",
+ "print \"\\nList 1: \",\n",
+ "for i in range(max1):\n",
+ " print arr1[i],\n",
+ "print \"\\nList 2: \",\n",
+ "for i in range(max2):\n",
+ " print arr2[i],\n",
+ "print \"\\nMerged list: \"\n",
+ "for i in range(max1+max2):\n",
+ " print arr3[i],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the number of elements in list1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Take the elements in sorted order \n",
+ "Enter element 1 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 2 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the number of elements in list2: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Take the elements in sorted order :\n",
+ "\n",
+ "Enter element 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 3: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 4: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 5: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "List 1: 10 15 \n",
+ "List 2: 1 2 3 4 5 \n",
+ "Merged list: \n",
+ "1 2 3 4 5 10 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9, page no. 179"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = []\n",
+ "temp = []\n",
+ "\n",
+ "print \"\\nEnter the number of elements: \",\n",
+ "n = int(raw_input())\n",
+ "for i in range(n):\n",
+ " print \"Enter element %d: \" %(i+1),\n",
+ " arr.append(int(raw_input()))\n",
+ "print \"\\nUnsorted list is: \",\n",
+ "for i in range(n):\n",
+ " print arr[i],\n",
+ "\n",
+ "size = 1\n",
+ "\n",
+ "while size < n:\n",
+ " l1 = 0\n",
+ " k = 0\n",
+ " while(l1+size<n):\n",
+ " h1 = l1 + (size - 1)\n",
+ " l2 = h1 + 1\n",
+ " h2 = l2 + (size - 1)\n",
+ " if (h2>=n):\n",
+ " h2 = n-1\n",
+ " i=l1\n",
+ " j=l2\n",
+ " while(i<=h1 and j<=h2 ):\n",
+ " if (arr[i]<=arr[j]):\n",
+ " temp.append(arr[i])\n",
+ " i += 1\n",
+ " else:\n",
+ " temp.append(arr[j])\n",
+ " j += 1\n",
+ " while(i<=h1):\n",
+ " temp.append(arr[i])\n",
+ " i += 1\n",
+ " while(j<=h2):\n",
+ " temp.append(arr[j])\n",
+ " j += 1\n",
+ " l1 = h2+1\n",
+ " for i in range (l1, n):\n",
+ " temp.append(arr[i])\n",
+ " for i in range(0):\n",
+ " arr[i]=temp[i]\n",
+ " print \"\\nSize=%d \\nElements are: \" %size\n",
+ " for i in range(n):\n",
+ " print arr[i],\n",
+ " size = size * 2\n",
+ "arr = temp \n",
+ "print \"\\nSorted list is:\",\n",
+ "for i in range(n):\n",
+ " print arr[i],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the number of elements: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 3: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Unsorted list is: 15 10 5 \n",
+ "Size=1 \n",
+ "Elements are: \n",
+ "15 10 5 \n",
+ "Size=2 \n",
+ "Elements are: \n",
+ "15 10 5 \n",
+ "Sorted list is: 10 15 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10, page no. 181"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import zeros\n",
+ "array = []\n",
+ "def merge(low, mid, high):\n",
+ " global array\n",
+ " temp = zeros(len(array))\n",
+ " i = low;\n",
+ " j = mid +1 ;\n",
+ " k = low ;\n",
+ " print array\n",
+ " while((i<=mid) and (j<=high)):\n",
+ " if (array[i]<=array[j]):\n",
+ " temp[k] = array[i]\n",
+ " k += 1\n",
+ " i += 1\n",
+ " else:\n",
+ " temp[k] = array[j]\n",
+ " k += 1\n",
+ " j += 1\n",
+ " while(i<=mid):\n",
+ " temp[k] = array[i]\n",
+ " k += 1\n",
+ " i += 1\n",
+ " while(j<=high):\n",
+ " temp[k] = array[j]\n",
+ " k += 1\n",
+ " j += 1\n",
+ "\n",
+ " for i in range(low,high+1):\n",
+ " array[i] = temp[i]\n",
+ "\n",
+ "def merge_sort(low, high):\n",
+ " if (low != high):\n",
+ " mid = (low+high)/2;\n",
+ " merge_sort(low , mid)\n",
+ " merge_sort(mid+1, high)\n",
+ " merge(low, mid, high)\n",
+ " \n",
+ "print \"\\nEnter the number of elements: \"\n",
+ "n = int(raw_input())\n",
+ "for i in range(n):\n",
+ " print \"Enter element %d: \" %(i+1),\n",
+ " array.append(int(raw_input()))\n",
+ "print \"\\nUnsorted list is: \",\n",
+ "for i in range(n):\n",
+ " print array[i],\n",
+ "merge_sort(0, n-1)\n",
+ "print \"\\nSorted list is :\",\n",
+ "for i in range(n):\n",
+ " print array[i],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the number of elements: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter element 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 3: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Unsorted list is: 15 10 5 [15, 10, 5]\n",
+ "[10.0, 15.0, 5]\n",
+ "\n",
+ "Sorted list is : 5.0 10.0 15.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11, page no. 184"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import zeros\n",
+ "class node:\n",
+ " def __init__(self, info=None, link=None):\n",
+ " self.info = info\n",
+ " self.link = link\n",
+ "\n",
+ "start = None\n",
+ "\n",
+ "\n",
+ "def display():\n",
+ " global start\n",
+ " p = start\n",
+ " while(p != None):\n",
+ " print p.info,\n",
+ " p = p.link\n",
+ " print \"\"\n",
+ " \n",
+ "def large_dig(p):\n",
+ " large = 0\n",
+ " ndig = 0\n",
+ " while (p!=None):\n",
+ " if (p.info > large):\n",
+ " large = p.info\n",
+ " p = p.link\n",
+ " print \"\\nLargest Element is %d\" %large\n",
+ " while (large!=0):\n",
+ " ndig += 1\n",
+ " large = large/10\n",
+ " print \"\\nNumber of digits in it are %d \" %ndig\n",
+ " return ndig\n",
+ "\n",
+ "def digit(number, k):\n",
+ " digit = 0\n",
+ " for i in range (1, k+1):\n",
+ " digit = number % 10 ;\n",
+ " number = number /10 ;\n",
+ " return digit\n",
+ "\n",
+ "def radix_sort():\n",
+ " global start\n",
+ " rear = []\n",
+ " front = []\n",
+ " least_sig=1;\n",
+ " most_sig=large_dig(start);\n",
+ " for k in range(least_sig, most_sig+1):\n",
+ " print \"\\nPASS %d : Examining %dth digit from right\" %(k,k)\n",
+ " for i in range(0,10):\n",
+ " rear.append(None)\n",
+ " front.append(None)\n",
+ " maxdig=0\n",
+ " mindig=9\n",
+ " p = start\n",
+ " while(p!=None):\n",
+ " dig = digit(p.info, k)\n",
+ " if (dig>maxdig):\n",
+ " maxdig=dig\n",
+ " if (dig<mindig):\n",
+ " mindig=dig \n",
+ " if (front[dig] == None):\n",
+ " front[dig] = p\n",
+ " else:\n",
+ " rear[dig].link = p\n",
+ " rear[dig] = p\n",
+ " p = p.link\n",
+ " print \"\\nmindig=%d maxdig=%d\\n\" %(mindig, maxdig)\n",
+ " start = front[mindig]\n",
+ " for i in range(mindig,maxdig):\n",
+ " if (rear[i+1]!=None):\n",
+ " rear[i].link = front[i+1]\n",
+ " else:\n",
+ " rear[i+1]=rear[i];\n",
+ " rear[maxdig].link = None\n",
+ " print \"\\nNew list : \",\n",
+ " display()\n",
+ "\n",
+ "\n",
+ "q = node()\n",
+ "print \"Enter the number of elements in the list: \",\n",
+ "n = int(raw_input())\n",
+ "for i in range(n):\n",
+ " print \"Enter element %d: \" %(i+1),\n",
+ " item = int(raw_input())\n",
+ " tmp = node()\n",
+ " tmp.info = item\n",
+ " tmp.link = None\n",
+ " if (start == None):\n",
+ " start = tmp\n",
+ " print start.info\n",
+ " else:\n",
+ " q = start\n",
+ " while(q.link != None):\n",
+ " q = q.link\n",
+ " print q.info\n",
+ " q.link = tmp\n",
+ "print \"\\nUnsorted list is: \",\n",
+ "display()\n",
+ "radix_sort()\n",
+ "print \"\\nSorted list is: \"\n",
+ "display ()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number of elements in the list: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 15\n",
+ "Enter element 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 3: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 10\n",
+ "\n",
+ "Unsorted list is: 15 10 12 \n",
+ "\n",
+ "Largest Element is 15\n",
+ "\n",
+ "Number of digits in it are 2 \n",
+ "\n",
+ "PASS 1 : Examining 1th digit from right\n",
+ "\n",
+ "mindig=0 maxdig=5\n",
+ "\n",
+ "\n",
+ "New list : 10 12 15 \n",
+ "\n",
+ "PASS 2 : Examining 2th digit from right\n",
+ "\n",
+ "mindig=1 maxdig=1\n",
+ "\n",
+ "\n",
+ "New list : 10 12 15 \n",
+ "\n",
+ "Sorted list is: \n",
+ "10 12 15 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12, Page no. 197"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = []\n",
+ "n = None\n",
+ "\n",
+ "def display():\n",
+ " global n\n",
+ " for i in range(n):\n",
+ " print arr[i],\n",
+ "\n",
+ "\n",
+ "def insert(num, loc):\n",
+ " while(loc>0):\n",
+ " par = (loc-1)/2;\n",
+ " if (num<=arr[par]):\n",
+ " arr[loc] = num\n",
+ " return\n",
+ " arr[loc] = arr[par]\n",
+ " loc=par\n",
+ " arr[0] = num\n",
+ "\n",
+ "def create_heap():\n",
+ " global n\n",
+ " for i in range(n):\n",
+ " arr.append(i)\n",
+ "\n",
+ "def del_root(last):\n",
+ " i=0\n",
+ " arr[i], arr[last] = arr[last], arr[i]\n",
+ " left = 2*i+1\n",
+ " right = 2*i+2\n",
+ " while(right<last):\n",
+ " if (arr[i]>=arr[left] and arr[i]>=arr[right]):\n",
+ " return\n",
+ " if (arr[right]<=arr[left]):\n",
+ " arr[i], arr[left] = arr[left], arr[i]\n",
+ " else:\n",
+ " arr[i], arr[right] = arr[right], arr[i]\n",
+ " i=right;\n",
+ " left=2*i+1;\n",
+ " right=2*i+2;\n",
+ " if (left==last-1 and arr[i]<arr[left]):\n",
+ " arr[i], arr[left] = arr[left], arr[i]\n",
+ "\n",
+ "def heap_sort():\n",
+ " global n\n",
+ " last = n-1\n",
+ " while(last>0):\n",
+ " del_root(last)\n",
+ " last -= 1\n",
+ "\n",
+ "print \"Enter number of elements: \",\n",
+ "n = int(raw_input())\n",
+ "for i in range(n):\n",
+ " print \"Enter element %d: \" %(i+1),\n",
+ " arr.append(int(raw_input()))\n",
+ "print \"\\nEntered list is: \",\n",
+ "display()\n",
+ "create_heap()\n",
+ "print \"\\nHeap is: \",\n",
+ "display()\n",
+ "heap_sort()\n",
+ "print \"\\nSorted list is: \",\n",
+ "display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of elements: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 3: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Entered list is: 15 10 5 \n",
+ "Heap is: 15 10 5 \n",
+ "Sorted list is: 5 10 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_of_Data_structures_using_C_and_C++/chapter7.ipynb b/Principles_of_Data_structures_using_C_and_C++/chapter7.ipynb
new file mode 100644
index 00000000..94558c7a
--- /dev/null
+++ b/Principles_of_Data_structures_using_C_and_C++/chapter7.ipynb
@@ -0,0 +1,688 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c26c5d09848ed75dce1b0018e66d619a73d2133d6f4cf9d9908ab7addd4dbb8f"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Searchin & Hashing"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, page no. 208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "arr = []\n",
+ "opt = 'y'\n",
+ "print \"nHow many elements you want to enter in the array: \",\n",
+ "n = int(raw_input())\n",
+ "for i in range(n):\n",
+ " print \"Enter element %d: \" %(i+1),\n",
+ " arr.append(int(raw_input()))\n",
+ "print \"\\n\\nPress any key to continue...\"\n",
+ "raw_input()\n",
+ "\n",
+ "while (1):\n",
+ " if opt == 'Y' or opt == 'y':\n",
+ " print \"Enter the element to be searched: \",\n",
+ " item = int(raw_input())\n",
+ " found = False\n",
+ " for i in range(n):\n",
+ " if (item == arr[i]):\n",
+ " print \"\\n%d found at position %d\" %(item,(i+1))\n",
+ " found = True\n",
+ " break\n",
+ " if not found:\n",
+ " print \"Item %d not found in array\" %item\n",
+ " print \"Press (Y/y) to continue: \",\n",
+ " opt = raw_input()\n",
+ " else:\n",
+ " sys.exit()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "nHow many elements you want to enter in the array: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 3: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Press any key to continue...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element to be searched: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "5 found at position 3\n",
+ "Press (Y/y) to continue: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, page no. 211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "arr = []\n",
+ "print \"How many elements you want to enter in the array ?: \",\n",
+ "n = int(raw_input())\n",
+ "for i in range(n):\n",
+ " print \"Enter element %d: \" %(i+1),\n",
+ " arr.append(int(raw_input()))\n",
+ "print \"\\nPress any key to continue...\",\n",
+ "raw_input()\n",
+ "opt = 'y'\n",
+ "while(1):\n",
+ " if opt == \"Y\" or opt == \"y\":\n",
+ " print \"Enter the element to be searched: \",\n",
+ " item = int(raw_input())\n",
+ " start = 0\n",
+ " end = n - 1\n",
+ " middle = (start + end)/2\n",
+ " while(item != arr[middle] and start <= end):\n",
+ " if (item > arr[middle]):\n",
+ " start = middle+1\n",
+ " else:\n",
+ " end = middle-1\n",
+ " middle = (start+end)/2\n",
+ " if (item==arr[middle]):\n",
+ " print \"%d found at position %d\" %(item,(middle + 1));\n",
+ " if (start>end):\n",
+ " print \"%d not found in array\" %item\n",
+ " print \"Press (Y/y) to continue: \",\n",
+ " opt = raw_input()\n",
+ " else:\n",
+ " sys.exit()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " How many elements you want to enter in the array ?: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 3: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Press any key to continue..."
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the element to be searched: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 10 found at position 2\n",
+ "Press (Y/y) to continue: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, page no. 215"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class interpolation:\n",
+ " def InterSearch(self, arr, no):\n",
+ " Low = 0\n",
+ " High = no - 1\n",
+ " print \"Enter the Number to be searched: \",\n",
+ " key = int(raw_input())\n",
+ " while(Low < High):\n",
+ " Mid = (Low+(High-Low)) * ((key-arr[Low])/(arr[High]-arr[Low]))\n",
+ " if (key < arr[Mid]):\n",
+ " High = Mid-1\n",
+ " elif (key > arr[Mid]):\n",
+ " Low = Mid+1;\n",
+ " else:\n",
+ " print \"The key \", key, \" is found at the location \", Mid\n",
+ " return\n",
+ " print \"\\nThe Key \" , key, \" is NOT found\"\n",
+ "\n",
+ "\n",
+ "ob = interpolation()\n",
+ "print \"Enter the number of elements: \",\n",
+ "n = int(raw_input())\n",
+ "a = []\n",
+ "for i in range(n):\n",
+ " print \"Enter element %d: \" %(i+1),\n",
+ " a.append(int(raw_input()))\n",
+ "b = a\n",
+ "ob.InterSearch(b,n);\n",
+ "print \"Press any key to continue...\",\n",
+ "raw_input()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number of elements: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter element 3: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the Number to be searched: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The key 15 is found at the location 2\n",
+ "Press any key to continue..."
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 5,
+ "text": [
+ "''"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, page no. 217"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def fib(n):\n",
+ " f1 = 0\n",
+ " f2 = 1\n",
+ " for i in range(n):\n",
+ " temp = f2\n",
+ " f2 = (f1+f2)\n",
+ " f1 = temp\n",
+ " return f2\n",
+ "\n",
+ "def fibonacci_search(lst, n, item):\n",
+ " j = 1\n",
+ " while(fib(j)<n):\n",
+ " f1 = fib(j-2)\n",
+ " j += 1\n",
+ " f2 = fib(j-3)\n",
+ " mid = n-(f1+1);\n",
+ " while (item != lst[mid]):\n",
+ " if(mid<0 or item > lst[mid]):\n",
+ " if (f1==1):\n",
+ " return -1\n",
+ " mid = mid+f2\n",
+ " f1 = f1-f2\n",
+ " f2 = f2-f1\n",
+ " else:\n",
+ " if (f2==0):\n",
+ " return -1\n",
+ " mid = mid-f2\n",
+ " t = f1-f2\n",
+ " f1 = f2\n",
+ " f2 = t\n",
+ " return mid\n",
+ " \n",
+ "lst = []\n",
+ "print \"Enter the total number of list: \",\n",
+ "n = int(raw_input())\n",
+ "print \"Enter the elements in the list \"\n",
+ "for i in range(n):\n",
+ " print \"Input number \", i+1, \": \",\n",
+ " lst.append(int(raw_input()))\n",
+ "print \"Enter the number to be searched: \",\n",
+ "item = int(raw_input())\n",
+ "loc = fibonacci_search(lst, n, item)\n",
+ "if (loc != -1):\n",
+ " print \"The number is in the list...\"\n",
+ "else:\n",
+ " print \"The number is not in the list...\"\n",
+ "raw_input()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the total number of list: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the elements in the list \n",
+ "Input number 1 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Input number 2 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Input number 3 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the number to be searched: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The number is in the list...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 6,
+ "text": [
+ "''"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_of_Data_structures_using_C_and_C++/chapter8.ipynb b/Principles_of_Data_structures_using_C_and_C++/chapter8.ipynb
new file mode 100644
index 00000000..fd46edee
--- /dev/null
+++ b/Principles_of_Data_structures_using_C_and_C++/chapter8.ipynb
@@ -0,0 +1,1181 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c27bccc21274b298c9a4e263b1bbc13e122672406a37889e0a2049a62b1aa98a"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: The Trees"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, page no. 238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class node:\n",
+ " n = 0\n",
+ " keys = []\n",
+ " p = []\n",
+ "\n",
+ "root = None\n",
+ "\n",
+ "class KeyStatus:\n",
+ " Duplicate = 0\n",
+ " SearchFailure =1\n",
+ " Success = 2 \n",
+ " InsertIt = 3\n",
+ " LessKeys = 4\n",
+ "\n",
+ "def insert(key):\n",
+ " global root\n",
+ " newnode = node()\n",
+ " upKey = 0\n",
+ " value, upKey, newnode = ins(root, key, upKey, newnode)\n",
+ " if (value == KeyStatus.Duplicate):\n",
+ " print \"Key already available\"\n",
+ " if (value == KeyStatus.InsertIt):\n",
+ " uproot = root\n",
+ " root = node()\n",
+ " root.n = 1\n",
+ " root.keys.append(upKey)\n",
+ " root.p.append(uproot)\n",
+ " root.p.append(newnode)\n",
+ "\n",
+ "def ins(ptr, key, upKey, newnode):\n",
+ " newPtr = node()\n",
+ " lastPtr = node()\n",
+ " newKey = 0\n",
+ " if (ptr == None):\n",
+ " newnode = None\n",
+ " upKey = key\n",
+ " return KeyStatus.InsertIt, upKey, newnode\n",
+ " n = ptr.n\n",
+ " pos = searchPos(key, ptr.keys, n)\n",
+ " print pos\n",
+ " if (pos < n and key == ptr.keys[pos]):\n",
+ " return KeyStatus.Duplicate, upKey, newnode\n",
+ " value, newKey, newPtr = ins(ptr.p[pos], key, newKey, newPtr);\n",
+ " if (value != KeyStatus.InsertIt):\n",
+ " return value\n",
+ " if(n < (5-1)):\n",
+ " pos = searchPos(newKey, ptr.keys, n)\n",
+ " for i in range(pos, n, -1):\n",
+ " ptr.keys[i] = ptr.keys[i-1]\n",
+ " ptr.p.append(ptr.p[i])\n",
+ " ptr.keys.append(newKey)\n",
+ " ptr.p.append(newPtr)\n",
+ " ptr.n += 1\n",
+ " return KeyStatus.Success, upKey, newnode\n",
+ " if (pos == 5 - 1):\n",
+ " lastKey = newKey;\n",
+ " lastPtr = newPtr;\n",
+ " else:\n",
+ " lastKey = ptr.keys[5-2];\n",
+ " lastPtr = ptr.p[5-1];\n",
+ " for i in range(pos, 5-2, -1):\n",
+ " ptr.keys[i] = ptr.keys[i-1]\n",
+ " ptr.p.append(ptr.p[i])\n",
+ " ptr.keys.append(newKey)\n",
+ " ptr.p.append(newPtr)\n",
+ " splitPos = (5 - 1)/2\n",
+ " upKey = ptr.keys[splitPos]\n",
+ " newnode = node()\n",
+ " ptr.n = splitPos\n",
+ " newnode.n = 5-1-splitPos\n",
+ " for i in range(newnode.n):\n",
+ " newnode.p[i] = ptr.p[i + splitPos + 1]\n",
+ " if(i < newnode.n - 1):\n",
+ " newnode.keys[i] = ptr.keys[i + splitPos + 1]\n",
+ " else:\n",
+ " newnode.keys[i] = lastKey\n",
+ " newnode.p[newnode.n] = lastPtr\n",
+ " return KeyStatus.InsertIt, upKey, newnode\n",
+ "\n",
+ "def display(ptr, blanks):\n",
+ " if (ptr):\n",
+ " for i in range(blanks):\n",
+ " print \" \"\n",
+ " for i in range(ptr.n):\n",
+ " print \"%d \" %ptr.keys[i],\n",
+ " print \"\\n\"\n",
+ " for i in range(ptr.n):\n",
+ " display(ptr.p[i], blanks+10)\n",
+ "\n",
+ "def searchPos(key, key_arr, n):\n",
+ " pos = 0\n",
+ " while(pos < n and key > key_arr[pos]):\n",
+ " pos += 1\n",
+ " return pos\n",
+ "\n",
+ "def search(key):\n",
+ " global root\n",
+ " ptr = root\n",
+ " print \"Search path: \"\n",
+ " while(ptr):\n",
+ " n = ptr.n\n",
+ " for i in range(ptr.n):\n",
+ " print \"%d\" %ptr.keys[i]\n",
+ " print \"\\n\"\n",
+ " pos = searchPos(key, ptr.keys, n);\n",
+ " if (pos < n and key == ptr.keys[pos]):\n",
+ " print \"\\nKey %d found in position %d of last dispalyed node\\n\" %(key,i)\n",
+ " return\n",
+ " ptr = ptr.p[pos]\n",
+ " print \"Key %d is not available\\n\" %key\n",
+ "\n",
+ "def my_del(ptr, key):\n",
+ " p = node()\n",
+ " lptr = node()\n",
+ " rptr = node()\n",
+ " if(ptr == None):\n",
+ " return SearchFailure;\n",
+ " n=ptr.n\n",
+ " key_arr = ptr.keys\n",
+ " p = ptr.p\n",
+ " min = (5 - 1)/2\n",
+ " pos = searchPos(key, key_arr, n)\n",
+ " if(p[0] == None):\n",
+ " if (pos == n or key < key_arr[pos]):\n",
+ " return KeyStatus.SearchFailure\n",
+ " for i in range(pos+1, n):\n",
+ " key_arr[i-1] = key_arr[i]\n",
+ " p[i] = p[i+1]\n",
+ " ptr.n -= 1\n",
+ " temp = 0\n",
+ " if(ptr == root):\n",
+ " temp = 1\n",
+ " else:\n",
+ " temp = min\n",
+ " if(ptr.n >= temp):\n",
+ " return KeyStatus.Success\n",
+ " else:\n",
+ " return KeyStatus.LessKeys\n",
+ " if (pos < n and key == key_arr[pos]):\n",
+ " qp = p[pos]\n",
+ " while(True):\n",
+ " nkey = qp.n\n",
+ " qp1 = qp.p[nkey]\n",
+ " if (qp1 == None):\n",
+ " break\n",
+ " qp = qp1\n",
+ " key_arr[pos] = qp.keys[nkey-1]\n",
+ " qp.keys[nkey - 1] = key\n",
+ " value = my_del(p[pos], key)\n",
+ " if (value != KeyStatus.LessKeys):\n",
+ " return value\n",
+ " if (pos > 0 and p[pos-1].n > min):\n",
+ " pivot = pos - 1\n",
+ " lptr = p[pivot]\n",
+ " rptr = p[pos]\n",
+ " rptr.p[rptr.n + 1] = rptr.p[rptr.n]\n",
+ " for i in range(0, ptr.n, -1):\n",
+ " rptr.keys[i] = rptr.keys[i-1];\n",
+ " rptr.p[i] = rptr.p[i-1];\n",
+ " rptr.n += 1\n",
+ " rptr.keys[0] = key_arr[pivot]\n",
+ " rptr.p[0] = lptr.p[lptr.n]\n",
+ " key_arr[pivot] = lptr .keys[--lptr.n];\n",
+ " return KeyStatus.Success\n",
+ " if (pos<n and p[pos+1].n > min):\n",
+ " pivot = pos\n",
+ " lptr = p[pivot]\n",
+ " rptr = p[pivot+1]\n",
+ " lptr.keys[lptr.n] = key_arr[pivot]\n",
+ " lptr.p[lptr.n + 1] = rptr.p[0]\n",
+ " key_arr[pivot] = rptr.keys[0]\n",
+ " lptr.n += 1\n",
+ " rptr.n -= 1\n",
+ " for i in range(rptr.n):\n",
+ " rptr.keys[i] = rptr.keys[i+1]\n",
+ " rptr.p[i] = rptr.p[i+1]\n",
+ " rptr .p[rptr.n] = rptr.p[rptr.n + 1]\n",
+ " return KeyStatus.Success\n",
+ " if(pos == n):\n",
+ " pivot = pos-1\n",
+ " else:\n",
+ " pivot = pos\n",
+ " lptr = p[pivot]\n",
+ " rptr = p[pivot+1]\n",
+ " lptr.keys[lptr.n] = key_arr[pivot]\n",
+ " lptr.p[lptr.n + 1] = rptr.p[0]\n",
+ " for i in range(rptr.n):\n",
+ " lptr.keys[lptr .n + 1 + i] = rptr.keys[i]\n",
+ " lptr.p[lptr.n + 2 + i] = rptr.p[i+1]\n",
+ " lptr.n = lptr.n + rptr.n +1\n",
+ " for i in range(pos+1, n):\n",
+ " key_arr[i-1] = key_arr[i]\n",
+ " p[i] = p[i+1]\n",
+ " ptr -= 1\n",
+ " temp = 0\n",
+ " if(ptr == root):\n",
+ " temp = 1\n",
+ " else:\n",
+ " temp = min\n",
+ " if(ptr.n >= temp):\n",
+ " return KeyStatus.Success\n",
+ " else:\n",
+ " return KeyStatus.LessKeys\n",
+ "\n",
+ "def DelNode(key):\n",
+ " global root\n",
+ " uproot = node()\n",
+ " value = my_del(root,key)\n",
+ " if value == KeyStatus.SearchFailure:\n",
+ " print \"Key %d is not available\" %key\n",
+ " return\n",
+ " if value == KeyStatus.LessKeys:\n",
+ " uproot = root\n",
+ " root = root.p[0]\n",
+ " return\n",
+ "\n",
+ "\n",
+ "while(True):\n",
+ " print \"1.Insert\"\n",
+ " print \"2.Delete\"\n",
+ " print \"3.Search\"\n",
+ " print \"4.Display\"\n",
+ " print \"5.Quit\"\n",
+ " print \"Enter your choice : \",\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " print \"\\nEnter the key : \",\n",
+ " key = int(raw_input())\n",
+ " insert(key)\n",
+ " elif choice == 2:\n",
+ " print \"\\nEnter the key : \",\n",
+ " key = int(raw_input())\n",
+ " DelNode(key)\n",
+ " elif choice == 3:\n",
+ " print \"\\nEnter the key : \",\n",
+ " key = int(raw_input())\n",
+ " search(key)\n",
+ " elif choice == 4:\n",
+ " print \"\\nBtree is :\\n\"\n",
+ " display(root,0)\n",
+ " elif choice == 5:\n",
+ " import sys\n",
+ " sys.exit()\n",
+ " else:\n",
+ " print \"Wrong choice\"\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Search\n",
+ "4.Display\n",
+ "5.Quit\n",
+ "Enter your choice : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the key : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1.Insert\n",
+ "2.Delete\n",
+ "3.Search\n",
+ "4.Display\n",
+ "5.Quit\n",
+ "Enter your choice : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter the key : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1\n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Search\n",
+ "4.Display\n",
+ "5.Quit\n",
+ "Enter your choice : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Btree is :\n",
+ "\n",
+ "5 10 \n",
+ "\n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Search\n",
+ "4.Display\n",
+ "5.Quit\n",
+ "Enter your choice : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, page no. 250"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def preorder(p):\n",
+ " stack = []\n",
+ " top = -1\n",
+ " if(p != None):\n",
+ " print p.info\n",
+ " if(p.rchild != None):\n",
+ " top += 1\n",
+ " stack[top] = p.rchild\n",
+ " p = p.lchild\n",
+ " while(top >= -1):\n",
+ " while ( p!= None):\n",
+ " print p.data\n",
+ " if(p.rchild != None):\n",
+ " top += 1\n",
+ " stack[top] = p.rchild\n",
+ " p = p.lchild\n",
+ " p = stack[top]\n",
+ " top -= 1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Eample 3, page no. 253"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def inorder(p):\n",
+ " stack = []\n",
+ " top = -1;\n",
+ " if(p != None):\n",
+ " top += 1\n",
+ " stack[top] = p\n",
+ " p = p.lchild\n",
+ " while(top >= 0):\n",
+ " while ( p!= None):\n",
+ " top += 1\n",
+ " stack[top] = p\n",
+ " p = p.lchild\n",
+ " p = stack[top]\n",
+ " top -= 1\n",
+ " print p.data\n",
+ " p = p.rchild\n",
+ " if ( p != None):\n",
+ " top += 1\n",
+ " stack[top] = p\n",
+ " p = p.lchild"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, page no. 257"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def postorder(p):\n",
+ " stack = []\n",
+ " sig = 0\n",
+ " sign = []\n",
+ " top = -1\n",
+ " if(p != None):\n",
+ " top += 1\n",
+ " stack[top] = p\n",
+ " sign[top] = 1\n",
+ " if(p.rchild != None):\n",
+ " top += 1\n",
+ " stack[top] = p.rchild\n",
+ " sign[top] = -1\n",
+ " p = p.lchild\n",
+ " while(top >= 0):\n",
+ " while(p != None):\n",
+ " top += 1\n",
+ " stack[top] = p\n",
+ " sign[top] = 1\n",
+ " if(p.rchild != None):\n",
+ " top += 1\n",
+ " stack[top] = p.rchild\n",
+ " sign[top] = -1\n",
+ " p = p.lchild\n",
+ " p = stack[top]\n",
+ " sig = sign[top]\n",
+ " top -= 1\n",
+ " while((sig > 0) and (top >= -1)):\n",
+ " print p.info\n",
+ " p = stack[top]\n",
+ " sig = sign[top]\n",
+ " top -= 1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, page no. 264"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class BST:\n",
+ " class node:\n",
+ " info = None\n",
+ " lchild = None\n",
+ " rchild = None\n",
+ " def __init__(self):\n",
+ " self.root = self.node()\n",
+ "\n",
+ " def find(self, item, par, loc):\n",
+ " ptr = self.node()\n",
+ " ptrsave = self.node()\n",
+ " if(self.root==None):\n",
+ " loc = None\n",
+ " par = None\n",
+ " return\n",
+ " if(item == self.root.info):\n",
+ " loc = self.root\n",
+ " par = None\n",
+ " return\n",
+ " if(item < self.root.info):\n",
+ " ptr = self.root.lchild\n",
+ " else:\n",
+ " ptr = self.root.rchild\n",
+ " ptrsave = self.root\n",
+ " while(ptr!=None):\n",
+ " if(item == ptr.info):\n",
+ " loc = ptr\n",
+ " par = ptrsave\n",
+ " return\n",
+ " ptrsave = ptr\n",
+ " if(item<ptr.info):\n",
+ " ptr = ptr.lchild\n",
+ " else:\n",
+ " ptr = ptr.rchild\n",
+ " loc = None\n",
+ " par = ptrsave\n",
+ " return par,loc\n",
+ " \n",
+ " def case_a(self, par, loc):\n",
+ " if(par == None):\n",
+ " self.root = None\n",
+ " else:\n",
+ " if(loc == par.lchild):\n",
+ " par.lchild = None\n",
+ " else:\n",
+ " par.rchild = None\n",
+ " \n",
+ " def case_b(self, par, loc):\n",
+ " child = self.node()\n",
+ " if(loc.lchild != None):\n",
+ " chile = loc.lchild\n",
+ " else:\n",
+ " child = loc.rchild\n",
+ " if(par == None):\n",
+ " self.root = None\n",
+ " else:\n",
+ " if(loc == par.lchild):\n",
+ " par.lchild = child\n",
+ " else:\n",
+ " par.rchid = child\n",
+ " \n",
+ " def case_c(self, par, loc):\n",
+ " ptr = self.node()\n",
+ " ptrsave = self.node()\n",
+ " suc = self.node()\n",
+ " parsuc = self.node()\n",
+ " ptrsave = loc\n",
+ " ptr = loc.lchild\n",
+ " while(ptr.lchild != None):\n",
+ " ptrsave = ptr\n",
+ " ptr = ptr.lchild\n",
+ " suc = ptr\n",
+ " parsuc = ptrsave\n",
+ " if(suc.lchild == None and suc.rchild == None):\n",
+ " self.case_a(parsuc, suc)\n",
+ " else:\n",
+ " self.case_b(parsuc, suc)\n",
+ " if(par==None):\n",
+ " self.root = suc\n",
+ " else: \n",
+ " if(loc==par.lchild):\n",
+ " par.lchild = suc\n",
+ " else:\n",
+ " par.rchild = suc\n",
+ " suc.lchild = loc.lchild\n",
+ " suc.rchild = loc.rchild\n",
+ " \n",
+ " def insert(self, item):\n",
+ " tmp = self.node()\n",
+ " parent = self.node()\n",
+ " location = self.node()\n",
+ " parent,location = self.find(item, parent, location)\n",
+ " if(location != None):\n",
+ " print \"Item already present\"\n",
+ " raw_input()\n",
+ " return\n",
+ " tmp.info = item\n",
+ " tmp.lchild = None\n",
+ " tmp.rchild = None\n",
+ " if(parent.info==None):\n",
+ " self.root = tmp\n",
+ " else:\n",
+ " if(item<parent.info):\n",
+ " parent.lchild=tmp\n",
+ " else:\n",
+ " parent.rchild=tmp\n",
+ " \n",
+ " def my_del(self, item):\n",
+ " parent = self.node()\n",
+ " location = self.node()\n",
+ " if(self.root==None):\n",
+ " print \"Tree is empty\"\n",
+ " raw_input()\n",
+ " return\n",
+ " self.find(item, parent, location)\n",
+ " if(location==None):\n",
+ " print \"Item not present in tree\"\n",
+ " return\n",
+ " if(location.lchild==None and location.rchild==None):\n",
+ " self.case_a(parent,location)\n",
+ " if(location.lchild!=None and location.rchild==None):\n",
+ " self.case_b(parent,location)\n",
+ " if(location.lchild==None and location.rchild!=None):\n",
+ " self.case_b(parent,location)\n",
+ " if(location.lchild!=None and location.rchild!=None):\n",
+ " self.case_c(parent,location)\n",
+ " delete(location)\n",
+ " \n",
+ " def preorder(self, ptr):\n",
+ " if(self.root==None):\n",
+ " print \"Tree is empty\"\n",
+ " raw_input()\n",
+ " return\n",
+ " if(ptr!=None):\n",
+ " print ptr.info\n",
+ " self.preorder(ptr.lchild)\n",
+ " self.preorder(ptr.rchild)\n",
+ " \n",
+ " def inorder(self, ptr):\n",
+ " if(self.root==None):\n",
+ " print \"Tree is empty\"\n",
+ " raw_input()\n",
+ " return\n",
+ " if(ptr!=None):\n",
+ " self.inorder(ptr.lchild)\n",
+ " print ptr.info\n",
+ " self.inorder(ptr.rchild)\n",
+ " \n",
+ " def postorder(self, ptr):\n",
+ " if(self.root==None):\n",
+ " print \"Tree is empty\"\n",
+ " raw_input()\n",
+ " return\n",
+ " if(ptr!=None):\n",
+ " self.postorder(ptr.lchild)\n",
+ " self.postorder(ptr.rchild)\n",
+ " print ptr.info\n",
+ " \n",
+ " def display(self, ptr, level):\n",
+ " #print ptr.info\n",
+ " if (ptr!=None):\n",
+ " self.display(ptr.rchild, level+1);\n",
+ " for i in range(level):\n",
+ " print \" \"\n",
+ " print ptr.info\n",
+ " self.display(ptr.lchild, level+1)\n",
+ "\n",
+ "bo = BST()\n",
+ "while(1):\n",
+ " print \"\\n1.Insert\"\n",
+ " print \"2.Delete\"\n",
+ " print \"3.Inorder Traversal\"\n",
+ " print \"4.Preorder Traversal\"\n",
+ " print \"5.Postorder Traversal\"\n",
+ " print \"6.Display\"\n",
+ " print \"7.Quit\"\n",
+ " print \"\\nEnter your choice: \",\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " print \"Enter the number to be inserted: \",\n",
+ " num = int(raw_input())\n",
+ " bo.insert(num)\n",
+ " elif choice == 2:\n",
+ " print \"Enter the number to be deleted: \",\n",
+ " num = int(raw_input())\n",
+ " bo.my_del(num)\n",
+ " elif choice == 3:\n",
+ " bo.inorder(bo.root)\n",
+ " raw_input()\n",
+ " elif choice == 4:\n",
+ " bo.preorder(bo.root)\n",
+ " raw_input()\n",
+ " elif choice == 5:\n",
+ " bo.postorder(bo.root);\n",
+ " raw_input()\n",
+ " elif choice == 6:\n",
+ " bo.display(bo.root,1);\n",
+ " raw_input()\n",
+ " elif choice == 7:\n",
+ " sys.exit()\n",
+ " else:\n",
+ " print \"Wrong choice...\"\n",
+ " raw_input()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Inorder Traversal\n",
+ "4.Preorder Traversal\n",
+ "5.Postorder Traversal\n",
+ "6.Display\n",
+ "7.Quit\n",
+ "\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the number to be inserted: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Inorder Traversal\n",
+ "4.Preorder Traversal\n",
+ "5.Postorder Traversal\n",
+ "6.Display\n",
+ "7.Quit\n",
+ "\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the number to be inserted: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Inorder Traversal\n",
+ "4.Preorder Traversal\n",
+ "5.Postorder Traversal\n",
+ "6.Display\n",
+ "7.Quit\n",
+ "\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the number to be inserted: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Inorder Traversal\n",
+ "4.Preorder Traversal\n",
+ "5.Postorder Traversal\n",
+ "6.Display\n",
+ "7.Quit\n",
+ "\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the number to be inserted: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Inorder Traversal\n",
+ "4.Preorder Traversal\n",
+ "5.Postorder Traversal\n",
+ "6.Display\n",
+ "7.Quit\n",
+ "\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the number to be inserted: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Inorder Traversal\n",
+ "4.Preorder Traversal\n",
+ "5.Postorder Traversal\n",
+ "6.Display\n",
+ "7.Quit\n",
+ "\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the number to be inserted: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Inorder Traversal\n",
+ "4.Preorder Traversal\n",
+ "5.Postorder Traversal\n",
+ "6.Display\n",
+ "7.Quit\n",
+ "\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the number to be inserted: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Inorder Traversal\n",
+ "4.Preorder Traversal\n",
+ "5.Postorder Traversal\n",
+ "6.Display\n",
+ "7.Quit\n",
+ "\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 2\n",
+ "3\n",
+ "4\n",
+ "5\n",
+ "6\n",
+ "7\n",
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Inorder Traversal\n",
+ "4.Preorder Traversal\n",
+ "5.Postorder Traversal\n",
+ "6.Display\n",
+ "7.Quit\n",
+ "\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 4\n",
+ "3\n",
+ "2\n",
+ "8\n",
+ "7\n",
+ "6\n",
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1.Insert\n",
+ "2.Delete\n",
+ "3.Inorder Traversal\n",
+ "4.Preorder Traversal\n",
+ "5.Postorder Traversal\n",
+ "6.Display\n",
+ "7.Quit\n",
+ "\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_of_Data_structures_using_C_and_C++/chapter9.ipynb b/Principles_of_Data_structures_using_C_and_C++/chapter9.ipynb
new file mode 100644
index 00000000..a76b358b
--- /dev/null
+++ b/Principles_of_Data_structures_using_C_and_C++/chapter9.ipynb
@@ -0,0 +1,1894 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:3af0c5b7e2b3e44b42e6890fde587cb6dc8ea3cb552c17bf7bd33e8216829d14"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9: Graphs"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, page no. 314"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "adj =[]\n",
+ "n = None\n",
+ "\n",
+ "for i in range(20):\n",
+ " a = []\n",
+ " for j in range(20):\n",
+ " a.append(-1)\n",
+ " adj.append(a)\n",
+ "\n",
+ "def create_graph():\n",
+ " global n\n",
+ " print \"Enter number of nodes: \",\n",
+ " n = int(raw_input())\n",
+ " max_edges = n*(n-1)\n",
+ " for i in range(1,max_edges):\n",
+ " print \"Enter edge %d(0 0) to quit: \" %i\n",
+ " origin = int(raw_input())\n",
+ " destination = int(raw_input())\n",
+ " if ((origin==0) and (destination==0)):\n",
+ " break\n",
+ " if ( origin > n or destination > n or origin<=0 or destination<=0):\n",
+ " print \"Invalid edge! \"\n",
+ " i -= 1 \n",
+ " else:\n",
+ " adj[origin][destination] = 1\n",
+ "\n",
+ "def display():\n",
+ " global n\n",
+ " for i in range(1,n+1):\n",
+ " for j in range(1,n+1):\n",
+ " print \"%4d\" %(adj[i][j]),\n",
+ " print \"\"\n",
+ "\n",
+ "def insert_node():\n",
+ " global n\n",
+ " n += 1\n",
+ " print \"The inserted node is %d \" %n\n",
+ " for i in range(1,n+1):\n",
+ " adj[i][n] = 0\n",
+ " adj[n][i] = 0\n",
+ "\n",
+ "def delete_node(u):\n",
+ " global n\n",
+ " if(n == 0):\n",
+ " print \"Graph is empty \"\n",
+ " return\n",
+ " if ( u>n ):\n",
+ " print \"This node is not present in the graph \"\n",
+ " return\n",
+ " for i in range(u, n):\n",
+ " for j in range(1, n+1):\n",
+ " adj[j][i]=adj[j][i+1]\n",
+ " adj[i][j]=adj[i+1][j]\n",
+ " n -= 1\n",
+ "\n",
+ "def insert_edge(u, v):\n",
+ " global n\n",
+ " if (u > n):\n",
+ " print \"Source node does not exist\"\n",
+ " return\n",
+ " if(v > n):\n",
+ " print \"Destination node does not exist\"\n",
+ " return\n",
+ " adj[u][v] = 1\n",
+ "\n",
+ "def del_edge(u,v):\n",
+ " global n\n",
+ " if (u>n or v>n or adj[u][v]==0):\n",
+ " print \"This edge does not exist\"\n",
+ " return\n",
+ " adj[u][v] = 0\n",
+ "\n",
+ "create_graph()\n",
+ "while(1):\n",
+ " print \"1.Insert a node\"\n",
+ " print \"2.Insert an edge\"\n",
+ " print \"3.Delete a node\"\n",
+ " print \"4.Delete an edge\"\n",
+ " print \"5.Dispaly\"\n",
+ " print \"6.Exit\"\n",
+ " print \"Enter your choice: \",\n",
+ " choice = int(raw_input())\n",
+ " if choice == 1:\n",
+ " insert_node()\n",
+ " elif choice == 2:\n",
+ " print \"Enter an edge to be inserted: \",\n",
+ " origin = int(raw_input())\n",
+ " destin = int(raw_input())\n",
+ " insert_edge(origin, destin)\n",
+ " elif choice == 3:\n",
+ " print \"\\nEnter a node to be deleted: \",\n",
+ " node = int(raw_input())\n",
+ " delete_node(node)\n",
+ " elif choice == 4:\n",
+ " print \"Enter an edge to be deleted: \",\n",
+ " origin = int(raw_input())\n",
+ " destin = int(raw_input())\n",
+ " del_edge(origin,destin)\n",
+ " elif choice == 5:\n",
+ " display()\n",
+ " elif choice == 6:\n",
+ " sys.exit()\n",
+ " else:\n",
+ " print \"Wrong choice \""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of nodes: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edge 1(0 0) to quit: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter edge 2(0 0) to quit: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter edge 3(0 0) to quit: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter edge 4(0 0) to quit: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1.Insert a node\n",
+ "2.Insert an edge\n",
+ "3.Delete a node\n",
+ "4.Delete an edge\n",
+ "5.Dispaly\n",
+ "6.Exit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " -1 1 -1 \n",
+ " -1 -1 1 \n",
+ " 1 -1 -1 \n",
+ "1.Insert a node\n",
+ "2.Insert an edge\n",
+ "3.Delete a node\n",
+ "4.Delete an edge\n",
+ "5.Dispaly\n",
+ "6.Exit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The inserted node is 4 \n",
+ "1.Insert a node\n",
+ "2.Insert an edge\n",
+ "3.Delete a node\n",
+ "4.Delete an edge\n",
+ "5.Dispaly\n",
+ "6.Exit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " -1 1 -1 0 \n",
+ " -1 -1 1 0 \n",
+ " 1 -1 -1 0 \n",
+ " 0 0 0 0 \n",
+ "1.Insert a node\n",
+ "2.Insert an edge\n",
+ "3.Delete a node\n",
+ "4.Delete an edge\n",
+ "5.Dispaly\n",
+ "6.Exit\n",
+ "Enter your choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, page no. 321"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from collections import deque\n",
+ "\n",
+ "class MyBFS:\n",
+ " def __init__(self, n, e, src):\n",
+ " self.node = n\n",
+ " self.edges = e\n",
+ " self.source = src\n",
+ " self.color = ['W' for i in range(0,n)]\n",
+ " self.graph = color= [[False for i in range(0,n)] for j in range(0,n)]\n",
+ " self.queue = deque()\n",
+ " self.parent = [-1 for u in range(0,n)]\n",
+ "\n",
+ " self.create_graph()\n",
+ " self.traversal()\n",
+ "\n",
+ " def create_graph(self):\n",
+ " for u,v in self.edges:\n",
+ " self.graph[u][v], self.graph[v][u] = True, True\n",
+ "\n",
+ " def traversal(self):\n",
+ "\n",
+ " self.queue.append(self.source)\n",
+ " self.color[self.source] = 'B'\n",
+ "\n",
+ " while len(self.queue):\n",
+ " u = self.queue.popleft()\n",
+ " for v in range(0,self.node):\n",
+ " if self.graph[u][v] == True and self.color[v]=='W':\n",
+ " self.color[v]='B'\n",
+ " self.queue.append(v)\n",
+ " self.parent[v]=u\n",
+ "\n",
+ " def show_path(self, destin):\n",
+ " if destin == self.source:\n",
+ " print destin,\n",
+ " elif self.parent[destin] == -1:\n",
+ " print \"No Path\"\n",
+ " else:\n",
+ " self.show_path(self.parent[destin])\n",
+ " print \"-> \",destin,\n",
+ "\n",
+ "\n",
+ "e = []\n",
+ "print \"Enter Number of nodes: \", \n",
+ "n = int(raw_input())\n",
+ "for i in range(n):\n",
+ " print \"Enter edges (0 0) to quit: \",\n",
+ " origin = int(raw_input())\n",
+ " destin = int(raw_input())\n",
+ " if(origin == 0 and destin == 0):\n",
+ " break\n",
+ " temp = [origin, destin]\n",
+ " e.append(temp)\n",
+ " \n",
+ "print \"Enter source: \"\n",
+ "src = int(raw_input())\n",
+ "print \"Enter destination to be searched: \"\n",
+ "destin = int(raw_input())\n",
+ "#sample [(0,1),(0,3),(1,2),(1,5),(2,7),(3,4),(3,6),(4,5),(5,7)]\n",
+ "bfs = MyBFS(n, e, src)\n",
+ "print \"BFS Traversal\"\n",
+ "bfs.show_path(destin)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number of nodes: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edges (0 0) to quit: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edges (0 0) to quit: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edges (0 0) to quit: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edges (0 0) to quit: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edges (0 0) to quit: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edges (0 0) to quit: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edges (0 0) to quit: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edges (0 0) to quit: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edges (0 0) to quit: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edges (0 0) to quit: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter source: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter destination to be searched: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "BFS Traversal\n",
+ "0 -> 1 -> 4 -> 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, page no. 326"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "adj =[]\n",
+ "n = None\n",
+ "\n",
+ "for i in range(10):\n",
+ " a = []\n",
+ " for j in range(10):\n",
+ " a.append(-1)\n",
+ " adj.append(a)\n",
+ " \n",
+ "def buildadjm(adj, n):\n",
+ " for i in range(n):\n",
+ " for j in range(n):\n",
+ " print \"Enter 1 if there is an edge from %d to %d, otherwise enter 0 \" %(i,j),\n",
+ " adj[i][j] = int(raw_input())\n",
+ " \n",
+ "def dfs(x, visited, adj, n):\n",
+ " visited[x] = 1\n",
+ " print \"The node visited is %d\\n\" %x\n",
+ " for j in range(n):\n",
+ " if (adj[x][j] ==1 and visited[j] ==0):\n",
+ " dfs(j,visited,adj,n);\n",
+ "\n",
+ "visited = []\n",
+ "print \"Enter the number of nodes in graph maximum = 10: \"\n",
+ "n = int(raw_input())\n",
+ "buildadjm(adj, n);\n",
+ "for i in range(n):\n",
+ " visited.append(0)\n",
+ "for i in range(n):\n",
+ " if(visited[i] == 0):\n",
+ " dfs(i,visited,adj,n);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number of nodes in graph maximum = 10: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 1 if there is an edge from 0 to 0, otherwise enter 0 "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 1 if there is an edge from 0 to 1, otherwise enter 0 "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 1 if there is an edge from 0 to 2, otherwise enter 0 "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 1 if there is an edge from 1 to 0, otherwise enter 0 "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 1 if there is an edge from 1 to 1, otherwise enter 0 "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 1 if there is an edge from 1 to 2, otherwise enter 0 "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 1 if there is an edge from 2 to 0, otherwise enter 0 "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 1 if there is an edge from 2 to 1, otherwise enter 0 "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 1 if there is an edge from 2 to 2, otherwise enter 0 "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The node visited is 0\n",
+ "\n",
+ "The node visited is 2\n",
+ "\n",
+ "The node visited is 1\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, page no. 332"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "class edge:\n",
+ " u = 0\n",
+ " v = 0\n",
+ " weight = 0\n",
+ " link = None\n",
+ "\n",
+ "front = None\n",
+ "\n",
+ "father = []\n",
+ "tree = []\n",
+ "n = 0\n",
+ "wt_tree = 0\n",
+ "count = 0\n",
+ "\n",
+ "def create_graph():\n",
+ " global n\n",
+ " print \"Enter number of nodes: \",\n",
+ " n = int(raw_input())\n",
+ " max_edges = n*(n-1)/2\n",
+ " for i in range(1, max_edges+1):\n",
+ " print \"Enter edge %d (0 0) to quit: \" %i\n",
+ " origin = int(raw_input())\n",
+ " destin = int(raw_input())\n",
+ " if (origin==0 and destin == 0):\n",
+ " break\n",
+ " print \"Enter weight for this edge: \",\n",
+ " wt = int(raw_input())\n",
+ " if(origin > n or destin> n or origin < 0 or destin < 0):\n",
+ " print \"Invalid edge...\"\n",
+ " i -= 1\n",
+ " else:\n",
+ " insert_pque(origin, destin, wt)\n",
+ " if(i<n-1):\n",
+ " print \"Spanning tree is not possible...\"\n",
+ " sys.exit()\n",
+ "\n",
+ "def insert_pque(i, j, wt):\n",
+ " global front\n",
+ " tmp = edge()\n",
+ " tmp.u = i\n",
+ " tmp.v = j\n",
+ " tmp.weight = wt\n",
+ " if(front == None or tmp.weight < front.weight):\n",
+ " tmp.link = front\n",
+ " front = tmp\n",
+ " else:\n",
+ " q = front\n",
+ " while(q.link != None and q.link.weight <= tmp.weight):\n",
+ " q = q.link\n",
+ " tmp.link = q.link\n",
+ " q.link = tmp\n",
+ " if(q.link == None):\n",
+ " tmp.link = None\n",
+ "\n",
+ "def make_tree():\n",
+ " global n\n",
+ " global wt_tree\n",
+ " global count\n",
+ " global father\n",
+ " for i in range(n):\n",
+ " father.append(0)\n",
+ " temp = edge()\n",
+ " root_n1 = 0\n",
+ " root_n2 = 0\n",
+ " while(count<n-1):\n",
+ " print count\n",
+ " temp = del_pque()\n",
+ " node1 = temp.u\n",
+ " node2 = temp.v\n",
+ " print \"n1 = %d\" %node1\n",
+ " print \"n2 = %d\" %node2\n",
+ " while(node1>0):\n",
+ " root_n1 = node1\n",
+ " node1 = father[node1]\n",
+ " while(node2>0):\n",
+ " root_n2 = node2\n",
+ " node2 = father[node2]\n",
+ " print \"root_n1=%d\" %root_n1\n",
+ " print \"root_n2=%d\" %root_n2\n",
+ " if(root_n1!=root_n2):\n",
+ " insert_tree(temp.u, temp.v, temp.weight)\n",
+ " wt_tree = wt_tree + temp.weight\n",
+ " father[root_n2] = root_n1\n",
+ "\n",
+ "def insert_tree(i, j, wt):\n",
+ " global count\n",
+ " global tree\n",
+ " print \"This edge inserted in the spanning tree: \",\n",
+ " print count\n",
+ " count += 1\n",
+ " ob = edge()\n",
+ " ob.u = i\n",
+ " ob.v = j\n",
+ " ob.weight = wt\n",
+ " tree.append(ob)\n",
+ "\n",
+ "def del_pque():\n",
+ " global front\n",
+ " tmp = edge()\n",
+ " tmp = front\n",
+ " print \"Edge processed is %d->%d %d\" %(tmp.u, tmp.v, tmp.weight)\n",
+ " front = front.link\n",
+ " return tmp\n",
+ " \n",
+ "\n",
+ "create_graph()\n",
+ "make_tree()\n",
+ "print \"Edges to be included in spanning tree are: \",\n",
+ "print count\n",
+ "for i in range(0, count):\n",
+ " print tree[i].u, tree[i].v\n",
+ "print \"Weight of the minimum spanning tree is: \", wt_tree"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of nodes: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edge 1 (0 0) to quit: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter weight for this edge: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edge 2 (0 0) to quit: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter weight for this edge: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edge 3 (0 0) to quit: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter weight for this edge: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 0\n",
+ "Edge processed is 0->1 5\n",
+ "n1 = 0\n",
+ "n2 = 1\n",
+ "root_n1=0\n",
+ "root_n2=1\n",
+ "This edge inserted in the spanning tree: 0\n",
+ "1\n",
+ "Edge processed is 1->2 7\n",
+ "n1 = 1\n",
+ "n2 = 2\n",
+ "root_n1=1\n",
+ "root_n2=2\n",
+ "This edge inserted in the spanning tree: 1\n",
+ "Edges to be included in spanning tree are: 2\n",
+ "0 1\n",
+ "1 2\n",
+ "Weight of the minimum spanning tree is: 12\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, page no. 341"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "from numpy import *\n",
+ "\n",
+ "class node:\n",
+ " predecessor = 0\n",
+ " dist = 0\n",
+ " status = 0\n",
+ "\n",
+ "class edge:\n",
+ " u = 0\n",
+ " v = 0\n",
+ "\n",
+ "adj = []\n",
+ "n = 0\n",
+ "TEMP = 0\n",
+ "PERM = 1\n",
+ "FALSE = 0\n",
+ "TRUE = 1\n",
+ "infinity = 9999\n",
+ "\n",
+ "for i in range(10):\n",
+ " a = []\n",
+ " for j in range(10):\n",
+ " a.append(-1)\n",
+ " adj.append(a)\n",
+ " \n",
+ "def create_graph():\n",
+ " global n\n",
+ " global TEMP\n",
+ " global PERM\n",
+ " global FALSE\n",
+ " global TRUE\n",
+ " global infinity\n",
+ " print \"Enter number of vertices: \",\n",
+ " n = int(raw_input())\n",
+ " max_edges=n*(n-1)/2\n",
+ " for i in range(1, max_edges+1):\n",
+ " print \"Enter edge %d(0 0 to quit): \" %i\n",
+ " origin = int(raw_input())\n",
+ " destin = int(raw_input())\n",
+ " if((origin==0) and (destin==0)):\n",
+ " break\n",
+ " print \"Enter weight for this edge: \",\n",
+ " wt = int(raw_input())\n",
+ " if( origin > n or destin > n or origin<=0 or destin<=0):\n",
+ " print \"Invalid edge! \"\n",
+ " i -= 1\n",
+ " else:\n",
+ " adj[origin][destin]=wt\n",
+ " adj[destin][origin]=wt\n",
+ " if(i<n-1):\n",
+ " print \"Spanning tree is not possible...\"\n",
+ " sys.exit()\n",
+ "\n",
+ "def display():\n",
+ " global n\n",
+ " for i in range(1, n+1):\n",
+ " for j in range(1, n+1):\n",
+ " print \"%3d\" %(adj[i][j]),\n",
+ " print \"\"\n",
+ "\n",
+ "def all_perm(state):\n",
+ " global n\n",
+ " global n\n",
+ " global TEMP\n",
+ " global PERM\n",
+ " global FALSE\n",
+ " global TRUE\n",
+ " global infinity\n",
+ " for i in range(1, n+1):\n",
+ " if( state[i].status == TEMP ):\n",
+ " return FALSE\n",
+ " return TRUE\n",
+ "\n",
+ "def maketree(tree):\n",
+ " global n\n",
+ " global TEMP\n",
+ " global PERM\n",
+ " global FALSE\n",
+ " global TRUE\n",
+ " global infinity\n",
+ " state = []\n",
+ " for i in range(n+1):\n",
+ " state.append(0)\n",
+ " weight=0\n",
+ " for i in range(1, n+1):\n",
+ " ob = node()\n",
+ " ob.predecessor=0\n",
+ " ob.dist = infinity\n",
+ " ob.status = TEMP\n",
+ " state[i] = ob\n",
+ " state[1].predecessor = 0\n",
+ " state[1].dist = 0\n",
+ " state[1].status = PERM\n",
+ " current = 1\n",
+ " count = 0\n",
+ " while( all_perm(state) != TRUE ):\n",
+ " for i in range(1, n+1):\n",
+ " if(adj[current][i] > 0 and state[i].status == TEMP):\n",
+ " if(adj[current][i] < state[i].dist):\n",
+ " state[i].predecessor = current\n",
+ " state[i].dist = adj[current][i]\n",
+ " min = infinity;\n",
+ " for i in range(1, n+1):\n",
+ " if (state[i].status == TEMP and state[i].dist < min):\n",
+ " min = state[i].dist\n",
+ " current = i\n",
+ " state[current].status = PERM\n",
+ " u1 = state[current].predecessor\n",
+ " v1 = current\n",
+ " count += 1\n",
+ " tree[count].u=u1\n",
+ " tree[count].v=v1\n",
+ " weight = weight+adj[u1][v1]\n",
+ " return count, weight\n",
+ "\n",
+ "path = []\n",
+ "\n",
+ "tree = []\n",
+ "for i in range(10):\n",
+ " ob = edge()\n",
+ " ob.u = 0\n",
+ " ob.v = 0\n",
+ " tree.append(ob)\n",
+ "create_graph()\n",
+ "print \"Adjacency matrix is: \"\n",
+ "display()\n",
+ "count, weight = maketree(tree)\n",
+ "print \"Weight of spanning tree is: %d\" %weight\n",
+ "print \"Edges to be included in spanning tree are: \"\n",
+ "for i in range(1, count+1):\n",
+ " print tree[i].u, tree[i].v"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of vertices: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edge 1(0 0 to quit): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter weight for this edge: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edge 2(0 0 to quit): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter weight for this edge: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edge 3(0 0 to quit): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter weight for this edge: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Adjacency matrix is: \n",
+ " -1 7 5 \n",
+ " 7 -1 6 \n",
+ " 5 6 -1 \n",
+ "Weight of spanning tree is: 11\n",
+ "Edges to be included in spanning tree are: \n",
+ "1 3\n",
+ "3 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6, page no. 351"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "TEMP = 0\n",
+ "PERM = 1\n",
+ "infinity = 9999\n",
+ "adj = [[0 for i in range(100)] for j in range(100)]\n",
+ "n = 0 \n",
+ "\n",
+ "\n",
+ "class node:\n",
+ " predecessor = 0\n",
+ " dist = 0\n",
+ " status = 0\n",
+ " \n",
+ "for i in range(10):\n",
+ " ob = node()\n",
+ " adj.append(ob)\n",
+ "\n",
+ "def create_graph():\n",
+ " global TEMP\n",
+ " global PERM\n",
+ " global infinity\n",
+ " global n\n",
+ " print \"Enter number of vertices: \",\n",
+ " n = int(raw_input())\n",
+ " max_edges = n*(n-1)\n",
+ " for i in range (1, max_edges+1):\n",
+ " print \"Enter edge %d(0 0 to quit): \" %i\n",
+ " origin = int(raw_input())\n",
+ " destin = int(raw_input())\n",
+ " if((origin==0) and (destin==0)):\n",
+ " break\n",
+ " print \"Enter weight for this edge: \",\n",
+ " wt = int(raw_input())\n",
+ " if ( origin > n or destin > n or origin<=0 or destin<=0):\n",
+ " print \"Invalid edge! \"\n",
+ " i -= 1\n",
+ " else:\n",
+ " adj[origin][destin] = wt\n",
+ "\n",
+ "def display():\n",
+ " for i in range(1, n+1):\n",
+ " for j in range(1, n+1):\n",
+ " print \"%3d\" %(adj[i][j]),\n",
+ " print \"\"\n",
+ "def findpath(s, d, path, sdist):\n",
+ " global TEMP\n",
+ " global PERM\n",
+ " global infinity\n",
+ " global n\n",
+ " state = []\n",
+ " count = 0\n",
+ " sdist = 0\n",
+ " for i in range(1, n+1):\n",
+ " temp = node()\n",
+ " temp.predecessor = 0\n",
+ " temp.dist = infinity\n",
+ " temp.status = TEMP\n",
+ " state.append(temp)\n",
+ " state[s-1].predecessor = 0\n",
+ " state[s-1].dist = 0\n",
+ " state[s-1].status = PERM\n",
+ " current = s\n",
+ " while(current-1 != d):\n",
+ " for i in range(1, n+1):\n",
+ " if (adj[current-1][i-1] > 0 and state[i-1].status == TEMP):\n",
+ " newdist = state[current-1].dist + adj[current-1][i-1]\n",
+ " if ( newdist < state[i-1].dist ):\n",
+ " state[i-1].predecessor = current-1\n",
+ " state[i-1].dist = newdist\n",
+ " min = infinity\n",
+ " current = 0\n",
+ " for i in range(1, n+1):\n",
+ " if(state[i-1].status == TEMP and state[i-1].dist < min):\n",
+ " min = state[i-1].dist\n",
+ " current = i-1\n",
+ " if(current==0):\n",
+ " return 0\n",
+ " state[current].status=PERM\n",
+ " while( current!=0 ):\n",
+ " count += 1\n",
+ " path[count] = current\n",
+ " current=state[current-1].predecessor\n",
+ " for i in range(count, -1, -1):\n",
+ " u = path[i]\n",
+ " v = path[i-1]\n",
+ " sdist += adj[u][v]\n",
+ " return count\n",
+ "\n",
+ "path = []\n",
+ "create_graph()\n",
+ "print \"The adjacency matrix is: \"\n",
+ "display()\n",
+ "shortdist = 0\n",
+ "while(1):\n",
+ " print \"\\nEnter source node(0 to quit): \",\n",
+ " source = int(raw_input())\n",
+ " print \"\\nEnter destination node(0 to quit): \",\n",
+ " dest = int(raw_input())\n",
+ " if(source==0 or dest==0):\n",
+ " sys.exit()\n",
+ " count = findpath(source,dest,path,shortdist);\n",
+ " if(shortdist!=0):\n",
+ " print \"\\nShortest distance is: \", shortdist\n",
+ " print \"\\nShortest Path is: \"\n",
+ " for i in range(count, 1, -1):\n",
+ " print path[i]\n",
+ " print path[i]\n",
+ " print \"\"\n",
+ " else:\n",
+ " print \"There is no path from source to destination node\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of vertices: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edge 1(0 0 to quit): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter weight for this edge: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edge 2(0 0 to quit): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter weight for this edge: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edge 3(0 0 to quit): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter weight for this edge: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter edge 4(0 0 to quit): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The adjacency matrix is: \n",
+ " 0 8 0 \n",
+ " 0 0 7 \n",
+ " 5 0 0 \n",
+ "\n",
+ "Enter source node(0 to quit): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter destination node(0 to quit): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 2\n",
+ "There is no path from source to destination node\n",
+ "\n",
+ "Enter source node(0 to quit): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter destination node(0 to quit): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "ename": "SystemExit",
+ "evalue": "",
+ "output_type": "pyerr",
+ "traceback": [
+ "An exception has occurred, use %tb to see the full traceback.\n",
+ "\u001b[1;31mSystemExit\u001b[0m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "To exit: use 'exit', 'quit', or Ctrl-D.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Principles_of_Data_structures_using_C_and_C++/screenshots/graph.png b/Principles_of_Data_structures_using_C_and_C++/screenshots/graph.png
new file mode 100644
index 00000000..a1112571
--- /dev/null
+++ b/Principles_of_Data_structures_using_C_and_C++/screenshots/graph.png
Binary files differ
diff --git a/Principles_of_Data_structures_using_C_and_C++/screenshots/queue.png b/Principles_of_Data_structures_using_C_and_C++/screenshots/queue.png
new file mode 100644
index 00000000..5e19e23a
--- /dev/null
+++ b/Principles_of_Data_structures_using_C_and_C++/screenshots/queue.png
Binary files differ
diff --git a/Principles_of_Data_structures_using_C_and_C++/screenshots/stack.png b/Principles_of_Data_structures_using_C_and_C++/screenshots/stack.png
new file mode 100644
index 00000000..0324ae7d
--- /dev/null
+++ b/Principles_of_Data_structures_using_C_and_C++/screenshots/stack.png
Binary files differ
diff --git a/Programming_With_Java_A_Primer/README.txt b/Programming_With_Java_A_Primer/README.txt
new file mode 100644
index 00000000..215ec20a
--- /dev/null
+++ b/Programming_With_Java_A_Primer/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Vaibhav Vajani
+Course: others
+College/Institute/Organization: brahmanand institute of management & science
+Department/Designation: Assistant Professor
+Book Title: Programming With Java A Primer
+Author: E. Balagurusamy
+Publisher: Tata McGraw-Hill Publishing Company Limited
+Year of publication: 2007
+Isbn: 0070617139
+Edition: 3rd \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter10.ipynb b/Programming_With_Java_A_Primer/chapter10.ipynb
new file mode 100644
index 00000000..47f27579
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter10.ipynb
@@ -0,0 +1,133 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:995bd55986cb75ede34cceda310ffd2c9f00a5c6e6a22d85c294456d1db3fd3f"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10: Interfaces: Multiple Inheritance"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 10.1, page no. page no. 184"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "There are no interfaces in Python. We will use normal classes instead\n",
+ "\"\"\"\n",
+ "\n",
+ "class Rectangle:\n",
+ " def compute(self, x, y):\n",
+ " return x*y\n",
+ "\n",
+ "class Circle:\n",
+ " pi = 3.14\n",
+ " def compute(self, x, y):\n",
+ " return self.pi*x*x\n",
+ "\n",
+ "rect = Rectangle()\n",
+ "cir = Circle()\n",
+ "print \"Area of rectangle: \", rect.compute(10, 20)\n",
+ "print \"Area of circle: \", cir.compute(10, 0)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area of rectangle: 200\n",
+ "Area of circle: 314.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 10.2, page no. 211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "class Student(object):\n",
+ " rollNumber = 0\n",
+ " def getNumber(self, n):\n",
+ " self.rollNumber = n\n",
+ " def putNumber(self):\n",
+ " print \"Roll No.: \", self.rollNumber\n",
+ "\n",
+ "class Test(Student, object):\n",
+ " part1 = 0.0\n",
+ " part2 = 0.0\n",
+ " def getMarks(self, m1, m2):\n",
+ " self.part1 = m1\n",
+ " self.part2 = m2\n",
+ " def putMarks(self):\n",
+ " print \"Marks Obtained\"\n",
+ " print \"Part 1 = \", self.part1\n",
+ " print \"Part 2 = \", self.part2\n",
+ "\n",
+ "class Results(Test):\n",
+ " sportWt = 6.0\n",
+ " def putWt(self):\n",
+ " print \"Sports Wt: \", self.sportWt\n",
+ " def display(self):\n",
+ " total = self.part1 + self.part2 + self.sportWt\n",
+ " self.putNumber()\n",
+ " self.putMarks()\n",
+ " self.putWt()\n",
+ " print \"Total Score: \", total\n",
+ "\n",
+ "student1 = Results()\n",
+ "student1.getNumber(1234)\n",
+ "student1.getMarks(27.5, 33.0)\n",
+ "student1.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll No.: 1234\n",
+ "Marks Obtained\n",
+ "Part 1 = 27.5\n",
+ "Part 2 = 33.0\n",
+ "Sports Wt: 6.0\n",
+ "Total Score: 66.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter11.ipynb b/Programming_With_Java_A_Primer/chapter11.ipynb
new file mode 100644
index 00000000..66fe04c8
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter11.ipynb
@@ -0,0 +1,151 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:661266ea5854f8cdb4c1381d519c16a00dd0491ecb04f34e084c46771d5dc464"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Pckages: Putting Classes Together"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 11.1, page no. 198"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "Note there are no packages in Python, a python program(file) can be used as a module in anoter Python program\n",
+ "\"\"\"\n",
+ "\n",
+ "from package1 import *\n",
+ "from package2 import *\n",
+ "\n",
+ "a = classA()\n",
+ "b = classB()\n",
+ "\n",
+ "a.display()\n",
+ "b.displayB()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Class A\n",
+ "Class B\n",
+ "m = 10.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 11.2, page no. 200"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "Note there are no packages in Python, a python program(file) can be used as a module in anoter Python program\n",
+ "\"\"\"\n",
+ "\n",
+ "from package2 import *\n",
+ "\n",
+ "class classC(classB):\n",
+ " n = 20\n",
+ " def displayC(self):\n",
+ " print \"Class C\"\n",
+ " print \"m = \", self.m\n",
+ " print \"n = \", self.n\n",
+ "\n",
+ "c = classC()\n",
+ "c.displayB()\n",
+ "c.displayC()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Class B\n",
+ "m = 10.0\n",
+ "Class C\n",
+ "m = 10.0\n",
+ "n = 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 11.3, page no. 204"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "there is no concept of static import. We will use normal import instead\n",
+ "\"\"\"\n",
+ "\n",
+ "import math\n",
+ "\n",
+ "class mathop:\n",
+ " def circle(self, r):\n",
+ " area = math.pi*r*r\n",
+ " print \"The Area of circle is: \", area\n",
+ "\n",
+ "obj = mathop()\n",
+ "obj.circle(2.3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Area of circle is: 16.6190251375\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter12.ipynb b/Programming_With_Java_A_Primer/chapter12.ipynb
new file mode 100644
index 00000000..ea0f31a7
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter12.ipynb
@@ -0,0 +1,231 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:0815ba2045ff6b90ad464c5410843a3c00d29eb193c3c9a13b08fcf0be33a42e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12: Multithreaded Programming"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 12.1, page no. 211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "note: the output will differ from that given in textbook as Threading in Python differs from that in J\n",
+ "\"\"\"\n",
+ "\n",
+ "\n",
+ "def threadA():\n",
+ " for i in range(1, 6):\n",
+ " print \"From Thread A: i = \", i\n",
+ " print \"Exit from A\"\n",
+ "\n",
+ "def threadB():\n",
+ " for i in range(1, 6):\n",
+ " print \"From Thread B: i = \", i\n",
+ " print \"Exit from B\"\n",
+ "\n",
+ "def threadC():\n",
+ " for i in range(1, 6):\n",
+ " print \"From Thread C: i = \", i\n",
+ " print \"Exit from C\"\n",
+ "\n",
+ "thread1 = Thread(target=threadA, args=())\n",
+ "thread2 = Thread(target=threadB, args=())\n",
+ "thread3 = Thread(target=threadC, args=())\n",
+ "\n",
+ "thread1.start()\n",
+ "thread2.start()\n",
+ "thread3.start()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "From Thread C: i = 1\n",
+ "From Thread C: i = 2\n",
+ "From Thread C: i = 3\n",
+ "From Thread C: i = 4\n",
+ "From Thread C: i = 5\n",
+ "Exit from C\n",
+ "From Thread A: i = 1\n",
+ "From Thread A: i = 2\n",
+ "From Thread A: i = 3\n",
+ "From Thread A: i = 4\n",
+ "From Thread A: i = 5\n",
+ "Exit from A\n",
+ "From Thread B: i = 1\n",
+ "From Thread B: i = 2\n",
+ "From Thread B: i = 3\n",
+ "From Thread B: i = 4\n",
+ "From Thread B: i = 5\n",
+ "Exit from B\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 12.2, page no. 217"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "there is no yield or stop function for threads in Python. Demonstrating just sleep() function\n",
+ "\"\"\"\n",
+ "\n",
+ "from threading import Thread\n",
+ "\n",
+ "import time\n",
+ "\n",
+ "def threadA():\n",
+ " for i in range(1, 6):\n",
+ " print \"From Thread A: i = \", i\n",
+ " print \"Exit from A\"\n",
+ "\n",
+ "def threadB():\n",
+ " for i in range(1, 6):\n",
+ " print \"From Thread B: i = \", i\n",
+ " print \"Exit from B\"\n",
+ "\n",
+ "def threadC():\n",
+ " for i in range(1, 6):\n",
+ " print \"From Thread C: i = \", i\n",
+ " time.sleep(0.5)\n",
+ " print \"Exit from C\"\n",
+ "\n",
+ "thread1 = Thread(target=threadA, args=())\n",
+ "thread2 = Thread(target=threadB, args=())\n",
+ "thread3 = Thread(target=threadC, args=())\n",
+ "\n",
+ "thread1.start()\n",
+ "time.sleep(0.5)\n",
+ "thread2.start()\n",
+ "time.sleep(0.5)\n",
+ "thread3.start()\n",
+ "time.sleep(0.5)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "From Thread A: i = 1\n",
+ "From Thread A: i = 2\n",
+ "From Thread A: i = 3\n",
+ "From Thread A: i = 4\n",
+ "From Thread A: i = 5\n",
+ "Exit from A\n",
+ "From Thread B: i = 1\n",
+ "From Thread B: i = 2\n",
+ "From Thread B: i = 3\n",
+ "From Thread B: i = 4\n",
+ "From Thread B: i = 5\n",
+ "Exit from B\n",
+ "From Thread C: i = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#There is no way you can set priority for a thread in Python. Hence, example 12.3 is avoided"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 12.4, page no. 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "There is no runnable interface in Python. Will use normal threading instead\n",
+ "\"\"\"\n",
+ "\n",
+ "import threading\n",
+ "class X(threading.Thread):\n",
+ " def run(self):\n",
+ " for i in range(1, 11):\n",
+ " print \"ThreadX: \", i\n",
+ " print \"End of ThreadX\"\n",
+ "\n",
+ "runnable = X()\n",
+ "threadx = Thread()\n",
+ "threadx.start()\n",
+ "print \"End of main thread\"\n",
+ "runnable.run()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "End of main thread\n",
+ "ThreadX: 1\n",
+ "ThreadX: 2\n",
+ "ThreadX: 3\n",
+ "ThreadX: 4\n",
+ "ThreadX: 5\n",
+ "ThreadX: 6\n",
+ "ThreadX: 7\n",
+ "ThreadX: 8\n",
+ "ThreadX: 9\n",
+ "ThreadX: 10\n",
+ "End of ThreadX\n"
+ ]
+ }
+ ],
+ "prompt_number": 69
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter13.ipynb b/Programming_With_Java_A_Primer/chapter13.ipynb
new file mode 100644
index 00000000..7c07d269
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter13.ipynb
@@ -0,0 +1,267 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5b64344dd4b10e210167de1e2d127d9539461b4485363c51a2c3ddba9df7db38"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13: Managing Errors & Exceptions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 13.1, page no. 231"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "there is no need of semicolon. We will show error for something else\n",
+ "\"\"\"\n",
+ "\n",
+ "print \"Hello Python..."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "SyntaxError",
+ "evalue": "EOL while scanning string literal (<ipython-input-1-c13cce4dd116>, line 7)",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;36m File \u001b[1;32m\"<ipython-input-1-c13cce4dd116>\"\u001b[1;36m, line \u001b[1;32m7\u001b[0m\n\u001b[1;33m print \"Hello Python...\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 13.2, page no. 232"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "a = 10\n",
+ "b = 5\n",
+ "c = 5\n",
+ "x = a/(b-c)\n",
+ "print \"x = \", x\n",
+ "y = a/(b+c)\n",
+ "print \"y = \", y"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "ZeroDivisionError",
+ "evalue": "integer division or modulo by zero",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m<ipython-input-2-d52b7922541b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"x = \"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;31mZeroDivisionError\u001b[0m: integer division or modulo by zero"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.3 page no : 235"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "a = 10\n",
+ "b = 5\n",
+ "c = 5\n",
+ "try:\n",
+ " x = a/(b-c)\n",
+ "except Exception,e :\n",
+ " print \"Division by zero\"\n",
+ "y = a/(b+c)\n",
+ "print \"y = \",y"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Division by zero\n",
+ "y = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.4 page no : 236"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "import sys\n",
+ "invalid = 0\n",
+ "count = 0\n",
+ "for i in sys.argv:\n",
+ " try:\n",
+ " a = int(i)\n",
+ " except:\n",
+ " invalid += 1\n",
+ " print \"Invalid number\" , i\n",
+ " continue\n",
+ " count += 1\n",
+ "\n",
+ "print \"Valid Numbers : \" ,count\n",
+ "print \"Invalid numbers \",invalid\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Invalid number -c\n",
+ "Invalid number -f\n",
+ "Invalid number /tmp/tmp1tOqar/profile_default/security/kernel-082ebfe6-5650-4ba4-8bcf-cd17bc99af7a.json\n",
+ "Invalid number --IPKernelApp.parent_appname='ipython-notebook'\n",
+ "Invalid number --profile-dir\n",
+ "Invalid number /tmp/tmp1tOqar/profile_default\n",
+ "Invalid number --parent=1\n",
+ "Valid Numbers : 0\n",
+ "Invalid numbers 7\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 13.5, page no. 239"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "a = [5,10]\n",
+ "b = 5\n",
+ "try:\n",
+ " x = a[2]/b - a[1]\n",
+ "except AssertionError:\n",
+ " print \"AssertionError:\"\n",
+ "except IndexError:\n",
+ " print \"Array Index Error\"\n",
+ "except Exception:\n",
+ " print \"Any Error\"\n",
+ "y = a[1]/a[0]\n",
+ "print \"y = \" , y "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Array Index Error\n",
+ "y = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.6 page no : 239"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "x = 5\n",
+ "y = 1000\n",
+ "\n",
+ "class MyException(Exception):\n",
+ " def __init__(self, message):\n",
+ " Exception.__init__(self, message)\n",
+ " def error(self):\n",
+ " print self.message\n",
+ "\n",
+ "try:\n",
+ " z = x/y\n",
+ " if(z<0.01):\n",
+ " raise MyException(\"Number is too small\")\n",
+ "except MyException, error:\n",
+ " print \"Caught MyException\"\n",
+ " print error.message\n",
+ "finally:\n",
+ " print \"I am always here\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Caught MyException\n",
+ "Number is too small\n",
+ "I am always here\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter16.ipynb b/Programming_With_Java_A_Primer/chapter16.ipynb
new file mode 100644
index 00000000..8bd99a77
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter16.ipynb
@@ -0,0 +1,426 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:218fbe19da172953280529e0559355d55a34bf2741e9ecd127042579a2a52e47"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 16: Managing Input/Output file"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 16.1, page no. 300"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "fr = open(\"input.txt\", \"r\")\n",
+ "fw = open(\"output.txt\", \"w\")\n",
+ "my_str = fr.readline()\n",
+ "\n",
+ "for letter in my_str:\n",
+ " fw.write(letter) \n",
+ "#close a file\n",
+ "fr.close()\n",
+ "fw.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.2, page no. 303"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "fw = open(\"cities.txt\", \"w\")\n",
+ "cities = ['Delhi\\n','Madras\\n','London\\n'];\n",
+ "count = len(cities)\n",
+ "for city in cities:\n",
+ " fw.write(city) \n",
+ "fw.close()\n",
+ "fr = open(\"cities.txt\", \"r\")\n",
+ "for line in fr.readlines():\n",
+ " print line,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Delhi\n",
+ "Madras\n",
+ "London\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.3 is done using CLI which is not possible in IPython Notebook"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.4, page no. 305"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "there is no bytes stream in Python. We will use normal file operations to copy from one file to another\n",
+ "\"\"\"\n",
+ "\n",
+ "fr = open(\"in.txt\", \"r\")\n",
+ "fw = open(\"out.txt\", \"w\")\n",
+ "for line in fr.readlines():\n",
+ " fw.write(line) \n",
+ "fr.close()\n",
+ "fw.close()\n",
+ "\n",
+ "fw = open(\"out.txt\", \"r\")\n",
+ "for line in fw.readlines():\n",
+ " print line"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Java programming for internet.\n",
+ "\n",
+ "Javascript for webpage develpoment.\n",
+ "\n",
+ "Perl for server side scripting.\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.5, page no. 307"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\"\"\"\n",
+ "Note: In Python you can store data in file only as string.\n",
+ "\"\"\"\n",
+ "\n",
+ "fos = open(\"prim.dat\", \"w\")\n",
+ "fos.write(str(1999)+'\\n')\n",
+ "fos.write(str(375.85)+'\\n')\n",
+ "fos.write(str(False)+'\\n')\n",
+ "fos.write(\"x\"+'\\n')\n",
+ "fos.close()\n",
+ "\n",
+ "fis = open(\"prim.dat\", \"r\")\n",
+ "for line in fis.readlines():\n",
+ " print line\n",
+ "fis.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1999\n",
+ "\n",
+ "375.85\n",
+ "\n",
+ "False\n",
+ "\n",
+ "x\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.6, page no. 308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "from random import *\n",
+ "\n",
+ "dos = open(\"rand.dat\", \"w\")\n",
+ "try:\n",
+ " for i in range(20):\n",
+ " dos.write(str(randint(0,100))+'\\n')\n",
+ "except IOError:\n",
+ " print IOError.message\n",
+ "finally:\n",
+ " dos.close()\n",
+ "\n",
+ "dis = open(\"rand.dat\", \"r\")\n",
+ "# Note: random numbers are generated so output will differ from that given in the textbook.\n",
+ "for line in dis.readlines():\n",
+ " print line,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "92\n",
+ "49\n",
+ "68\n",
+ "67\n",
+ "71\n",
+ "25\n",
+ "85\n",
+ "53\n",
+ "10\n",
+ "87\n",
+ "15\n",
+ "5\n",
+ "33\n",
+ "30\n",
+ "72\n",
+ "52\n",
+ "80\n",
+ "85\n",
+ "36\n",
+ "84\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.7, page no. 310"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "file1 = open(\"file1.txt\", \"r\")\n",
+ "file2 = open(\"file2.txt\", \"r\")\n",
+ "file3 = open(\"file3.txt\", \"a\")\n",
+ "\n",
+ "for line in file1.readlines():\n",
+ " file3.write(line)\n",
+ "for line in file2.readlines():\n",
+ " file3.write(line)\n",
+ " \n",
+ "file1.close()\n",
+ "file2.close()\n",
+ "file3.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.8, page no. 312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "fp = open(\"random.dat\", \"w+\")\n",
+ "fp.write(\"x\\n\")\n",
+ "fp.write(str(555)+'\\n')\n",
+ "fp.write(str(3.1412)+'\\n')\n",
+ "fp.seek(0)\n",
+ "print fp.readline()\n",
+ "print fp.readline()\n",
+ "print fp.readline()\n",
+ "fp.seek(2)\n",
+ "print fp.readline()\n",
+ "fp.seek(fp.tell()+len(fp.readline()))\n",
+ "fp.write(\"False\\n\")\n",
+ "fp.seek(13)\n",
+ "print fp.readline()\n",
+ "fp.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x\n",
+ "\n",
+ "555\n",
+ "\n",
+ "3.1412\n",
+ "\n",
+ "555\n",
+ "\n",
+ "False\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.9, page no. 314"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "fp = open(\"cities.txt\", \"a\")\n",
+ "fp.write(\"Mumbai\\n\")\n",
+ "fp.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 85
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.10, page no. 315"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "dos = open(\"invent.dat\", \"w\")\n",
+ "dos.write(raw_input(\"Enter code number: \")+'\\n')\n",
+ "dos.write(raw_input(\"Enter number of items: \")+'\\n')\n",
+ "dos.write(raw_input(\"Enter cost: \")+'\\n')\n",
+ "dos.close()\n",
+ "dis = open(\"invent.dat\", \"r\")\n",
+ "codeNumber = int(dis.readline())\n",
+ "totalItems = int(dis.readline())\n",
+ "itemCost = int(dis.readline())\n",
+ "totalCost = totalItems*itemCost\n",
+ "dis.close()\n",
+ "\n",
+ "print \"Code Number: \", codeNumber\n",
+ "print \"Item Cost: \", itemCost\n",
+ "print \"Total Items: \", totalItems\n",
+ "print \"Total Cost: \", totalCost"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter code number: 1001\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of items: 193\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter cost: 452\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Code Number: 1001\n",
+ "Item Cost: 452\n",
+ "Total Items: 193\n",
+ "Total Cost: 87236\n"
+ ]
+ }
+ ],
+ "prompt_number": 91
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter17.ipynb b/Programming_With_Java_A_Primer/chapter17.ipynb
new file mode 100644
index 00000000..c8344546
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter17.ipynb
@@ -0,0 +1,61 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:6e44d5a558f592081f494afbf193b979399d3f382d6ddf2dd199186d661ef909"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 17: Assertion & Design by Contract"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17.1, page no. 336"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "class Division():\n",
+ " def assertcheck(self, a, b):\n",
+ " assert(b!=0), \"The value b cannot be zero\"\n",
+ " c = a/b\n",
+ " print \"The result is: \", c\n",
+ "div = Division()\n",
+ "div.assertcheck(5, 0)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "AssertionError",
+ "evalue": "The value b cannot be zero",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mAssertionError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m<ipython-input-3-39ef7600cfd3>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"The result is: \"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mc\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0mdiv\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mDivision\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 11\u001b[1;33m \u001b[0mdiv\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0massertcheck\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
+ "\u001b[1;32m<ipython-input-3-39ef7600cfd3>\u001b[0m in \u001b[0;36massertcheck\u001b[1;34m(self, a, b)\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mclass\u001b[0m \u001b[0mDivision\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0massertcheck\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[1;32massert\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m!=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"The value b cannot be zero\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0mc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"The result is: \"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mc\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;31mAssertionError\u001b[0m: The value b cannot be zero"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter18.ipynb b/Programming_With_Java_A_Primer/chapter18.ipynb
new file mode 100644
index 00000000..3760aefe
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter18.ipynb
@@ -0,0 +1,372 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:b65111374697402ea20166f271bb1488f1e63cc13c5da33961c35513244b0d0c"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 18: Java Collections"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.1, page no. 348"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\"\"\"\n",
+ "Note: there is no such class in Python. We will perform normal operations on array\n",
+ "\"\"\"\n",
+ "\n",
+ "arrayList = []\n",
+ "print \"Initial size of arrayList: \", len(arrayList)\n",
+ "arrayList.append(\"A\")\n",
+ "arrayList.append(\"B\")\n",
+ "arrayList.append(\"C\")\n",
+ "arrayList.append(\"D\")\n",
+ "arrayList.insert(2, \"E\")\n",
+ "print \"Changed contents of arraylist by adding element at the given index: \", arrayList\n",
+ "arrayList.pop(3)\n",
+ "arrayList.remove(\"A\")\n",
+ "print \"Changed contents of arraylist by removing element from the list: \", arrayList"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Initial size of arrayList: 0\n",
+ "Changed contents of arraylist by adding element at the given index: ['A', 'B', 'E', 'C', 'D']\n",
+ "Changed contents of arraylist by removing element from the list: ['B', 'E', 'D']\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.2, page no. 349"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\"\"\"\n",
+ "Note: There is no such collection in Python. We will dqueue instead, which is very much similar\n",
+ "\"\"\"\n",
+ "\n",
+ "from collections import deque\n",
+ "\n",
+ "d = deque()\n",
+ "\n",
+ "class MyStack():\n",
+ " def push1(self, o):\n",
+ " d.appendleft(o)\n",
+ " def push2(self, o):\n",
+ " d.append(o)\n",
+ " def bottom(self):\n",
+ " return d.pop()\n",
+ " def pop(self):\n",
+ " return d.popleft()\n",
+ "\n",
+ "class Car():\n",
+ " car1 = \"Benz\"\n",
+ " car2 = \"Toyoto\"\n",
+ " car3 = \"Qualis\"\n",
+ " car4 = \"Santro\"\n",
+ "\n",
+ "class Bird():\n",
+ " bird1 = \"parrot\"\n",
+ " bird2 = \"duck\"\n",
+ " bird3 = \"raven\"\n",
+ "\n",
+ "myCar = Car()\n",
+ "myBird = Bird()\n",
+ "s = MyStack()\n",
+ "s.push1(myCar.car1)\n",
+ "s.push2(myBird.bird3)\n",
+ "myCar = s.pop()\n",
+ "print \"The first element in the list: \", myCar\n",
+ "print \"The last element in the list: \", myBird.bird3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The first element in the list: Benz\n",
+ "The last element in the list: raven\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.3, page no. 351"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\"\"\"\n",
+ "Note: there is no collection hash set in Python. We will solve it in different manner\n",
+ "\"\"\"\n",
+ "\n",
+ "hs = set()\n",
+ "\n",
+ "hs.add(\"D\")\n",
+ "hs.add(\"A\")\n",
+ "hs.add(\"C\")\n",
+ "hs.add(\"B\")\n",
+ "hs.add(\"E\")\n",
+ "\n",
+ "#answer will differ due to difference in built-in techniques\n",
+ "print \"The elements available in the hash set are: \", hs"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The elements available in the hash set are: set(['A', 'C', 'B', 'E', 'D'])\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#There is no TreeSet or similar collection in Python (can be done using normal list like 18.1) so skipping example 18.4"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.5, page no. 353"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\"\"\"\n",
+ "Note: there is no vector in Python. Doing using normal lists.\n",
+ "\"\"\"\n",
+ "\n",
+ "fruits = []\n",
+ "\n",
+ "fruits.append(\"Apple\")\n",
+ "fruits.append(\"Orange\")\n",
+ "fruits.append(\"Grapes\")\n",
+ "fruits.append(\"Pine\")\n",
+ "\n",
+ "for ele in fruits:\n",
+ " print ele"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Apple\n",
+ "Orange\n",
+ "Grapes\n",
+ "Pine\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.6, page no. 354"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\"\"\"\n",
+ "In python we can use list itself as stack\n",
+ "\"\"\"\n",
+ "\n",
+ "st = []\n",
+ "\n",
+ "st.append(\"Java\")\n",
+ "st.append(\"latest\")\n",
+ "st.append(\"Edition\")\n",
+ "st.append(\"-fifth\")\n",
+ "\n",
+ "print \"The elements in the Stack: \", st\n",
+ "print \"The element at the top: \", st[-1:]\n",
+ "print \"The element poped out of the stack: \", st.pop()\n",
+ "print \"The element in a stack after pop out element: \", st\n",
+ "try:\n",
+ " \"The result of searching: \", st.index(\"r u\")\n",
+ "except ValueError:\n",
+ " print \"The result of searching: \", -1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The elements in the Stack: ['Java', 'latest', 'Edition', '-fifth']\n",
+ "The element at the top: ['-fifth']\n",
+ "The element poped out of the stack: -fifth\n",
+ "The element in a stack after pop out element: ['Java', 'latest', 'Edition']\n",
+ "The result of searching: -1\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.7, page no. 355"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\"\"\"\n",
+ "Note: we will use dictionaries\n",
+ "\"\"\"\n",
+ "\n",
+ "ht ={}\n",
+ "\n",
+ "ht['item1'] = \"Apple\"\n",
+ "ht['item2'] = \"Orange\"\n",
+ "ht['item3'] = \"Grapes\"\n",
+ "ht['item4'] = \"Pine\"\n",
+ "\n",
+ "for key in ht.iterkeys():\n",
+ " print ht[key]\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Orange\n",
+ "Grapes\n",
+ "Apple\n",
+ "Pine\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.8, page no. 357"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Answers will differ due to difference in built-in techniques of the classes\n",
+ "\n",
+ "from random import shuffle\n",
+ "\n",
+ "l = []\n",
+ "\n",
+ "l.append(\"java\")\n",
+ "l.append(\"is\")\n",
+ "l.append(\"platform\")\n",
+ "l.append(\"independent\")\n",
+ "\n",
+ "l_r = list(reversed(l))\n",
+ "l_r = sorted(l_r)\n",
+ "\n",
+ "print \"List sorted in reverse order is: \"\n",
+ "for ele in l_r:\n",
+ " print ele,\n",
+ "\n",
+ "print \"\\nList shuffled: \"\n",
+ "shuffle(l_r)\n",
+ "for ele in l_r:\n",
+ " print ele,\n",
+ "\n",
+ "print \"\\nMinimum: \", min(l_r)\n",
+ "print \"Maximum: \", max(l_r)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "List sorted in reverse order is: \n",
+ "independent is java platform \n",
+ "List shuffled: \n",
+ "java independent is platform \n",
+ "Minimum: independent\n",
+ "Maximum: platform\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter3.ipynb b/Programming_With_Java_A_Primer/chapter3.ipynb
new file mode 100644
index 00000000..15da94c7
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter3.ipynb
@@ -0,0 +1,178 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:900e8c40d4fed93f16924c238f3501224263d68b0f636bde52b89454eb250cc4"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3 : Overview of Java Language"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "exmple 3.1, page no. 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Python is better than Java.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Python is better than Java.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 3.2, page no. 27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "import math\n",
+ "\n",
+ "x = 5\n",
+ "y = math.sqrt(x)\n",
+ "print \"y = \", round(y,5)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "y = 2.23607\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 3.3, page no. 28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\"\"\"\n",
+ "Note: there is no need of another class here, as in Python there is no need of main class.\n",
+ "\"\"\"\n",
+ "\n",
+ "class Room:\n",
+ " length = 0.0\n",
+ " breadth = 0.0\n",
+ " def getdata(self, a, b):\n",
+ " self.length = a\n",
+ " self.breadth = b\n",
+ "\n",
+ "room1 = Room()\n",
+ "room1.getdata(14.0, 10.0)\n",
+ "area = room1.length*room1.breadth\n",
+ "print \"Area = \", area"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area = 140.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 3.4, page no. 35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "print \"Hellow!\"\n",
+ "print \"Welcome to the world of Python.\"\n",
+ "print \"Let us learn Python.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hellow!\n",
+ "Welcome to the world of Python.\n",
+ "Let us learn Python.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\"\"\"\n",
+ "Command line arguments cannot be taken from IPython Notebook.\n",
+ "Hence, example 3.5 is ignored.\n",
+ "\"\"\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 8,
+ "text": [
+ "'\\nCommand line arguments cannot be taken from IPython Notebook.\\nHence, example 3.5 is ignored.\\n'"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter4.ipynb b/Programming_With_Java_A_Primer/chapter4.ipynb
new file mode 100644
index 00000000..fd3a6d08
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter4.ipynb
@@ -0,0 +1,191 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d5e2b3b4e2eecb1f7195196f8d754ec6a4ed41953a9ae9d18560339b9d5ef6ea"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4: Constants, Variables & Datatypes"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 4.1, page no. 50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "intnum = int(raw_input(\"Enter an Integer: \"))\n",
+ "floatnum = float(raw_input(\"Enter a Float: \"))\n",
+ "\n",
+ "print \"intnum = \", intnum\n",
+ "print \"floatnum = \", floatnum"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an Integer: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a Float: 6.9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "intnum = 3\n",
+ "floatnum = 6.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 4.2, page no. 54"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "print \"Variables Created\"\n",
+ "c = \"x\"\n",
+ "b = 50\n",
+ "s = 1996\n",
+ "i = 123456789\n",
+ "l = 1234567654321L\n",
+ "f1 = 3.142\n",
+ "f2 = 1.2e-5\n",
+ "d2 = 0.000000987\n",
+ "\n",
+ "print \"c = \", c\n",
+ "print \"b = \", b\n",
+ "print \"s = \", s\n",
+ "print \"i = \", i\n",
+ "print \"l = \", l\n",
+ "print \"f1 = \", f1\n",
+ "print \"f2 = \", f2\n",
+ "print \"d2 = \", d2\n",
+ "\n",
+ "print \"Types Converted\"\n",
+ "#there is no short type in python\n",
+ "s1 = b\n",
+ "s2 = i\n",
+ "n1 = float(l)\n",
+ "m1 = int(f1)\n",
+ "\n",
+ "print \"s1 = \", s1\n",
+ "print \"s2 = \", s2\n",
+ "print \"n1 = %.5e\"% n1\n",
+ "print \"m1 = \", m1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Variables Created\n",
+ "c = x\n",
+ "b = 50\n",
+ "s = 1996\n",
+ "i = 123456789\n",
+ "l = 1234567654321\n",
+ "f1 = 3.142\n",
+ "f2 = 1.2e-05\n",
+ "d2 = 9.87e-07\n",
+ "Types Converted\n",
+ "s1 = 50\n",
+ "s2 = 123456789\n",
+ "n1 = 1.23457e+12\n",
+ "m1 = 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 4.3, page no. 56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "for i in range(1, 10):\n",
+ " for j in range(1, i+1):\n",
+ " print i,\n",
+ " print \"\"\n",
+ "print \"Screen Display Done\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 \n",
+ "2 2 \n",
+ "3 3 3 \n",
+ "4 4 4 4 \n",
+ "5 5 5 5 5 \n",
+ "6 6 6 6 6 6 \n",
+ "7 7 7 7 7 7 7 \n",
+ "8 8 8 8 8 8 8 8 \n",
+ "9 9 9 9 9 9 9 9 9 \n",
+ "Screen Display Done\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter5.ipynb b/Programming_With_Java_A_Primer/chapter5.ipynb
new file mode 100644
index 00000000..12e20bd5
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter5.ipynb
@@ -0,0 +1,325 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c8fa15513a66bcc3c782e246851674786a1e5f0313759a5d553c588db3808162"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5: Operators & Expressions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 5.1, page no. 62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "a = 20.5\n",
+ "b = 6.4\n",
+ "\n",
+ "print \"a = \", a\n",
+ "print \"b = \", b\n",
+ "print \"a+b = \", (a+b)\n",
+ "print \"a-b = \", (a-b)\n",
+ "print \"a*b = \", (a*b)\n",
+ "print \"a/b = \", (a/b)\n",
+ "print \"a%b = \", (a%b)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a = 20.5\n",
+ "b = 6.4\n",
+ "a+b = 26.9\n",
+ "a-b = 14.1\n",
+ "a*b = 131.2\n",
+ "a/b = 3.203125\n",
+ "a%b = 1.3\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 5.2, page no. 64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "a = 15.0\n",
+ "b = 20.75\n",
+ "c = 15.0\n",
+ "print \"a = \", a\n",
+ "print \"b = \", b\n",
+ "print \"c = \", c\n",
+ "print \"a<b is \", (a<b)\n",
+ "print \"a>b is \", (a>b)\n",
+ "print \"a==c is \", (a==c)\n",
+ "print \"a<=c is \", (a<=c)\n",
+ "print \"a>=b is \", (a>=b)\n",
+ "print \"b!=c is \", (b!=c)\n",
+ "print \"b==(a+c) is \", (b==(a+c))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a = 15.0\n",
+ "b = 20.75\n",
+ "c = 15.0\n",
+ "a<b is True\n",
+ "a>b is False\n",
+ "a==c is True\n",
+ "a<=c is True\n",
+ "a>=b is False\n",
+ "b!=c is True\n",
+ "b==(a+c) is False\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 5.3, page no. 67"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#there is no inrement operator in Python, we will use += instead\n",
+ "\n",
+ "m = 10\n",
+ "n = 20\n",
+ "print \"m = \", m\n",
+ "print \"n = \", n\n",
+ "m+=1\n",
+ "print \"++m = \", m \n",
+ "print \"n++ = \", n\n",
+ "n+=1\n",
+ "print \"m = \", m\n",
+ "print \"n = \", n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "m = 10\n",
+ "n = 20\n",
+ "++m = 11\n",
+ "n++ = 20\n",
+ "m = 11\n",
+ "n = 21\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 5.4, page no. 73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "my_sum = 0\n",
+ "for i in range(1, 11):\n",
+ " my_sum = my_sum + (1/float(i))\n",
+ " print \"i = \", i,\n",
+ " print \"sum = \", my_sum"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i = 1 sum = 1.0\n",
+ "i = 2 sum = 1.5\n",
+ "i = 3 sum = 1.83333333333\n",
+ "i = 4 sum = 2.08333333333\n",
+ "i = 5 sum = 2.28333333333\n",
+ "i = 6 sum = 2.45\n",
+ "i = 7 sum = 2.59285714286\n",
+ "i = 8 sum = 2.71785714286\n",
+ "i = 9 sum = 2.82896825397\n",
+ "i = 10 sum = 2.92896825397\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 5.5, page no. 74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "my_list = []\n",
+ "my_list.append(1)\n",
+ "my_list.append(2)\n",
+ "l = len(my_list)-1\n",
+ "total = 0\n",
+ "while l >= 0:\n",
+ " total = total + my_list[l]\n",
+ " l -= 1\n",
+ "print \"The total amount is \", total"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The total amount is 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 5.6, page no. 77"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "a = 10\n",
+ "b = 5\n",
+ "c = 8\n",
+ "d = 2\n",
+ "x = 6.4\n",
+ "y = 3.0\n",
+ "\n",
+ "answer1 = a * b + c / d\n",
+ "answer2 = a * (b+c) / d\n",
+ "\n",
+ "answer3 = a/c\n",
+ "answer4 = float(a)/c\n",
+ "answer5 = a / y\n",
+ "\n",
+ "answer6 = a % c\n",
+ "answer7 = float(x%y)\n",
+ "\n",
+ "bool1 = a > b and c > d\n",
+ "bool2 = a < b and c > d\n",
+ "bool3 = a < b or c > d\n",
+ "bool4 = not(a - b == c)\n",
+ "\n",
+ "print \"Order of Evaluation\"\n",
+ "print \"a * b + c / d = \", answer1\n",
+ "print \"a * (b+c) / d = \", answer2\n",
+ "\n",
+ "print \"Type Conversion\"\n",
+ "print \"a / c = \", answer3\n",
+ "print \"float(a)/c = \", answer4\n",
+ "print \"a / y = \", answer5\n",
+ "\n",
+ "print \"Modulo Operations\"\n",
+ "print \"a % c = \", answer6\n",
+ "print \"x % y = \", answer6\n",
+ "\n",
+ "print \"Logical Operations\"\n",
+ "print \"a > b and c > d = \", bool1\n",
+ "print \"a < b and c > d = \", bool2\n",
+ "print \"a < b or c > d = \", bool3\n",
+ "print \"not(a - b == c) \", bool4"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Order of Evaluation\n",
+ "a * b + c / d = 54\n",
+ "a * (b+c) / d = 65\n",
+ "Type Conversion\n",
+ "a / c = 1\n",
+ "float(a)/c = 1.25\n",
+ "a / y = 3.33333333333\n",
+ "Modulo Operations\n",
+ "a % c = 2\n",
+ "x % y = 2\n",
+ "Logical Operations\n",
+ "a > b and c > d = True\n",
+ "a < b and c > d = False\n",
+ "a < b or c > d = True\n",
+ "not(a - b == c) True\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter6.ipynb b/Programming_With_Java_A_Primer/chapter6.ipynb
new file mode 100644
index 00000000..3ffd656c
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter6.ipynb
@@ -0,0 +1,245 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1252446619e6e4563a32f0df79325967492fbf5a5dc688c7dbacba6bd7f62327"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Decision Making & Branching"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 6.1, page no. 84"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "weight = [45.0, 55.0, 47.0, 51.0, 54.0]\n",
+ "height = [176.5, 174.2, 168.0, 170.7, 169.0]\n",
+ "count = 0\n",
+ "count1 = 0\n",
+ "for i in range(0, 5):\n",
+ " if(weight[i]<50.0 and height[i]>170.0):\n",
+ " count1 += 1\n",
+ " count += 1\n",
+ "count2 = count - count1\n",
+ "print \"Number of persons with...\"\n",
+ "print \"Weight<50 and height>170 = \", count1\n",
+ "print \"Others = \", count2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of persons with...\n",
+ "Weight<50 and height>170 = 1\n",
+ "Others = 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 6.2, page no. 86"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "number = [50, 65, 56, 71, 81]\n",
+ "even = 0\n",
+ "odd = 0\n",
+ "for i in range(0, len(number)):\n",
+ " if(number[i] % 2 == 0):\n",
+ " even += 1\n",
+ " else:\n",
+ " odd += 1\n",
+ "print \"Even numbers = \", even, \"Odd Numbers = \", odd"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Even numbers = 2 Odd Numbers = 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 6.3, page no. 89"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "a = 325\n",
+ "b = 712\n",
+ "c = 478\n",
+ "\n",
+ "print \"Largets value is \",\n",
+ "if a > b:\n",
+ " if a > c:\n",
+ " print a\n",
+ " else:\n",
+ " print c\n",
+ "else:\n",
+ " if c > b:\n",
+ " print c\n",
+ " else:\n",
+ " print b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Largets value is 712\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 6.4, page no. 92"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "rollnumber = [111, 222, 333, 444]\n",
+ "marks = [81, 75, 43, 58]\n",
+ "for i in range(0, len(rollnumber)):\n",
+ " if marks[i] > 79:\n",
+ " print rollnumber[i], \"Honours\"\n",
+ " elif marks[i] > 59:\n",
+ " print rollnumber[i], \"I Division\"\n",
+ " elif marks[i] > 49:\n",
+ " print rollnumber[i], \"II Division\"\n",
+ " else:\n",
+ " print rollnumber[i], \"Fail\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "111 Honours\n",
+ "222 I Division\n",
+ "333 Fail\n",
+ "444 II Division\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 6.5, page no. 96"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#there is switch() statement in python, we will use if...else instead\n",
+ "\n",
+ "print \"Select your choice: \"\n",
+ "print \"M --> Madras\"\n",
+ "print \"B --> Bombay\"\n",
+ "print \"C --> Calcutta\"\n",
+ "print \"Choice --> \",\n",
+ "choice = raw_input()\n",
+ "if choice == \"M\" or choice == \"m\":\n",
+ " print \"Madras: Booklet 5\"\n",
+ "elif choice == \"B\" or choice == \"b\":\n",
+ " print \"Bombay: Booklet 9\"\n",
+ "elif choice == \"C\" or choice == \"c\":\n",
+ " print \"Calcutta: Booklet 15\"\n",
+ "else:\n",
+ " print \"Invalid Choice (IC)\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Select your choice: \n",
+ "M --> Madras\n",
+ "B --> Bombay\n",
+ "C --> Calcutta\n",
+ "Choice --> "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Madras: Booklet 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter7.ipynb b/Programming_With_Java_A_Primer/chapter7.ipynb
new file mode 100644
index 00000000..66904b83
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter7.ipynb
@@ -0,0 +1,309 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:a924e86900c65c3fd8c20ee5aee9bc052eac287d056598356137191816cafe4b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Decision Making & Looping"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 7.1, page no. 108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "the method shown in textbook is not possible in python.\n",
+ "We will implement in a different way\n",
+ "\"\"\"\n",
+ "\n",
+ "print \"Enter a string. Enter quit to stop\"\n",
+ "\n",
+ "my_str = \"\"\n",
+ "while True:\n",
+ " c = raw_input()\n",
+ " if c == \"quit\":\n",
+ " break\n",
+ " my_str = my_str + c + \" \"\n",
+ "print \"String you entered is: \", my_str"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string. Enter quit to stop\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Java\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "is\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Good\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "quit\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "String you entered is: Java is Good \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 7.2, page no. 109"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Do.. While loop\n",
+ "\n",
+ "\n",
+ "row = 1\n",
+ "column = 1\n",
+ "\n",
+ "while row <= 3:\n",
+ " column = 1\n",
+ " while column <= 3:\n",
+ " y = row * column\n",
+ " print \" \", y,\n",
+ " column += 1\n",
+ " print \"\"\n",
+ " row += 1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1 2 3 \n",
+ " 2 4 6 \n",
+ " 3 6 9 \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 7.3, page no. 112"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "print \"2 to power-n n 2 to power n\"\n",
+ "p = 1\n",
+ "for n in range(0,10):\n",
+ " if n == 0:\n",
+ " p = 1\n",
+ " else:\n",
+ " p = p * 2\n",
+ " q = float(1.0/p)\n",
+ " print q,\" \",n,\" \",p"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2 to power-n n 2 to power n\n",
+ "1.0 0 1\n",
+ "0.5 1 2\n",
+ "0.25 2 4\n",
+ "0.125 3 8\n",
+ "0.0625 4 16\n",
+ "0.03125 5 32\n",
+ "0.015625 6 64\n",
+ "0.0078125 7 128\n",
+ "0.00390625 8 256\n",
+ "0.001953125 9 512\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 7.4, page no. 116"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "states = [\"TamilNadu\", \"AndhraPradesh\", \"UttarPradesh\", \"Rajasthan\"]\n",
+ "for i in range(0, len(states)):\n",
+ " print \"Standard for-loop: state name: \", states[i]\n",
+ "print \"\"\n",
+ "for state in states:\n",
+ " print \"Enhanced for-loop: state name: \", state\n",
+ "\n",
+ "print \"\"\n",
+ "cities = []\n",
+ "cities.append(\"Delhi\")\n",
+ "cities.append(\"Mumbai\")\n",
+ "cities.append(\"Calcutta\")\n",
+ "cities.append(\"Chennai\")\n",
+ "\n",
+ "for i in range(0, len(cities)):\n",
+ " print \"Standard for-loop: state name: \", cities[i]\n",
+ "print \"\"\n",
+ "for city in cities:\n",
+ " print \"Enhanced for-loop: enhanced name: \", city\n",
+ "\n",
+ "print \"\\nIn Collection\"\n",
+ "for i in cities:\n",
+ " print i\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Standard for-loop: state name: TamilNadu\n",
+ "Standard for-loop: state name: AndhraPradesh\n",
+ "Standard for-loop: state name: UttarPradesh\n",
+ "Standard for-loop: state name: Rajasthan\n",
+ "\n",
+ "Enhanced for-loop: state name: TamilNadu\n",
+ "Enhanced for-loop: state name: AndhraPradesh\n",
+ "Enhanced for-loop: state name: UttarPradesh\n",
+ "Enhanced for-loop: state name: Rajasthan\n",
+ "\n",
+ "Standard for-loop: state name: Delhi\n",
+ "Standard for-loop: state name: Mumbai\n",
+ "Standard for-loop: state name: Calcutta\n",
+ "Standard for-loop: state name: Chennai\n",
+ "\n",
+ "Enhanced for-loop: enhanced name: Delhi\n",
+ "Enhanced for-loop: enhanced name: Mumbai\n",
+ "Enhanced for-loop: enhanced name: Calcutta\n",
+ "Enhanced for-loop: enhanced name: Chennai\n",
+ "\n",
+ "In Collection\n",
+ "Delhi\n",
+ "Mumbai\n",
+ "Calcutta\n",
+ "Chennai\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 7.5, page no. 120"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "for i in range(1,100):\n",
+ " print \" \"\n",
+ " if i >= 10:\n",
+ " break\n",
+ " for j in range(1, 100):\n",
+ " print \" * \",\n",
+ " if j == i:\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ " * \n",
+ " * * \n",
+ " * * * \n",
+ " * * * * \n",
+ " * * * * * \n",
+ " * * * * * * \n",
+ " * * * * * * * \n",
+ " * * * * * * * * \n",
+ " * * * * * * * * * \n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter8.ipynb b/Programming_With_Java_A_Primer/chapter8.ipynb
new file mode 100644
index 00000000..85db9833
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter8.ipynb
@@ -0,0 +1,319 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:8fe09a5e04ffadf78c63c627faf8ee708ea9328cbf18aa701a8f4bd8d5b46292"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: Classes, Objects & Methods"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 8.1, page no. 132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "class Rectangle:\n",
+ " length = 0\n",
+ " width = 0\n",
+ " def getData(self, x, y):\n",
+ " self.length = x\n",
+ " self.width = y\n",
+ " def rectArea(self):\n",
+ " area = self.length * self.width\n",
+ " return area\n",
+ "\n",
+ "rect1 = Rectangle()\n",
+ "rect1.length = 15\n",
+ "rect1.width = 10\n",
+ "rect2 = Rectangle()\n",
+ "area1 = rect1.length*rect1.width\n",
+ "rect2.getData(20,12)\n",
+ "area2 = rect2.rectArea()\n",
+ "print \"Area1 = \", area1\n",
+ "print \"Area2 = \", area2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Area1 = 150\n",
+ "Area2 = 240\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 8.2, page no. 134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "class Rectangle:\n",
+ " length = 0\n",
+ " width = 0\n",
+ " def __init__(self, x=0, y=0):\n",
+ " self.length = x\n",
+ " self.width = y\n",
+ " def rectArea(self):\n",
+ " return self.length * self.width\n",
+ "rect1 = Rectangle(15, 10)\n",
+ "area1 = rect1.rectArea()\n",
+ "print \"Area1 = \", area1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area1 = 150\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 8.3, page no. 136"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#there are no static methods in Python, we will use normal methods instead\n",
+ "\n",
+ "class MathOperations:\n",
+ " def mul(self, x, y):\n",
+ " return x*y\n",
+ " def divide(self, x, y):\n",
+ " return x/y\n",
+ "\n",
+ "obj = MathOperations()\n",
+ "a = obj.mul(4.0,5.0)\n",
+ "b = obj.divide(a,2.0)\n",
+ "print \"b = \", b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "b = 10.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 8.3, page no. 137"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "class Nesting:\n",
+ " m = 0\n",
+ " n = 0\n",
+ " def __init__(self, x, y):\n",
+ " self.m = x\n",
+ " self.n = y\n",
+ " def largest(self):\n",
+ " if(self.m>=self.n):\n",
+ " return self.m\n",
+ " else:\n",
+ " return self.n\n",
+ " def display(self):\n",
+ " large = self.largest()\n",
+ " print \"Largest Value: \", large\n",
+ "\n",
+ "nest = Nesting(50, 40)\n",
+ "nest.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Largest Value: 50\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 8.4, page no. 139"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "class Room(object):\n",
+ " def __init__(self, x, y):\n",
+ " self.length = x\n",
+ " self.breadth = y\n",
+ " def area(self):\n",
+ " return self.length*self.breadth\n",
+ "\n",
+ "class BedRoom(Room):\n",
+ " height = 0\n",
+ " def __init__(self, x, y, z):\n",
+ " Room.__init__(self, x, y)\n",
+ " self.height = z\n",
+ " def volume(self):\n",
+ " return self.length*self.breadth*self.height\n",
+ "\n",
+ "room1 = BedRoom(14, 12, 10)\n",
+ "area1 = room1.area()\n",
+ "volume1 = room1.volume()\n",
+ "print \"Area = \", area1\n",
+ "print \"Volume = \", volume1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area = 168\n",
+ "Volume = 1680\n"
+ ]
+ }
+ ],
+ "prompt_number": 63
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 8.6, page no. 142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "class Super(object):\n",
+ " x = 0\n",
+ " def __init__(self, x):\n",
+ " self.x = x\n",
+ " def display(self):\n",
+ " print \"Super x = \", self.x\n",
+ "\n",
+ "class Sub(Super):\n",
+ " y = 0\n",
+ " def __init__(self, x, y):\n",
+ " Super.__init__(self, x)\n",
+ " self.y = y\n",
+ " def display(self):\n",
+ " print \"Super x = \", self.x\n",
+ " print \"Sub y = \", self.y\n",
+ "s1 = Sub(100, 200)\n",
+ "s1.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Super x = 100\n",
+ "Sub y = 200\n"
+ ]
+ }
+ ],
+ "prompt_number": 65
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 8.7, page no. 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "class Exampleprg:\n",
+ " def __init__(self, *args):\n",
+ " for arg in args:\n",
+ " print \"Hello \", arg\n",
+ "\n",
+ "e = Exampleprg(\"John\", \"David\", \"Suhel\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello John\n",
+ "Hello David\n",
+ "Hello Suhel\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/chapter9.ipynb b/Programming_With_Java_A_Primer/chapter9.ipynb
new file mode 100644
index 00000000..af0b5898
--- /dev/null
+++ b/Programming_With_Java_A_Primer/chapter9.ipynb
@@ -0,0 +1,475 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5c730697085cba47efcd5224cc57d70aca1160f9a5e192f67596eb53b4b5b4af"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9: Arrays, Strings & Vectors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 9.1, page no. 157"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "number = [55, 40, 80, 65, 71]\n",
+ "print \"Given List: \",\n",
+ "for num in number:\n",
+ " print num,\n",
+ "number = sorted(number)[: : -1]\n",
+ "print \"\\nSorted List: \",\n",
+ "for num in number:\n",
+ " print num,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Given List: 55 40 80 65 71 \n",
+ "Sorted List: 80 71 65 55 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 9.2, page no. 160"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "rows = 20\n",
+ "columns = 20\n",
+ "product = [[0 for x in range(rows)] for x in xrange(columns)]\n",
+ "print \"Multiplication Table\"\n",
+ "for i in range(10, rows):\n",
+ " for j in range(10, columns):\n",
+ " product[i][j] = i*j\n",
+ " print \" \", product[i][j],\n",
+ " print \" \""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication Table\n",
+ " 100 110 120 130 140 150 160 170 180 190 \n",
+ " 110 121 132 143 154 165 176 187 198 209 \n",
+ " 120 132 144 156 168 180 192 204 216 228 \n",
+ " 130 143 156 169 182 195 208 221 234 247 \n",
+ " 140 154 168 182 196 210 224 238 252 266 \n",
+ " 150 165 180 195 210 225 240 255 270 285 \n",
+ " 160 176 192 208 224 240 256 272 288 304 \n",
+ " 170 187 204 221 238 255 272 289 306 323 \n",
+ " 180 198 216 234 252 270 288 306 324 342 \n",
+ " 190 209 228 247 266 285 304 323 342 361 \n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 9.3, page no. 163"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "name = [\"Madras\", \"Delhi\", \"Ahmedabad\", \"Calcutta\", \"Bombay\"]\n",
+ "name = sorted(name)\n",
+ "\n",
+ "for n in name:\n",
+ " print n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ahmedabad\n",
+ "Bombay\n",
+ "Calcutta\n",
+ "Delhi\n",
+ "Madras\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 9.4, page no. 164"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "aString = \"Object language\"\n",
+ "print \"Original String : \", aString\n",
+ "print \"Length of String: \", len(aString)\n",
+ "for i in range(len(aString)):\n",
+ " print \"Character at position: %d is %c\" %(i+1,aString[i])\n",
+ "\n",
+ "aString = aString.split(\" \")\n",
+ "aString.insert(1, \"-Oriented\") \n",
+ "aString = \" \".join(aString)\n",
+ "print \"Modified String: \", aString\n",
+ "aString = aString + \" improves security.\"\n",
+ "print \"Appended String: \", aString\n",
+ "\n",
+ "# Note : In python, string is immutable so we can not edit/update it."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Original String : Object language\n",
+ "Length of String: 15\n",
+ "Character at position: 1 is O\n",
+ "Character at position: 2 is b\n",
+ "Character at position: 3 is j\n",
+ "Character at position: 4 is e\n",
+ "Character at position: 5 is c\n",
+ "Character at position: 6 is t\n",
+ "Character at position: 7 is \n",
+ "Character at position: 8 is l\n",
+ "Character at position: 9 is a\n",
+ "Character at position: 10 is n\n",
+ "Character at position: 11 is g\n",
+ "Character at position: 12 is u\n",
+ "Character at position: 13 is a\n",
+ "Character at position: 14 is g\n",
+ "Character at position: 15 is e\n",
+ "Modified String: Object -Oriented language\n",
+ "Appended String: Object -Oriented language improves security.\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 9.5, page no. 166"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#vector is an array only in Python & commandline arguments cannot be taken in IPython Notebook\n",
+ "\n",
+ "v1 = []\n",
+ "v1.append(\"Ada\")\n",
+ "v1.append(\"BASIC\")\n",
+ "v1.append(\"COBOL\")\n",
+ "v1.append(\"C++\")\n",
+ "v1.append(\"FORTRAN\")\n",
+ "v1.append(\"Python\")\n",
+ "\n",
+ "print \"List of Languages: \"\n",
+ "for ele in v1:\n",
+ " print ele"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "List of Languages: \n",
+ "Ada\n",
+ "BASIC\n",
+ "COBOL\n",
+ "C++\n",
+ "FORTRAN\n",
+ "Python\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 9.6, page no. 169"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "There is no wrapper class in Python.\n",
+ "\"\"\"\n",
+ "\n",
+ "principalAmount = float(raw_input(\"Enter Principal Amount: \"))\n",
+ "interestRate = float(raw_input(\"Enter Interest Rate: \"))\n",
+ "numYears = float(raw_input(\"Enter Number of Years: \"))\n",
+ "\n",
+ "def loan(p, r, n):\n",
+ " year = 1\n",
+ " my_sum = p\n",
+ " while year<=n:\n",
+ " my_sum = my_sum*(1+r)\n",
+ " year += 1\n",
+ " return my_sum\n",
+ "\n",
+ "def printline():\n",
+ " for i in range(1, 30):\n",
+ " print \"-\",\n",
+ " print \"\"\n",
+ "\n",
+ "value = loan(principalAmount, interestRate, numYears)\n",
+ "printline()\n",
+ "print \"Final Value: \", round(value,2)\n",
+ "printline()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Principal Amount: 5000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Interest Rate: 0.15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Number of Years: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n",
+ "Final Value: 8745.03\n",
+ "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 9.7, page no. 195"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "There is no inbuilt module to use stack as it is done in the book \"java.util.stack\". We will use normal lists as stack in Python\n",
+ "\"\"\"\n",
+ "\n",
+ "stack = []\n",
+ "stack.append(10)\n",
+ "stack.append(20)\n",
+ "stksum1 = stack.pop()\n",
+ "stksum2 = stack.pop()\n",
+ "stksum = stksum1 + stksum2\n",
+ "print \"The top most element from the stack is: \", stksum2\n",
+ "print \"The next top most element from the stack is: \", stksum1\n",
+ "print \"The sum of two elements from the stack is: \", stksum"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The top most element from the stack is: 10\n",
+ "The next top most element from the stack is: 20\n",
+ "The sum of two elements from the stack is: 30\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 9.8, page no. 196"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "Enum is not supported by default in Python 2.X version. It has been backported to various versions of Python.\n",
+ "But, the package has to be installed seperately.\n",
+ "Using normal class here.\n",
+ "\"\"\"\n",
+ "\n",
+ "class WorkingDays:\n",
+ " Sunday = 0\n",
+ " Monday = 1\n",
+ " Tuesday = 2\n",
+ " Wednesday = 3\n",
+ " Thursday = 4\n",
+ " Friday = 5\n",
+ " Saturday = 6\n",
+ "\n",
+ "def weekend(d):\n",
+ " if d == WorkingDays.Sunday:\n",
+ " print \"Value = Sunday is a Holiday\"\n",
+ " elif d == WorkingDays.Monday:\n",
+ " print \"Value = Monday is a working day\"\n",
+ " elif d == WorkingDays.Tuesday:\n",
+ " print \"Value = Tuesday is a working day\"\n",
+ " elif d == WorkingDays.Wednesday:\n",
+ " print \"Value = Wednesday is a working day\"\n",
+ " elif d == WorkingDays.Thursday:\n",
+ " print \"Value = Thursday is a working day\" \n",
+ " elif d == WorkingDays.Friday:\n",
+ " print \"Value = Friday is a working day\"\n",
+ " else:\n",
+ " print \"Value = Saturday is a working day\"\n",
+ "\n",
+ "for i in range(WorkingDays.Sunday, WorkingDays.Saturday+1):\n",
+ " weekend(i)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value = Sunday is a Holiday\n",
+ "Value = Monday is a working day\n",
+ "Value = Tuesday is a working day\n",
+ "Value = Wednesday is a working day\n",
+ "Value = Thursday is a working day\n",
+ "Value = Friday is a working day\n",
+ "Value = Saturday is a working day\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example 9.9, page no. 199"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\"\"\"\n",
+ "There is no concept of annotations in Python\n",
+ "\"\"\"\n",
+ "\n",
+ "class MySingle:\n",
+ " value = 0\n",
+ " def __init__(self, x):\n",
+ " self.value = 100\n",
+ " def display(self):\n",
+ " print \"The value is: \", self.value\n",
+ "\n",
+ "ob = MySingle(100)\n",
+ "try:\n",
+ " ob.display()\n",
+ "except:\n",
+ " print \"No such method found...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value is: 100\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Programming_With_Java_A_Primer/screenshots/chapter13.png b/Programming_With_Java_A_Primer/screenshots/chapter13.png
new file mode 100644
index 00000000..3d211895
--- /dev/null
+++ b/Programming_With_Java_A_Primer/screenshots/chapter13.png
Binary files differ
diff --git a/Programming_With_Java_A_Primer/screenshots/chapter18.png b/Programming_With_Java_A_Primer/screenshots/chapter18.png
new file mode 100644
index 00000000..68c1c7e5
--- /dev/null
+++ b/Programming_With_Java_A_Primer/screenshots/chapter18.png
Binary files differ
diff --git a/Programming_With_Java_A_Primer/screenshots/chapter9.png b/Programming_With_Java_A_Primer/screenshots/chapter9.png
new file mode 100644
index 00000000..9e456528
--- /dev/null
+++ b/Programming_With_Java_A_Primer/screenshots/chapter9.png
Binary files differ
diff --git a/Water_and_Wastewater_Engineering/README.txt b/Water_and_Wastewater_Engineering/README.txt
new file mode 100644
index 00000000..64c521dc
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Sailesh Baria
+Course: mca
+College/Institute/Organization: Smart-Apps Solution Pvt Ltd
+Department/Designation: Developer
+Book Title: Water and Wastewater Engineering
+Author: G. M. Fair, J. C. Geyer and D. A. Okun
+Publisher: John Wiley, NewYork
+Year of publication: 1966
+Isbn: 9780471251309
+Edition: 11 \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch10.ipynb b/Water_and_Wastewater_Engineering/ch10.ipynb
new file mode 100644
index 00000000..f78608b7
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch10.ipynb
@@ -0,0 +1,111 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:a8b74fc9d03d0c351dd92e0bc3a167aee10debeb1676b07b6cf10a252a49f523"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10 : Groundwater Collection"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.1 Page No : 10-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "w1 = 1000.\t#ft\n",
+ "w2 = 2000.\t#ft\n",
+ "r = 700.\t#gpm\n",
+ "d = 10. \t#days\n",
+ "q = 2\t #ft\n",
+ "u = 1.87*((3.4*10**-5)/(3.2*10**4))*(d**6/d)\t#ft\n",
+ "W = 7.94\t#ft\n",
+ "p = 114.6*(7*10**2)*W/(3.2*10**4)\t#ft\n",
+ "U = 1.87*((3.4*10**-5)/(3.2*10**4))*(4*d**6/d)\t#ft\n",
+ "Wu = 6.55\t#ft\n",
+ "P = 114.6*(7*10**2)*Wu/(3.2*10**4)\t#ft\n",
+ "R = 54\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "W1 = R+p+P\t#ft\n",
+ "D = R+q*p\t#ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the expected drawndown the first well is pumped at a rate = %.0f ft'%(W1)\n",
+ "print 'the drawdown in each well all the three are pupped at a rate = %.0f ft'%(D)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the expected drawndown the first well is pumped at a rate = 90 ft\n",
+ "the drawdown in each well all the three are pupped at a rate = 94 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.3 Page No : 10-19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "g = 20\t#ft\n",
+ "k = 10**-1\t#cm/sec\n",
+ "g1 = 3.28*10**-3\t#fps\n",
+ "w = 2\t#ft\n",
+ "w1 = 30\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "Q = (1./2)*(g1)*((g**2)-(2**2))/(w1)\t#cfs\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the flow into a foot of gallery = %.1e cfs'%(Q)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the flow into a foot of gallery = 2.2e-02 cfs\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch11.ipynb b/Water_and_Wastewater_Engineering/ch11.ipynb
new file mode 100644
index 00000000..66e86589
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch11.ipynb
@@ -0,0 +1,227 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d97ef885e741db81adc7f9703c96d41639df30eb154ebfc4a587f4f7ba56c3d8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11 : Surface-Water Collection"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.1 Page No : 11-20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "s = 20.\t#mph\n",
+ "t = 90.\t#min\n",
+ "w = 1.31\t#ft\n",
+ "h = 7.5\t#miles\n",
+ "h1 = 0.22\t#ft\n",
+ "t1 = 1100.\t#min\n",
+ "t2 = 6.0\t#min\n",
+ "p = 32.2\t#ft\n",
+ "l = 5.12\t#length\n",
+ "l1 = 2.8\t#length\n",
+ "p1 = 1400.\t#ft\n",
+ "d = 73.\t#depth\n",
+ "h3 = 2.06\t#ft\n",
+ "e = 173.0\t#ft\n",
+ "hi = 0.2\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "W = s*w\t#mph\n",
+ "hs = h1*((W)**2/p)**0.53*h**0.47\t#ft\n",
+ "Ts = t2*(W/p)**0.44*(h/p)**0.28\t#sec\n",
+ "Td = t1*h/(p*Ts)\t#min\n",
+ "Ls = l1/(l*(Ts)**2)\t#ft\n",
+ "D = d/(l*(Ts)**2)\t#ft\n",
+ "H = (W)**2*(h*(1/(p1*d)))\t#ft\n",
+ "hr = h3*l1\t#ft\n",
+ "M = e+hi+hr\t#ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the overwater wind speed = %.0f mph'%(W)\n",
+ "print 'the significant wave height = %.1f ft'%(hs)\n",
+ "print 'the significant wave period = %.1f sec'%(Ts)\n",
+ "print 'the minimum wind duration required to reach the significant wave height = %.0f min'%(Td)\n",
+ "print 'the significant wave lenght adn steepness = %.3f ft'%(Ls)\n",
+ "print 'the reservoir depth ratio = %.1f ft'%(D)\n",
+ "print 'the wind tide or set up = % f ft'%(H)\n",
+ "print 'the run up = %.1f ft'%(hr)\n",
+ "print 'the maximum elevation reached by the waves = %.1f ft'%(M)\n",
+ "\n",
+ "# rounding off error. please check."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the overwater wind speed = 26 mph\n",
+ "the significant wave height = 2.9 ft\n",
+ "the significant wave period = 3.6 sec\n",
+ "the minimum wind duration required to reach the significant wave height = 70 min\n",
+ "the significant wave lenght adn steepness = 0.041 ft\n",
+ "the reservoir depth ratio = 1.1 ft\n",
+ "the wind tide or set up = 0.050375 ft\n",
+ "the run up = 5.8 ft\n",
+ "the maximum elevation reached by the waves = 179.0 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.2 Page No : 11-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "g = 264\t#quartz\n",
+ "p = 0.39\t#percent\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "S = (1-p)*(g-1)\t#in\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the hydraulic gradient and seepage velocity = %.2f in'%(S)\n",
+ "#incorrect answer in textbook"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the hydraulic gradient and seepage velocity = 160.43 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.3 Page No : 11-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "w = 40\t#ft\n",
+ "k = 2*10**-3\t#cm/sec\n",
+ "p = 3.28*10**-3\t#cfs\n",
+ "h = 6.47*10**5\t#gpd\n",
+ "p1 = 0.433\t#ft\n",
+ "m = 9\t#ft\n",
+ "delh = w/(18*9)\t#in\n",
+ "k1 = 4.94*10**-4\t#cm/sec\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "Q = k*p*w*(9./18)\t#cfs\n",
+ "Q1 = Q*h\t#gpd/ft width\n",
+ "P = (1-8./18)*w*p1\t#Psig\n",
+ "H = k1/k\t#in\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the seepage through each foot width of the foundation = %.0f gpd/ft/ width'%(Q1*10)\n",
+ "print 'the excess hydrostatic pressure on the upstream side of the bottom of the sheet pilling = %.2f Psig'%(P)\n",
+ "print 'the maximum hydraulic gradient and its relations to the coeeficent = %.2f in'%(H)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the seepage through each foot width of the foundation = 849 gpd/ft/ width\n",
+ "the excess hydrostatic pressure on the upstream side of the bottom of the sheet pilling = 9.62 Psig\n",
+ "the maximum hydraulic gradient and its relations to the coeeficent = 0.25 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.4 Page No : 11-13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "d = 120\t#ft\n",
+ "w = 16\t#ft\n",
+ "d1 = 120/0.8\t#ft\n",
+ "p = 60*0.8\t#ft\n",
+ "h = 2\t#ft\n",
+ "v = 18.74*0.8\t#ft\n",
+ "s = 95.23\t#ft\n",
+ "s1 = 0.8\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "W = d-h*p\t#ft\n",
+ "S = s*s1\t#ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'in succession from the intersection of the upstream slop = %.2f ft'%(S)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "in succession from the intersection of the upstream slop = 76.18 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch12.ipynb b/Water_and_Wastewater_Engineering/ch12.ipynb
new file mode 100644
index 00000000..752b1d0d
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch12.ipynb
@@ -0,0 +1,236 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:14bd2b02adda106b7feb66c435425687c9047c3f660e50bfc5fca311a000dc14"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12 : Water Transmission"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.1 Page No : 12-9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "c = 100\t#in\n",
+ "a = 10\t#in\n",
+ "Q = 0.976\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "G = a*Q\t#ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the graphical basic = %.2f ft'%(G)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the graphical basic = 9.76 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.2 Page No : 12-9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "a = 27.6\t#sq ft\n",
+ "h = 1.37\t#ft\n",
+ "d = 1.53*(27.9)**0.38*(1.36)**0.24\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "R = d/4\t#ft\n",
+ "A = (math.pi*d**2)/4\t#sq ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'The diameter hydraulics radius and area of the hydraulically equivalent circular conduit = %.1f sq ft'%(A)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The diameter hydraulics radius and area of the hydraulically equivalent circular conduit = 26.7 sq ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.3 Page No : 12-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "h1 = 13.5\t#ft\n",
+ "h2 = 19.0\t#ft\n",
+ "h3 = 27.5\t#ft\n",
+ "c1 = 2.0*10**4\t#ft\n",
+ "c2 = 2.1*10**4\t#ft\n",
+ "c3 = 2.2*10**4\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "H = h1+h2+h3\t#ft\n",
+ "C = c1+c2+c3\t#ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the most economical distributions of the available head = %.1e ft'%(C)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the most economical distributions of the available head = 6.3e+04 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.4 Page No : 12-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialisation of variables\n",
+ "p = 60\t#in\n",
+ "h = 20\t#percent\n",
+ "a = 1000\t#ft\n",
+ "h1 = 40\t#percent\n",
+ "c = 0.5\t#ft\n",
+ "p1 = 14.3\t#ft\n",
+ "p2 = 6.1\t#ft\n",
+ "d = 11.7*10**-2\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "deltaV = 26.7 - 18.3 # fps\n",
+ "eq = 3.9*10**-2 * math.sqrt(deltaV/c)*(0.426)**0.356\n",
+ "D = p*eq\t #ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the air valve with a discharge the change in slop = %.2f in.'%(D)\n",
+ "\n",
+ "# note : slightly different because of rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the air valve with a discharge the change in slop = 7.08 in.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.5 Page No : 12-29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "p = 90.\t #deg\n",
+ "h = 48.\t #in\n",
+ "p1 = 100.\t#psig\n",
+ "P = (1/2*math.pi)*h**2*p1*0.7071\t#lb\n",
+ "r = 3000./54-31\t#ft\n",
+ "l = 170.\t#in\n",
+ "b = 6.5*10**-6\t#ft\n",
+ "w = 46. \t#ft\n",
+ "w1 = 1000.\t #ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "s = b*w*30*10**6\n",
+ "D = (1./4*math.pi)*h**2*p1\t#lb\n",
+ "P = (r)*h**2\t#lb\n",
+ "T = math.pi*h*(1/4)*s\t#lb\n",
+ "T1 = (1./2)*l\t#tons\n",
+ "Del = b*w*w1\t#ft per\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'The expansion and contraction of the steel line can be as great as = %.1f ft per 1000ft of length, if unrestrained'%(Del)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The expansion and contraction of the steel line can be as great as = 0.3 ft per 1000ft of length, if unrestrained\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch13.ipynb b/Water_and_Wastewater_Engineering/ch13.ipynb
new file mode 100644
index 00000000..b7870ef8
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch13.ipynb
@@ -0,0 +1,229 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:ee62a0db1d14e1ef03e248f6d6042a1fdd2b0d432d5212bd4ea1bd700bb94f91"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13 : Water Distribution"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.2 Page No : 13-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "p1 = 7.8\t#ft\n",
+ "p2 = 6.0\t#ft\n",
+ "p3 = 7.4\t#ft\n",
+ "p4 = 6.5\t#ft\n",
+ "p = 7.6\t#ft\n",
+ "h = 1.0\t#ft\n",
+ "h1 = 6.7\t#ft\n",
+ "p5 = 3.3\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "D = p1-p2\t#mgd\n",
+ "D1 = p1-p3\t#mgd\n",
+ "D2 = p-p4\t#mgd\n",
+ "D3 = p4+h\t#mgd\n",
+ "D4 = h1-p5\t#mgd\n",
+ "D5 = 2.0 - 1.6\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print \"1 . Deficiency : %.1f mgd\"%D\n",
+ "print \"2 . Deficiency : %.1f mgd\"%D1\n",
+ "print \"3 . Deficiency : %.1f mgd\"%D2\n",
+ "print \" Net added capacity = %.1f mgd\"%(1.2 - 0.2)\n",
+ "print \" Reinforced capacity : %.1f mgd\"%(D3)\n",
+ "print \"4 . Deficiency : %.1f mgd\"%D4\n",
+ "print \" Net added capacity : %.1f mgd\"%(p5 - 0.3)\n",
+ "print \" Reinforced capacity : %.1f mgd\"%(p5+3)\n",
+ "print \"5. Deficiency : %.1f mgd\"%D5 \n",
+ "print \" Net added capacity : %.1f mgd\"%(0.6 - 0.2 )\n",
+ "print \" Reinforced capacity : %.1f mgd\"%(1.6+0.4)\n",
+ "print 'the demand is taken = %.1f mgd'%(D3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 . Deficiency : 1.8 mgd\n",
+ "2 . Deficiency : 0.4 mgd\n",
+ "3 . Deficiency : 1.1 mgd\n",
+ " Net added capacity = 1.0 mgd\n",
+ " Reinforced capacity : 7.5 mgd\n",
+ "4 . Deficiency : 3.4 mgd\n",
+ " Net added capacity : 3.0 mgd\n",
+ " Reinforced capacity : 6.3 mgd\n",
+ "5. Deficiency : 0.4 mgd\n",
+ " Net added capacity : 0.4 mgd\n",
+ " Reinforced capacity : 2.0 mgd\n",
+ "the demand is taken = 7.5 mgd\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.3 Page No : 13-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "w = 500. \t#ft\n",
+ "p = 20. \t#psig\n",
+ "h = 40. \t#psig\n",
+ "h1 = 1000. \t#in\n",
+ "q = 1250.\t#ft\n",
+ "g = 2.308/0.75\t#ft\n",
+ "g1 = 2.308/1.00\t#ft\n",
+ "s = 5200.\t#gpm\n",
+ "a = 250. \t#gpm\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "H = (h1-(1./2)*(w))\t#ft\n",
+ "H1 = (h-p)*g\t#percent\n",
+ "Q = (q-(1./2)*(w))\t#ft\n",
+ "Q1 = (h-p)*g1\t#percent\n",
+ "S = s/a\t#gpm\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the number of standard fire streams = %.1f gpm'%(S)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the number of standard fire streams = 20.8 gpm\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.6 Page No : 13-21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "h1 = 2.1*3\t#ft\n",
+ "h2 = 2.1\t#ft\n",
+ "h = 8.4\t#ft\n",
+ "p = 1000.\t#ft\n",
+ "h3 = 5.7\t#ft\n",
+ "h4 = 4.2*3\t#ft\n",
+ "q = 4.2\t#ft\n",
+ "s = 1.68\t#ft\n",
+ "q1 = 1.33\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "A = p*h/h2\t#ft\n",
+ "B = p*(h3+h4)/q\t#ft\n",
+ "C = p*(h1+h2)/s\t#ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the equilent pipe for the Hazen willians coefficent = %.0f ft'%(A)\n",
+ "print 'the equilent pipe for the Hazen willians coefficent = %.0f ft'%(round(B,-1))\n",
+ "print 'the equilent pipe for the Hazen willians coefficent = %.0f ft'%(C)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the equilent pipe for the Hazen willians coefficent = 4000 ft\n",
+ "the equilent pipe for the Hazen willians coefficent = 4360 ft\n",
+ "the equilent pipe for the Hazen willians coefficent = 5000 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.8 Page No : 13-27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "d = 10\t#hr\n",
+ "p = 50000\t#in\n",
+ "a = 7.5\t#mgd\n",
+ "w = 0.75\t#mg\n",
+ "s = 5.03\t#mg\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "S = s/w\t#mg\n",
+ "P = S-s\t#mg\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'a steady gravity supply equal to maximum daily = %.2f mg'%(P)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a steady gravity supply equal to maximum daily = 1.68 mg\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch14.ipynb b/Water_and_Wastewater_Engineering/ch14.ipynb
new file mode 100644
index 00000000..2498efee
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch14.ipynb
@@ -0,0 +1,550 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:b3817b87ab26f1af6cc1ad821b24c26f6f6f9d19671fc5e655b736548ecb040a"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 14 : Wastewater Flows"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.1 Page No : 14-4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "n = 0.013\t#ft\n",
+ "s = 4.90\t#ft\n",
+ "v = 0.590\t#ft\n",
+ "d = 0.463\t#ft\n",
+ "w = 3.9*10**-2\t#ft\n",
+ "p = 1.696\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "V = s*v\t#fps\n",
+ "Q = s*d\t#cfs\n",
+ "N = (w*p)**2*1000\t#percent\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the velocity of flow and rate of discharge = %.2f percent'%(N)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the velocity of flow and rate of discharge = 4.38 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.2 Page No : 14-7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "v = 1.34\t#fps\n",
+ "s = 3.7*10**-3\t#fps\n",
+ "k = 0.8\t#ft\n",
+ "r = 20\t#ft\n",
+ "k1 = 0.04\t#ft\n",
+ "v = 3.0\t#fps\n",
+ "v1 = 5.0\t#fps\n",
+ "d = 10**-1\t#ft\n",
+ "d1 = 1.34\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "V = round((1.49/1.3*10**-2)*(1./4)**(1./6)*(k1*d/30.48*(2.65-1)/1)**(1./2) * 10000,2)\n",
+ "# for v = 3\n",
+ "v1 = 3.\n",
+ "D1 = d*(v1/V)**2\n",
+ "\n",
+ "# for v = 5\n",
+ "v2 = 5\n",
+ "D2 = d*(v2/V)**2\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'For velocity = %d, the gradient at the which coarse quartz = %.1f cm'%(v1,D1) #incorrect answer in the textbook\n",
+ "print \"For velocity = %d, the gradient at the which coarse quartz = %.1f cm\"%(v2,D2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For velocity = 3, the gradient at the which coarse quartz = 0.5 cm\n",
+ "For velocity = 5, the gradient at the which coarse quartz = 1.4 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.3 Page No : 14-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "v = 2.5\t#fps\n",
+ "q = 0.873\t#cfs\n",
+ "s = 5.20\t#percent\n",
+ "a = 0.252\t#ft\n",
+ "r = 0.684\t#ft\n",
+ "r1 = 1.46\t#ft\n",
+ "v1 = 0.776\t#ft\n",
+ "q1 = 0.196\t#ft\n",
+ "n = 0.78\t#ft\n",
+ "R = 0.939\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "V = v1*v\t#fps\n",
+ "Q = q1*q\t#cfs\n",
+ "R1 = r1*s\t#percent\n",
+ "Vs = R*v\t#ft\n",
+ "N = n*Vs\t#fps\n",
+ "Qs = a*R*q\t#cfs\n",
+ "N1 = n*Qs\t#cfs\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the required grades and associated velocity and rates = %.3f cfs'%(V)\n",
+ "print 'the depth and a grade = %.3f cfs'%(Q)\n",
+ "print 'the self cleaning flow = %.3f cfs'%(N1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the required grades and associated velocity and rates = 1.940 cfs\n",
+ "the depth and a grade = 0.171 cfs\n",
+ "the self cleaning flow = 0.161 cfs\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.4 Page No : 14-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "Q = 0.873\t#cfs\n",
+ "s = 5.20\t#percent\n",
+ "d = 0.161\t#cfs\n",
+ "q1 = 0.185\t#ft\n",
+ "d2 = 2.5\t#ft\n",
+ "v = 0.91\t#ft\n",
+ "s1 = 1.70\t#ft\n",
+ "s3 = 1.46\t#ft\n",
+ "w = 0.185\t#ft\n",
+ "d1 = 0.30\t#ft\n",
+ "v1 = 0.732\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "q = d/Q\t#cfs\n",
+ "Vs = v*d2\t#fps\n",
+ "Ss = s1*s\t#percent\n",
+ "Va = v1*d2\t#fps\n",
+ "Ss1 = s3*s\t#percent\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the depth and velocity of flow and the required slop = %.1f percent'%(Ss1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the depth and velocity of flow and the required slop = 7.6 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.5 Page No : 14-13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "d1 = 0.67\t#ft\n",
+ "h1 = 2.00\t#ft\n",
+ "h2 = 4.04\t#ft\n",
+ "hv1 = 0.062\t#ft\n",
+ "hv2 = 0.254\t#ft\n",
+ "d = 0.19\t#ft\n",
+ "h = 0.2\t#ft\n",
+ "h1 = 0.04\t#ft\n",
+ "q = 0.644\t#ft\n",
+ "q1 = 0.65\t#ft\n",
+ "v = 0.92\t#ft\n",
+ "d2 = 6.5\t#ft\n",
+ "v1 = 3.69\t#ft\n",
+ "d3 = 0.542\t#ft\n",
+ "hv3 = 0.21\t#ft\n",
+ "delv = 0.15\t#ft\n",
+ "d4 = 0.02\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "H = d1+hv1\t#ft\n",
+ "H1 = d1+hv2\t#ft\n",
+ "he = h*d\t#ft\n",
+ "hi = d+h1\t#ft\n",
+ "H2 = d3+hv3\t#ft\n",
+ "he1 = h*delv\t#ft\n",
+ "S = d4+h1\t#ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the required slope = %.2f ft'%(hi)\n",
+ "print 'the lower sewer and the invert drop in the transition = %.2f ft'%(S)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the required slope = 0.23 ft\n",
+ "the lower sewer and the invert drop in the transition = 0.06 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.6 Page No : 14-17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "q = 60\t#cfs\n",
+ "D = 4\t#ft\n",
+ "w = 0.177\t#ft\n",
+ "s = 0.59\t#ft\n",
+ "h = 4.0\t#ft\n",
+ "d1 = 1.0\t#ft\n",
+ "v = 0.90\t#ft\n",
+ "d1 = 0.42\t#ft\n",
+ "h1 = 6.0\t#ft\n",
+ "h2 = 1.5\t#ft\n",
+ "dl = 1.3\t#ft\n",
+ "p = 0.41\t#ft\n",
+ "u = 0.8\t#ft\n",
+ "u1 = 3.2\t#ft\n",
+ "y = 0.45\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "H = s*D\t#ft\n",
+ "d2 = d1*D\t#ft\n",
+ "V = v*D\t#ft\n",
+ "P = p*D\t#ft\n",
+ "D1 = y*D\t#ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the critical depth = %.1f ft'%(H)\n",
+ "print 'the alternate stages for an energy = %.1f ft'%(V)\n",
+ "print 'the alternate stages for an energy head = %.1f ft'%(P)\n",
+ "print 'the lower alternate stage with upper alternate stage = %.1f ft'%(D1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the critical depth = 2.4 ft\n",
+ "the alternate stages for an energy = 3.6 ft\n",
+ "the alternate stages for an energy head = 1.6 ft\n",
+ "the lower alternate stage with upper alternate stage = 1.8 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.7 Page No : 14-19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "d = 106\t #cfs\n",
+ "q = 400.\t#cfs\n",
+ "d1 = 0.40\t#cfs\n",
+ "w = 10\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "D = d/q\t#cfs\n",
+ "D1 = d1*w\t#cfs\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the water level in this well rises = %.f ft'%(D1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the water level in this well rises = 4 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.8 Page No : 14-19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\t\n",
+ "#initialisation of variables\n",
+ "Q = (400/78.5*math.sqrt(10*32.2))**2\t#ft\n",
+ "N = 0.012\t#ft\n",
+ "d = 0.47\t#ft\n",
+ "q = 10\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "D = d*q\t#ft\n",
+ "\n",
+ "#RESULTS\n",
+ "print 'the water surface in the sewer when it is flowing at maximum capacity = %.1f ft'%(D)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the water surface in the sewer when it is flowing at maximum capacity = 4.7 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.9 Page No : 14-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\n",
+ "#initialisation of variable\n",
+ "g = math.sqrt(3)\t#ft\n",
+ "d = 5.67\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "C = g*d\t#ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'The rate of propagation of a discontinuous surge = %.1f ft'%(C)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The rate of propagation of a discontinuous surge = 9.8 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.10 Page No : 14-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#initialisation of variables\n",
+ "Q1 = 30\t#cfs\n",
+ "Q2 = 16\t#cfs\n",
+ "a = 32\t#sq ft\n",
+ "r = 1.6\t#ft\n",
+ "i = 10**-4\t#ft\n",
+ "n = 1.25*10**-2\t#ft\n",
+ "h2 = 0.50\t#ft\n",
+ "c = 3.33\t#ft\n",
+ "h1 = 5.20\t#ft\n",
+ "l = 72\t#ft\n",
+ "s = 12320\t#ft\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "L = s-l\t#ft\n",
+ "h1 = 0.49022 - 8.04*10**-5*l\t\n",
+ "#RESULTS\n",
+ "print 'the forchheimer s methos = %.0f ft'%(L)\n",
+ "print (Q1**2-Q2**2)/(2*32.2*a**2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the forchheimer s methos = 12248 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.11 Page No : 14-27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialisation of variables\n",
+ "q = 1.0\t#cfs\n",
+ "g = 2.0\t#percent\n",
+ "g1 = 5.6\t#percent\n",
+ "r = 0.015\t#cfs\n",
+ "w = 90.\t#percent\n",
+ "Q = 10*0.9*q\t#ft\n",
+ "p = 0.10\t#ft\n",
+ "h = 3.48*g1**(1./3)\t#ft\n",
+ "i = 5.6*10**-2\t\n",
+ "Q0 = 1.\n",
+ "s = 2*10**-2\n",
+ "n = 1.5*10**-2\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "q_l = round(1.87*i**0.569*(Q0/(math.sqrt(s)/n))**0.563,2)\n",
+ "l = q_l * 100\n",
+ "Q = 10*0.9*Q0\n",
+ "d = (3.48*32.2**(1./3)) * (q_l)**(2./3)\n",
+ "\n",
+ "#RESULTS\n",
+ "print 'The maximum depth of flow in the gutter = %.1f in'%(d)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum depth of flow in the gutter = 2.4 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch15.ipynb b/Water_and_Wastewater_Engineering/ch15.ipynb
new file mode 100644
index 00000000..5101dc59
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch15.ipynb
@@ -0,0 +1,221 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:209dfa66c415d9b6d77e6ef0fd2310df1d6593c2b60b5941934cee9e5b7d9fa6"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 15 : Wastewater Collection"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.1 Page No : 15-4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "q = 0.25\t#in\n",
+ "Q = 0.34\t#in\n",
+ "r = 0.76\t#in\n",
+ "v = 0.83\t#in\n",
+ "n = 0.78\t#in\n",
+ "r1 = 0.84\t#in\n",
+ "v1 = 0.70\t#in\n",
+ "w = 2\t#in\n",
+ "q1 = 0.056\t#in\n",
+ "d = 0.16\t#in\n",
+ "v2 = 0.53\t#in\n",
+ "n1 = 0.80\t#in\n",
+ "d1 = 0.18\t#in\n",
+ "n2 = 0.46\t#in\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "V = v*w\t#fps\n",
+ "N = v1*w\t#fps\n",
+ "V1 = v2*w\t#fps\n",
+ "V2 = n2*w\t#fps\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'The one fourth their full flow = %.2f fps'%(N)\n",
+ "print 'The one enghteenth their full flow = %.2f fps'%(V2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The one fourth their full flow = 1.40 fps\n",
+ "The one enghteenth their full flow = 0.92 fps\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.2 Page No : 15-9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "v = 2.5\t#fps\n",
+ "N = 0.015\t#fps\n",
+ "a = (40+27)\t#in\n",
+ "b = (40*27+27*19)/a\n",
+ "c = 0.440\t#cfs\n",
+ "w = 49*0.09/100\t#cfs\n",
+ "g = 0.008\t#percent\n",
+ "Q = 0.82\t#cfs\n",
+ "r = 0.795\t#cfs\n",
+ "t = 2.35*1.16\t#fps\n",
+ "d1 = 113.20-113.03\t#ft\n",
+ "d2 = 12\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "R = r/Q\t#cfs\n",
+ "D = g*r\t#in\n",
+ "D2 = d1*d2\t#in\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'The required capacity and find the slope size and hydraulic characteristics of the system = %.0f in'%(D2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The required capacity and find the slope size and hydraulic characteristics of the system = 2 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.3 Page No : 15-17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "p = 20\t#min\n",
+ "N = 0.012\t#in\n",
+ "k = 2.19\t#min\n",
+ "l = k+1.97\t#min\n",
+ "q = 340/(60*3.94)\t#min\n",
+ "r = 2.56*0.508\t#min\n",
+ "del1 = 0.42\t#min\n",
+ "j = 84.28\t#min\n",
+ "w1 = 0.92\t#min\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "r1 = r*k\t#cfs\n",
+ "w = p+q\t#min\n",
+ "G = j-del1\t#min\n",
+ "S = (G-w1)\t#min\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'The required capacity and find the slop size and hydraulic = %.2f min'%(S)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The required capacity and find the slop size and hydraulic = 82.94 min\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.4 Page No : 15-25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "a = 42.\t#in\n",
+ "d = 45.\t#mgd\n",
+ "d1 = 0.75\t#in\n",
+ "s = 60.\t#ft\n",
+ "p1 = 9.\t#in\n",
+ "p2 = 8.4\t#in\n",
+ "p3 = 9.\t#in\n",
+ "c1 = 13*63.6\t#sq in\n",
+ "c2 = 9*55.4\t#sq in\n",
+ "c3 = 9.21\t#sq ft\n",
+ "M = d*1.547\t#cfs\n",
+ "v = M/c3\t#fps\n",
+ "g = 0.025*32.2\t#ft/sec**2\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "F = v/math.sqrt(g*(p1/12))\t#ft\n",
+ "S = s/d1\t#in\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the port near the end of the diffuser pipe = %.2f in'%(F)\n",
+ "\n",
+ "# note : rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the port near the end of the diffuser pipe = 9.73 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch16.ipynb b/Water_and_Wastewater_Engineering/ch16.ipynb
new file mode 100644
index 00000000..2b395898
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch16.ipynb
@@ -0,0 +1,64 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:3c3856bc217e5f495e078375001a6745906e09c45dfca2c5d1fe105500ef94b8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 16 : Machinery and Equipment"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.2 Page No : 16-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "p = 500\t#ft\n",
+ "p1 = 6\t#in\n",
+ "t = 500\t#cfm\n",
+ "p2 = 7\t#psig\n",
+ "P = p2+14.7\t#psia\n",
+ "T = 520*(P/14.7)**0.283\t#F\n",
+ "f = 0.048*p1**0.027/(t)**0.148\t#in\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "delP = 20.*10**-3*p*T*(t)**2/(38*10**3*P*p1**5)\t#psia\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the pressure drop = %.2f psia'%(delP)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the pressure drop = 0.23 psia\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch2.ipynb b/Water_and_Wastewater_Engineering/ch2.ipynb
new file mode 100644
index 00000000..d099aba5
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch2.ipynb
@@ -0,0 +1,374 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:af736a02c1f2601e59ec790e080728198307e957dded2cfbca28aa79de429565"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2 : Water Systems"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1 Page No : 2-5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "w = 3000.\t#sq ft\n",
+ "w1 = 2000.\t#sq ft\n",
+ "w2 = 1000.\t#sq ft\n",
+ "r = 15. \t#in\n",
+ "a = 12.\t #in\n",
+ "h = 7.5\t #in\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "G = w*(r/a)*h\t#gal\n",
+ "g = w1*(r/a)*h\t#gal\n",
+ "g1 = w2*(r/a)*h\t#gal\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the normally be stored to tide the supply over dry spells = %.0f gal'%(G)\n",
+ "#wrong ans in book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the normally be stored to tide the supply over dry spells = 28125 gal\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2 Page No : 2-9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "m = 17.378 \t#mg\n",
+ "h = 20. \t #in/sq mile \n",
+ "d = 365.\t #in\n",
+ "s = 0.75\t #percent\n",
+ "a = 100.\t #sq miles\n",
+ "p = 750000.\t #gpd per sq mile\n",
+ "t = 180.\t #in\n",
+ "c = 150.\t #gpcd\n",
+ "n = 64600. \t #gpd per sq mile\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "R = h*m\t#mg\n",
+ "A = R/d\t#mgd\n",
+ "S = s*a*t\t#billion gal\n",
+ "Q = a*p/c\t#gpd\n",
+ "P = a*n/c\t#people against\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the surface water sheds and storage requirements = %.0f mg'%(R)\n",
+ "print 'the well watered sections of north america = %.1f billion gal'%(S/1000)\n",
+ "print 'the average consumption populations = %.0f gpd'%(Q)\n",
+ "print 'the presence of proper storage = %.0f people against'%(round(P,-3))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the surface water sheds and storage requirements = 348 mg\n",
+ "the well watered sections of north america = 13.5 billion gal\n",
+ "the average consumption populations = 500000 gpd\n",
+ "the presence of proper storage = 43000 people against\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3 Page No : 2-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "w = 20 \t#ft\n",
+ "r = 3\t #ft a day\n",
+ "g = 500\t #ft\n",
+ "g1 = 1000\t #ft\n",
+ "h = 7.5/1440\t#ft\n",
+ "p = 7.5/1000000\t#ft\n",
+ "r1 = 2\t #ft a day\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "W1 = w*g1*r*h\t#gpm\n",
+ "W2 = w*g1*r1*r*p\t#mgd\n",
+ "\t\n",
+ "#RESULTS\n",
+ "#wrong ans in book\n",
+ "print 'the ground water laterally = %.2f gpm'%(W1)\n",
+ "print 'the water from both sides = %.2f mgd'%(W2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the ground water laterally = 312.50 gpm\n",
+ "the water from both sides = 0.90 mgd\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4 Page No : 2-18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "p1 = 10.\t #mgd\n",
+ "p2 = 6940.\t#gpm\n",
+ "w = 67000.\t#people\n",
+ "d = 2.\t #min\n",
+ "v = d*p2/d\t#gal\n",
+ "v1 = 98.2\t#cu ft each\n",
+ "q = 30.\t #min\n",
+ "q1 = q*p2/d\t#gal\n",
+ "q2 = 13900.\t#cu ft\n",
+ "a = 1390.\t#sq ft\n",
+ "s = 2.\t #hr\n",
+ "s1 = 120*p2/d\t#gal\n",
+ "s2 = 55700.\t#cu ft \n",
+ "s3 = s2/8.\t#sq ft\n",
+ "r = 3\t #gpm/sq ft\n",
+ "r1 = 6\t #rapid\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "D = math.sqrt(v1*4/math.pi)\t#ft\n",
+ "S = p2/s3\t#gpm/sq ft\n",
+ "A = p2/(r1*r)\t#sq ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the capacity of the components of a rapid sand filtration plant = %d sq ft'%(A)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the capacity of the components of a rapid sand filtration plant = 385 sq ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5 Page No : 2-21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "r = 10000.\t#ft\n",
+ "l = 400000\t#people\n",
+ "q = 1000000.\t#mgd\n",
+ "w = 100\t#gpcd\n",
+ "w1 = 150\t#gpcd\n",
+ "m = 50\t#percent\n",
+ "g = 1.5\t#ft\n",
+ "h1 = 2.32\t#cfs\n",
+ "h2 = 139\t#cfs\n",
+ "d = 12\t#ft\n",
+ "c = 100\t#ft\n",
+ "l = 10.8\t#ft\n",
+ "l2 = 0.85\t#ft\n",
+ "l1 = 1000\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "a = r*w/q\t#mgd\n",
+ "b = l*w1/q\t#mgd\n",
+ "a1 = a*g\t#mgd\n",
+ "b1 = b*g\t#mgd\n",
+ "D = d*math.sqrt(h1/math.pi)\t#in\n",
+ "D1 = d*math.sqrt(h2/math.pi)\t#in\n",
+ "L = l/l1\t#ft\n",
+ "L1 = l2/l1\t#ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the higher loss of head in small conduits at equal velocity = %f ft'%(L1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the higher loss of head in small conduits at equal velocity = 0.000850 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.6 Page No : 2-25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "a = 12\t#in\n",
+ "b = 24\t#in\n",
+ "r = 500\t#gpm\n",
+ "d = 200.\t#gpcd\n",
+ "d1 = 150.\t#gpcd\n",
+ "p1 = 113\t#sq in\n",
+ "p2 = 425\t#sq in\n",
+ "v1 = 3\t #fps\n",
+ "v2 = 2.35\t#cfs\n",
+ "v3 = 9.42\t#cfs\n",
+ "h = 646000\t#gpd\n",
+ "w = 720000\t#gpd\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "D1 = v2*h\t#gpd\n",
+ "D2 = v3*h\t#gpd\n",
+ "W1 = D1-w\t#gpd\n",
+ "W2 = D2-w\t#gpd\n",
+ "R1 = D1/d\t#people\n",
+ "R2 = D2/d\t#people\n",
+ "S = W1/d1\t#people\n",
+ "S1 = W2/d1\t#people\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the absence of fire service for a maximum draft = %d gpd'%(round(D2,-3))\n",
+ "print 'The residential fire flow requirements = %.0f gpd'%(round(W2,-3))\n",
+ "\n",
+ "# note: answers are correct. please check using calculator."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the absence of fire service for a maximum draft = 6085000 gpd\n",
+ "The residential fire flow requirements = 5365000 gpd\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.7 Page No : 2-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "w = 100000.\t#ft\n",
+ "c = 250. \t#per capita\n",
+ "p1 = 0.3\t#percent\n",
+ "p2 = 0.1\t#percent\n",
+ "p3 = 0.60\t#percent\n",
+ "w1 = 15.\t#mgd\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "T = c*w\t#$\n",
+ "W = p1*T\t#$\n",
+ "W1 = p2*T\t#$\n",
+ "W2 = p3*T\t#$\n",
+ "W3 = ((w1)**(2./3))*(T/100)\t#$\n",
+ "\n",
+ "#RESULTS\n",
+ "print 'the replacement cost of the water of a city = %.0f $'%(round(W3,-5))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the replacement cost of the water of a city = 1500000 $\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch3.ipynb b/Water_and_Wastewater_Engineering/ch3.ipynb
new file mode 100644
index 00000000..1294bb03
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch3.ipynb
@@ -0,0 +1,348 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:0ac87828ad067f0685215c3ea3f783dc1f30af884f5edc144a109aec1b63e4e7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3 : Wastewater Systems"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.1 Page No : 3-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "v = 2.5\t#fps\n",
+ "c = 0.013\t#gpd\n",
+ "p = 300\t#gpd\n",
+ "d = 50\t#per care\n",
+ "m = 5.20\t#ft\n",
+ "a = 1000\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "C = (math.pi*64)/(4*144)*v*646000\t#gpd\n",
+ "M = m/a\t#ft\n",
+ "P = C/p\n",
+ "A = P/d\t#acres\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the acres will it drain if the population density = %.1f acres'%(A)\n",
+ "\n",
+ "# rounding off error"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the acres will it drain if the population density = 37.6 acres\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.2 Page No : 3-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "a = 37.4\t#acres\n",
+ "r = 2.\t#in\n",
+ "p = 30.\t#min\n",
+ "v = 3\t#fps\n",
+ "r1 = 0.6\t#in\n",
+ "h = 1.0\t#cfs\n",
+ "p1 = 50\t#percent\n",
+ "q = 646000\t#gpd\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "R = r*r1*a\t#cfs\n",
+ "A = R/v\t#sq ft\n",
+ "D = 12*math.sqrt(4*A/math.pi)\t#in\n",
+ "P = r*r1*q/p1\t#gpcd\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the per capita storm runoff for a population density = %.0f gpcd'%(round(P,-1))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the per capita storm runoff for a population density = 15500 gpcd\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3 Page No : 3-16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "w = 1.0\t#cfs\n",
+ "w1 = 3.0\t#cfs\n",
+ "w2 = 45.0\t#cfs\n",
+ "v = 3.0\t#fps\n",
+ "h = 144\t#ft\n",
+ "D = 12*math.sqrt(4*w/(math.pi*w1))\t#in\n",
+ "d1 = 1.95\t#cfs\n",
+ "D1 = 12*math.sqrt(4*d1)/(math.pi*v)\t#in\n",
+ "d2 = 41.6\t#cfs\n",
+ "D2 = 12*math.sqrt(4*d2)/(math.pi*w1)\t#ins\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "C = math.pi*(D)**2*3/(4*h)\t#cfs\n",
+ "C1 = math.pi*(1./4)*3\t#cfs\n",
+ "V = (d2*4)/(math.pi*4**2)\t#fps\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'The minimum dry-weather flow = %.2f cfs'%(C)\n",
+ "print 'The maximum dry-weather flow in excess actual capacity = %.1f cfs'%(C1)\n",
+ "print 'the storm flow in axcess of maximum dry-weather flow = %.1f fps'%(V)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum dry-weather flow = 1.00 cfs\n",
+ "The maximum dry-weather flow in excess actual capacity = 2.4 cfs\n",
+ "the storm flow in axcess of maximum dry-weather flow = 3.3 fps\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.4 Page No : 3-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "t = 0.8\t#mgd\n",
+ "d = 8000.\t#people\n",
+ "a = 2.\t#hr\n",
+ "v = 800000.\t#ft\n",
+ "h = 10.\t#ft\n",
+ "a1 = 4.\t#in\n",
+ "d1 = 1.\t#sq ft per capita\n",
+ "a3 = 3.\t#mgad\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "V = v*(a/24)/a\t#gal\n",
+ "S = V/h\t#sq ft\n",
+ "S1 = (v/h)/S\t#gpd per sq ft\n",
+ "V1 = a*d/h\t#cu ft\n",
+ "D = d/S\t#ft\n",
+ "E = d1*d/a1\t#sq ft\n",
+ "A = t/a3\t#acre\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the capacity of the components of a small trickling-filter = %.2f acre'%(A)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the capacity of the components of a small trickling-filter = 0.27 acre\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.5 Page No : 3-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "w = 2000.\t#sq miles\n",
+ "r = 0.1 \t#cfs\n",
+ "d = 80000.\t#ft\n",
+ "p = 100.\t#gpd\n",
+ "p1 = 80.\t#ft\n",
+ "p2 = 340.\t#percent\n",
+ "h = 646000.\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "L = r*w\t#cfs\n",
+ "R = 6*p1/1.4\t#cfs\n",
+ "P = p1*(p2-L)/p2\t#percent\n",
+ "D = (d*p)\t#gpd\n",
+ "D1 = (L*h)\t#gpd\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print \"Low-water flow = %d cfs\"%(0.1*w)\n",
+ "print \"Required flow for disposal of domestic sewage if it i left untreated = %d cfs\"%(round(6*80/1.4,-1))\n",
+ "print 'the percent of removal of pollutional load needed = %.0f percent'%(P)\n",
+ "print \"Dilution ratio = %d : %d\"%((d*p)/(d*p),(200*h)/(d*p))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Low-water flow = 200 cfs\n",
+ "Required flow for disposal of domestic sewage if it i left untreated = 340 cfs\n",
+ "the percent of removal of pollutional load needed = 33 percent\n",
+ "Dilution ratio = 1 : 16\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.6 Page No : 3-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "p = 10000.\t#people\n",
+ "p1 = 4. \t#ft\n",
+ "w = 10. \t#in\n",
+ "s = 80. \t#gpcd\n",
+ "h = 43560.\t#ft\n",
+ "p2 = 20. \t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "R = ((w/12)*7.5*h)/365\t#gpad\n",
+ "A = p*s/R\t#acres\n",
+ "A1 = 1.7\t#sq miles\n",
+ "P = p/500\t#acres\n",
+ "D = p2*h*4*7.48/(p*s)\t#days\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the detention period in ponds = %.0f days'%(D)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the detention period in ponds = 33 days\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.7 Page No : 3-31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "p = 100000.\t#people\n",
+ "a = 75. \t#$\n",
+ "a2 = 47. \t#in\n",
+ "b = 10. \t#in\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "P = a*p\t#people\n",
+ "S = ((a2)*(b**5))/(b)**(1./4)\t#$\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the money is inversed in the sanitary sewerage system = %.0f $'%(round(S,-5))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the money is inversed in the sanitary sewerage system = 2600000 $\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch4.ipynb b/Water_and_Wastewater_Engineering/ch4.ipynb
new file mode 100644
index 00000000..c47b5c94
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch4.ipynb
@@ -0,0 +1,287 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:69dc81267d132717cceb5ed01afab9cdbb37bfc431d05698243961d6dd4f91a3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4 : Information Analysis"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.2 Page No : 4-22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import *\n",
+ "\n",
+ "#initialisation of variables\n",
+ "y_bar = 19.5\t#in\n",
+ "x = 396.8\t#in\n",
+ "n = 6\t#in\n",
+ "y1 = 2.20\t#in\n",
+ "x1 = 51.14\t#in\n",
+ "p = 5.64\t#in\n",
+ "ob_y = array([44,20,24,14,12,3])\n",
+ "ob_x = array([5.3,3.5,3.,1.2,0.48,-0.26])\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "Beta = round((x-n*(y_bar)*(y1))/(x1-n*(y1)**2),2)\n",
+ "y = around(y_bar + Beta*(ob_x - 2.2),decimals=1)\n",
+ "Ri = ob_y - y\n",
+ "sumRi = sum(Ri)\n",
+ "\n",
+ "#RESULTS\n",
+ "print \"Beta B = %.2f\"%Beta\n",
+ "print \"residuals Ri are : \" ,Ri\n",
+ "print 'the method of leate squares = %.2f minimum'%(sumRi)\n",
+ "\n",
+ "# note : answer is slighty different because of rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Beta B = 6.31\n",
+ "residuals Ri are : [ 4.9 -7.7 -0.5 0.8 3.4 -1. ]\n",
+ "the method of leate squares = -0.10 minimum\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3 Page No : 4-30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import *\n",
+ "\n",
+ "#initialisation of variables\n",
+ "a = 12.\t #in\n",
+ "h = 121.\t#in\n",
+ "p = 11. #in\n",
+ "s = 220.\t#in\n",
+ "observed_time = array([11,12,13,14,15,16,17,18,19,20,21])\n",
+ "i = array([1,2,3,4,5,6,7,8,9,10,11])\n",
+ "observed_magnitude = array([2,4,6,8,10,12,14,16,18,20,22])\n",
+ "y_uy = array([-10,-8,-6,-4,-2,0,2,4,6,8,10])\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "B = a/p*(h-1)*s\t#per unit\n",
+ "n = len(i)\n",
+ "i_6 = i - (n+1)/2\n",
+ "i_6_y_uy = (i - (n+1)/2)*y_uy\n",
+ "\n",
+ "#RESULTS\n",
+ "print \"Observed Time \", observed_time\n",
+ "print \"Order,i \", i\n",
+ "print \"[i-(n+1)/2] \", i_6\n",
+ "print \"Observed magnitude \", observed_magnitude\n",
+ "print \"Deviation from mean \", y_uy\n",
+ "print \"[i-(n+1)/2](y-uy) \", i_6_y_uy \n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Observed Time [11 12 13 14 15 16 17 18 19 20 21]\n",
+ "Order,i [ 1 2 3 4 5 6 7 8 9 10 11]\n",
+ "[i-(n+1)/2] [-5 -4 -3 -2 -1 0 1 2 3 4 5]\n",
+ "Observed magnitude [ 2 4 6 8 10 12 14 16 18 20 22]\n",
+ "Deviation from mean [-10 -8 -6 -4 -2 0 2 4 6 8 10]\n",
+ "[i-(n+1)/2](y-uy) [50 32 18 8 2 0 2 8 18 32 50]\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.5 Page No : 4-31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "a = 4404.\t#ft\n",
+ "q = 9.\t#ft\n",
+ "mu = 12.\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "F = math.sqrt(a/q)\t#ft\n",
+ "CF = F/mu*100\t#percent\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the coefficient of fluctuation is = %.0f percent'%(CF)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the coefficient of fluctuation is = 184 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7 Page No : 4-35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "h2 = 5\t#in\n",
+ "x = 3.72\t#in\n",
+ "x1 = 1.28\t#in\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "H = h2*x1/x\t#in\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the either side of the center of the scale = %.2f in'%(H)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the either side of the center of the scale = 1.72 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8 Page No : 4-35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "p = 80\t#in\n",
+ "q = 20\t#in\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "K = p+q\t#ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the moments of the arithmetically normal frequency curve = %.0f ft'%(K)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the moments of the arithmetically normal frequency curve = 100 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.9 Page No : 4-38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "g = 3.2541\t#in\n",
+ "g1 = 3.46\t#in\n",
+ "m = 0.5390\t#ft\n",
+ "h = 2./99\t#ft\n",
+ "p = 1.52\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "L = math.sqrt(g*h)\t#in\n",
+ "mu = g1*p\t#in\n",
+ "M = g1/p\t#percent\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the points necessary to plot the straigt line of fit on math.log probability = %.2f percent'%(M)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the points necessary to plot the straigt line of fit on math.log probability = 2.28 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch5.ipynb b/Water_and_Wastewater_Engineering/ch5.ipynb
new file mode 100644
index 00000000..1946a849
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch5.ipynb
@@ -0,0 +1,311 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d903acbbd579075c20da58df0664f6b615313ecea1f356fbfe69d66ce9759ff7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5 : Water and Wastewater Volumes"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.1 Page No : 5-6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "t1 = 5.25\t#yr\n",
+ "t2 = 10.00\t#yr\n",
+ "yi = 171000\t#in\n",
+ "ye = 111000\t#in\n",
+ "yt = 5.23300\t#in\n",
+ "yl = 5.04532\t#in\n",
+ "yn = 31500\t#in\n",
+ "ym = 0.09853\t#in\n",
+ "tm = 9.25\t#yr\n",
+ "tn = 10.00\t#yr\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "T = t1/t2\t#yr\n",
+ "T1 = tm/tn\t#yr\n",
+ "Y = yi-ye\t#in\n",
+ "Yt = yt-yl\t#in\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the fifth intercensal year = %.3f yr'%(T)\n",
+ "print 'the ninth postcensal year = %.3f yr'%(T1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the fifth intercensal year = 0.525 yr\n",
+ "the ninth postcensal year = 0.925 yr\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2 Page No : 5-8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import Symbol\n",
+ "import math\n",
+ "\n",
+ "#initialisation of variables\n",
+ "y0 = 30000\t#in\n",
+ "y1 = 172000\t#in\n",
+ "y2 = 292000\t#in\n",
+ "a = 172\t #ft\n",
+ "p = 30.\t #ft\n",
+ "y = 292\t #ft\n",
+ "q = 322000\t#ft\n",
+ "g = 313\t #ft\n",
+ "n = 0.05\t#ft\n",
+ "d = -2.442\t#ft\n",
+ "t = Symbol('t')\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "L = (2*p*a*y2-(a)**2*q)/(p*y-(a)**2)\t#moreover\n",
+ "m = (g-p)/p\t#ft\n",
+ "N = n*d\t#in\n",
+ "Y = g/(1+9.43*math.exp(N)*t)\t#in\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the saturation populations = %.2f moreover'%(round(L,-3))\n",
+ "print 'the coefficients = %.3f in'%(N)\n",
+ "print 'the equation of a logistic curve = ',(Y)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the saturation populations = 313000.00 moreover\n",
+ "the coefficients = -0.122 in\n",
+ "the equation of a logistic curve = 313/(8.34611446180163*t + 1)\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4 Page No : 5-19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "p = 100000\t#in\n",
+ "d = 150.\t#in\n",
+ "h = 1000000.\t#in\n",
+ "a1 = 2.0\t#draft\n",
+ "a2 = 3.0\t#draft\n",
+ "a3 = 1.6\t#draft\n",
+ "m = 1.5\t #in\n",
+ "q = 2.5\t #in\n",
+ "v = 1020.\t#in\n",
+ "w = 100. \t#in\n",
+ "t = 0.01\t#in\n",
+ "v1 = 13.2\t#mgd\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "A = d*p/h\t#mgd\n",
+ "M = m*A\t#mgd\n",
+ "M1 = q*A\t#mgd\n",
+ "V = v*math.sqrt(w)*(1-t*math.sqrt(w))\t#gpm\n",
+ "D = M+v1\t#mgd\n",
+ "L = a1*A\t#mgd\n",
+ "L1 = (4./3)*M\t#max\n",
+ "H = a2*A\t#mgd\n",
+ "H1 = (4./3)*M1\t#max\n",
+ "F = a3*A\t#mgd\n",
+ "F1 = (1.6)*15\t#max\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the resulting capacities of the four system = %.f max'%(F1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the resulting capacities of the four system = 24 max\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6 Page No : 5-22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "r = 48\t#in\n",
+ "A = 450\t#gpd/acre\n",
+ "B = 8000.\t#gpd/mile\n",
+ "S = round(5280./350)\t#manholes/mile\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "C = (B-S*100)/12\t#gpd/mile\n",
+ "\n",
+ "#RESULTS\n",
+ "print 'the ground a quarter of it eventually = %.2f gpd/mile'%(C)\n",
+ "\n",
+ "# note : answer in book is wrong. please check."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the ground a quarter of it eventually = 541.67 gpd/mile\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.7 Page No : 5-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "p1 = 20.\t#ft\n",
+ "p2 = 30.\t#ft\n",
+ "w = 5. \t#person\n",
+ "s = 17800.\t#in\n",
+ "h = 1200.\t#in\n",
+ "q = 100. \t#in\n",
+ "i = 1.\t#in\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "S = p1*p2*i*s/(h*w)\t#gpcd\n",
+ "P = (q*w*10/S)\t#percent\n",
+ "\n",
+ "\n",
+ "#RESULTS\n",
+ "print 'the degree of separation of stormwater = %.0f percent'%(P)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the degree of separation of stormwater = 3 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.8 Page No : 5-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "s = 105\t#gpcd\n",
+ "m = 315\t#gpcd\n",
+ "m1 = 35\t#gpcd\n",
+ "Q1 = 360\t#gpcd\n",
+ "Q2 = 30\t#gpcd\n",
+ "p1 = 20\t#pecent\n",
+ "p2 = 15\t#persons/acer\n",
+ "D = 21\t#persons/acre\n",
+ "I = 2000\t#gpd/acre\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "A = D*(s+Q2)+I\t#gpd/acre\n",
+ "R = D*(m+Q2)+I\t#gpd/acre\n",
+ "L = D*(m1+Q2)+I\t#gpd/acre\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the average peak and low rates of flow = %.0f gpd/acre'%(round(L,-1))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the average peak and low rates of flow = 3370 gpd/acre\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch6.ipynb b/Water_and_Wastewater_Engineering/ch6.ipynb
new file mode 100644
index 00000000..1c733ac1
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch6.ipynb
@@ -0,0 +1,163 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:098e6f8caaa45e66f3c3c4de6e35624c980f673866a521599c34dc5ef9f6350c"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6 : Elements of Hydrology"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.1 Page No : 6-6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "H = 1360\t#ft\n",
+ "t = 60\t#f\n",
+ "a = (10**3)*5.5*(10**-3)\t#f\n",
+ "q = (1.36*10**3)*5.5*(10**-3)\t#f\n",
+ "s = (4-1.36)*(10**3)*(3.2*10**-3)\t#f\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "T = t-q-s\t#F\n",
+ "T1 = T+3*a\t#F\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the temperature at the mountain top = %.0f F'%(T)\n",
+ "print 'the temperature on the plain beyond the mountain = %.1f F'%(T1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the temperature at the mountain top = 44 F\n",
+ "the temperature on the plain beyond the mountain = 60.6 F\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.2 Page No : 6-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "t = 60\t#f\n",
+ "v = 0.52\t#in\n",
+ "t1 = 80\t#F\n",
+ "p = 40\t#percent\n",
+ "v1 = 1.03*0.40\t#in\n",
+ "w = 8\t#mph\n",
+ "pa = 29.0\t#in\n",
+ "p1 = 0.497\t#ft\n",
+ "q = 1.32*10**-2\t#ft\n",
+ "r = 0.268\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "E = p1*(1-q*pa)*(1+r*w)*(v-.41)\t#in\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the evaporation for the a day during = %.2e in'%(E)\n",
+ "\n",
+ "# note : answer is slightly different because of rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the evaporation for the a day during = 1.06e-01 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3 Page No : 6-19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "t = 47\t#f\n",
+ "q = 8000\t#ft\n",
+ "a = 100\t#ft\n",
+ "d = 0.10\t#in\n",
+ "d1 = 7\t#degree days\n",
+ "s1 = 14000\t#ft\n",
+ "s2 = 7000\t#ft\n",
+ "s = 1000\t#ft\n",
+ "g = 32\t#ft\n",
+ "h = 17.37\t#ft\n",
+ "h1 = 1.547\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "T = q+s*(t-g)/3\t#ft\n",
+ "T1 = t-3*1\t#F\n",
+ "T2 = (T1+g)/2\t#F\n",
+ "T3 = d1*d*a\t#sq mile in\n",
+ "M = h*T3\t#mgd\n",
+ "M1 = M*h1\t#cfs\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the upper boundary of the melting zone and temperature at the snow line = %.0f F'%(T1)\n",
+ "print 'The average temperature of = %d cfs'%(M1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the upper boundary of the melting zone and temperature at the snow line = 44 F\n",
+ "The average temperature of = 1880 cfs\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch7.ipynb b/Water_and_Wastewater_Engineering/ch7.ipynb
new file mode 100644
index 00000000..60a0e5fa
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch7.ipynb
@@ -0,0 +1,156 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:42c32bb83042eba762c882953210b5f735a47b1ef07c7eade0266ced5fe417ef"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7 : Rainfall and Runoff"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5 Page No : 7-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "n = 20. \t#ft\n",
+ "s = math.sqrt(12676/19.)\t#ft\n",
+ "c = 45.5\t#ft\n",
+ "q = 551400\t#ft\n",
+ "q1 = 12700\t#ft\n",
+ "h = 8.5\t#ft\n",
+ "w = s/c\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "D = q/(2*s*q1)\t#cfs\n",
+ "D1 = D*(1+h/n)\t#cfs\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the record runoff of a stream draining = %.2f cfs'%(D1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the record runoff of a stream draining = 1.20 cfs\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.6 Page No : 7-19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "i = 16./(62)**0.66\t#in hr\n",
+ "q = (16*10**0.31)/(62)**0.66\t#in hr\n",
+ "c = 1.0\t#max\n",
+ "C1 = c*(0.01)**0.31\t#in\n",
+ "C2 = c*(0.1)**0.31\t#in\n",
+ "x1 = 640\t#cfs\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "Y1 = C1*i*c*x1\t#cfs\n",
+ "Y2 = C2*q*c*x1\t#cfs\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the time of concentration = %.f cfs'%(Y2)\n",
+ "\n",
+ "# rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the time of concentration = 672 cfs\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8 Page No : 7-25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "d = 163*48.5\t#cfs\n",
+ "a = 48.5\t#ft\n",
+ "q = 100\t#cfs\n",
+ "Q = 45.5*a\t#cfs\n",
+ "c = 0.57\t#cfs\n",
+ "v = 1.8\t#cfs\n",
+ "p = 0.45\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "P = d/(q*math.sqrt(a))\t#percent\n",
+ "C = Q/(a**0.8*(1+2*a**-0.3))\t#cfs\n",
+ "d1 = 2.6\t#cfs\n",
+ "T = (1-p*c+v*c*2)\t#cfs\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the meyers rating = %.1f percent'%(P)\n",
+ "print 'the magnitude of the maximum peak flood = %.1f cfs'%(T)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the meyers rating = 11.4 percent\n",
+ "the magnitude of the maximum peak flood = 2.8 cfs\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch8.ipynb b/Water_and_Wastewater_Engineering/ch8.ipynb
new file mode 100644
index 00000000..9aa81db6
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch8.ipynb
@@ -0,0 +1,202 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:fba260293419dba131eeeb5811674596ce6afa78c83d914173c371599b6aa433"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8 : Storage and Runoff Control"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2 Page No : 8-7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "a = 0.75\t#ft\n",
+ "p = 123\t#mg\n",
+ "v = 100\t#ft\n",
+ "s = 33\t#mg\n",
+ "s1 = 67\t#mg\n",
+ "d = 26.6\t#mgd\n",
+ "d1 = 0.0477\t#mgd\n",
+ "q = 0.750\t#gpd/sq mile\n",
+ "d2 = 365\t#days\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "S = p/a\t#mg per sq mile\n",
+ "Cv = v*s/s1\t#percent\n",
+ "M = d*d1\t#mgd per sq mile\n",
+ "D = v*q/M\t#MAF\n",
+ "D1 = (v*p)/(M*d2)\t#MAF\n",
+ "R = p/q\t#days\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the use monthly averages rather then daily stream flow = %.0f days'%(R)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the use monthly averages rather then daily stream flow = 164 days\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3 Page No : 8-9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "d = 750000\t#gpd per sq mile\n",
+ "v = 0.22\t#ft\n",
+ "a = 1.27\t#ft\n",
+ "q = 0.30\t#ft\n",
+ "d1 = 365\t#days\n",
+ "p = 0.25\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "Q = q*a*d1\t#mg/sq mile\n",
+ "H = p*a*d1\t#mg/sq mile\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the results obtained by normal analytical procedures and by Hazen s = %.0f mg/sq mile'%(H)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the results obtained by normal analytical procedures and by Hazen s = 116 mg/sq mile\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4 Page No : 8-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "d = 30.0\t#mgd\n",
+ "a = 40.0\t#sq miles\n",
+ "a1 = 1500\t#acres\n",
+ "r1 = 47.0\t#in\n",
+ "r2 = 27.0\t#in\n",
+ "q = 0.9\t#in\n",
+ "k = 640\t#in\n",
+ "h = 0.052\t#gpd/sq mile\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "Q = r2-(r2+a-r1)*q*a1/(k*a)\t#in\n",
+ "D = d+a*h\t#mgd\n",
+ "A = a-(q*a1/k)*(1-(r1-a)/(r2))\t#sq miles\n",
+ "R = r2+a-r1\t#in\n",
+ "S = R*q\t#in\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the revised mean annual runoff = %.1f in'%(Q)\n",
+ "print 'the equivalent mean draft = %.1f mgd'%(D)\n",
+ "print 'the equivalent land area = %.1f sq miles'%(A)\n",
+ "print 'the adjusted flowline = %.0f in'%(S)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the revised mean annual runoff = 25.9 in\n",
+ "the equivalent mean draft = 32.1 mgd\n",
+ "the equivalent land area = 38.4 sq miles\n",
+ "the adjusted flowline = 18 in\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.6 Page No : 8-18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "p = 100. \t#ft\n",
+ "q = 27000.\t #acre-ft\n",
+ "p1 = 10. \t#ft\n",
+ "s = 8250.\t#acre-ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "R = p*s/q\t#percent\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the ratio of peak inflow from fuller values = %d percent'%(R)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the ratio of peak inflow from fuller values = 30 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/ch9.ipynb b/Water_and_Wastewater_Engineering/ch9.ipynb
new file mode 100644
index 00000000..17df7377
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/ch9.ipynb
@@ -0,0 +1,297 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:cb8c1d89336b90a52fb3fc2ac2cf4a335c076b1a2d2bc8b2521052d89b269ec7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9 : Groundwater Flow"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.1 Page No : 9-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "t = 10\t#C\n",
+ "s = 74.2\t#days\n",
+ "c = 0.01\t#mm\n",
+ "d = 245\t#mm\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "h = s/(d*c)\t#cm\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the high will water at a temperature = %.1f cm'%(h)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the high will water at a temperature = 30.3 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.2 Page No : 9-13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "p1 = 1000\t#ft\n",
+ "p2 = 50\t#ft\n",
+ "g = 20\t#ft/mile\n",
+ "v = 5280.\t#ft\n",
+ "q = 7.5*10**-6\t#ft\n",
+ "t = 60\t#F\n",
+ "k = 2835\t#ft/days\n",
+ "p = 7.5\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "S = g/v\t#ft\n",
+ "W = k*(g/v)\t#ft/day\n",
+ "Q = W*p1*p2*q\t#mgd\n",
+ "P = k*p\t#ft\n",
+ "P1 = P*p2\t#mgd\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the velocity of flow = %.2f mgd'%(Q)\n",
+ "print 'the standard coefficient pf permeability = %.2e mgd'%(P1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the velocity of flow = 4.03 mgd\n",
+ "the standard coefficient pf permeability = 1.06e+06 mgd\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.3 Page No : 9-19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math \n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "p = 40. \t#ft\n",
+ "d = 56. \t#ft\n",
+ "d1 = 140. \t#ft\n",
+ "p1 = 30. \t#ft\n",
+ "w = 3.28*10**-4\t#fps\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "Q = w*(p/d1)*2*d*p\t#cfs\n",
+ "q = Q/p\t#cfs\n",
+ "K = w*(p/d1)\t#fps\n",
+ "x0 = q/(2*math.pi*K)\t#ft\n",
+ "Z = 2*math.pi*x0\t#ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the yield of the well if the coefficient of permeability = %.1f ft'%(x0)\n",
+ "print 'the distance of the point of stagnation = %.0f ft'%(Z)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the yield of the well if the coefficient of permeability = 17.8 ft\n",
+ "the distance of the point of stagnation = 112 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4 Page No : 9-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "p = 5.*10**6\t #ft\n",
+ "Q = 350. \t#gpm\n",
+ "x = 225. \t#ft\n",
+ "u = 10.**-2\t#ft\n",
+ "g = 1.87\t#ft\n",
+ "p2 = 7.*10**2\t#ft\n",
+ "p3 = 10.9\t#ft\n",
+ "w = 4.0\t#ft\n",
+ "t = 114.6\t #ft\n",
+ "d = 10. \t#ft\n",
+ "p1 = 5. \t#ft\n",
+ "w1 = 3.2*10**4\t#ft\n",
+ "W = 21.75\t#ft\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "T = t*Q*4/p1\t#gpd/ft\n",
+ "S = u*(w1)/(g*(p))\t#ft\n",
+ "U = g*((S)/(T))*(x**2/d)\t#ft\n",
+ "P = t*(p2)*p3/(T)\t#ft\n",
+ "U1 = g*((S)/(T))*(1./d)\t#ft\n",
+ "P1 = t*(p2)*W/(T)\t#ft\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'the type curve as if a transparency of the observed data had moved into place over the type = %.0f ft'%(P1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the type curve as if a transparency of the observed data had moved into place over the type = 54 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.5 Page No : 9-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\t\n",
+ "#initialisation of variables\n",
+ "Q = 350. \t#gpm\n",
+ "x = 225. \t#ft\n",
+ "t = 1. \t#min\n",
+ "p = 1.6\t #ft\n",
+ "t2 = 10. \t#min\n",
+ "p2 = 4.5\t#ft\n",
+ "p3 = 700. \t#gpm\n",
+ "T = 3.2*10**4\t#gpd/ft\n",
+ "t0 = 0.3 \t#min\n",
+ "u = 1.15*10**-5\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "S = t0*(T)*t0/((x)**2*1440)\t#ft\n",
+ "P = ((114.6*p3)/(T))*(-0.5772*2.3*math.log(u))\t#ft\n",
+ "\n",
+ "#RESULTS\n",
+ "print 'A straight line being drawn through the ppints for the higher = %.0f ft'%(P)\n",
+ "\n",
+ "# note : book answer is wrong. please check."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "A straight line being drawn through the ppints for the higher = 38 ft\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6 Page No : 9-31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\t\n",
+ "#initialisation of variables\n",
+ "h = 4.8\t #ft\n",
+ "m = 13.4\t #ft\n",
+ "k = 10.**-1\t #cm/sec\n",
+ "k1 = 3.28*10**-3\t#fps\n",
+ "n = 7. \t#ft\n",
+ "n1 = 11. \t#ft\n",
+ "q = 1.0*10**-2\n",
+ "\t\n",
+ "#CALCULATIONS\n",
+ "Q = k1*h*n/n1\t#cfs/ft\n",
+ "Q1 = 2*q*10**2\t#cfs\n",
+ "\t\n",
+ "#RESULTS\n",
+ "print 'A satisfactory orthogonal system the flow of into the collector = %.0f cfs'%(Q1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "A satisfactory orthogonal system the flow of into the collector = 2 cfs\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Water_and_Wastewater_Engineering/screenshots/16Machinery&Equipment.png b/Water_and_Wastewater_Engineering/screenshots/16Machinery&Equipment.png
new file mode 100644
index 00000000..cd281e2d
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/screenshots/16Machinery&Equipment.png
Binary files differ
diff --git a/Water_and_Wastewater_Engineering/screenshots/2WaterSystems.png b/Water_and_Wastewater_Engineering/screenshots/2WaterSystems.png
new file mode 100644
index 00000000..3490b35b
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/screenshots/2WaterSystems.png
Binary files differ
diff --git a/Water_and_Wastewater_Engineering/screenshots/9GroundwaterFlow.png b/Water_and_Wastewater_Engineering/screenshots/9GroundwaterFlow.png
new file mode 100644
index 00000000..2a808d7c
--- /dev/null
+++ b/Water_and_Wastewater_Engineering/screenshots/9GroundwaterFlow.png
Binary files differ